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