1 /**
2  ****************************************************************************************
3  *
4  * @file ke_queue.h
5  *
6  * @brief This file contains the definition of the message object, queue element
7  * object and queue object
8  *
9  * Copyright (C) RivieraWaves 2009-2015
10  *
11  *
12  ****************************************************************************************
13  */
14 
15 #ifndef _KE_QUEUE_H_
16 #define _KE_QUEUE_H_
17 //
18 /**
19  ****************************************************************************************
20  * @addtogroup QUEUE Queues and Lists
21  * @ingroup KERNEL
22  * @brief Queue management module
23  *
24  * This module implements the functions used for managing message queues.
25  * These functions must not be called under IRQ!
26  * @{
27  ****************************************************************************************
28  */
29 
30 /*
31  * INCLUDE FILES
32  ****************************************************************************************
33  */
34 #include <stdint.h>              // standard integer
35 #include <stdbool.h>             // standard boolean
36 #include "ble_arch.h"            // compiler definitions
37 #include "ke_config.h"           // kernel configuration
38 #include "co_list.h"             // list definition
39 
40 /*
41  * FUNCTION PROTOTYPES
42  ****************************************************************************************
43  */
44 
45 /**
46  ****************************************************************************************
47  * @brief Pop entry to the queue
48  *
49  * @param[in]  queue    Pointer to the queue.
50  * @param[in]  element  Pointer to the element.
51  ****************************************************************************************
52  */
ke_queue_push(struct co_list * const queue,struct co_list_hdr * const element)53 __INLINE void ke_queue_push(struct co_list *const queue, struct co_list_hdr *const element)
54 {
55     co_list_push_back(queue, element);
56 }
57 
58 /**
59  ****************************************************************************************
60  * @brief Pop entry from the queue
61  *
62  * @param[in]  queue    Pointer to the queue.
63  *
64  * @return              Pointer to the element.
65  ****************************************************************************************
66  */
ke_queue_pop(struct co_list * const queue)67 __INLINE struct co_list_hdr *ke_queue_pop(struct co_list *const queue)
68 {
69     return co_list_pop_front(queue);
70 }
71 
72 /**
73  ****************************************************************************************
74  * @brief Extracts an element matching a given algorithm.
75  *
76  * @param[in]  queue    Pointer to the queue.
77  * @param[in]  func     Matching function.
78  * @param[in]  arg      Match argument.
79  *
80  * @return              Pointer to the element found and removed (NULL otherwise).
81  ****************************************************************************************
82  */
83 struct co_list_hdr *ke_queue_extract(struct co_list * const queue,
84                                  bool (*func)(struct co_list_hdr const * elmt, uint32_t arg),
85                                  uint32_t arg);
86 
87 /**
88  ****************************************************************************************
89  * @brief Insert an element in a sorted queue.
90  *
91  * This primitive use a comparison function from the parameter list to select where the
92  * element must be inserted.
93  *
94  * @param[in]  queue    Pointer to the queue.
95  * @param[in]  element  Pointer to the element to insert.
96  * @param[in]  cmp      Comparison function (return true if first element has to be inserted
97  *                      before the second one).
98  *
99  * @return              Pointer to the element found and removed (NULL otherwise).
100  ****************************************************************************************
101  */
102 void ke_queue_insert(struct co_list * const queue, struct co_list_hdr * const element,
103                      bool (*cmp)(struct co_list_hdr const *elementA,
104                      struct co_list_hdr const *elementB));
105 
106 /// @} QUEUE
107 
108 #endif // _KE_QUEUE_H_
109