|
Zephyr API 3.6.99
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
7#ifndef ZEPHYR_INCLUDE_SYS_LIST_GEN_H_
8#define ZEPHYR_INCLUDE_SYS_LIST_GEN_H_
14#define Z_GENLIST_FOR_EACH_NODE(__lname, __l, __sn) \
15 for ((__sn) = sys_ ## __lname ## _peek_head(__l); (__sn) != NULL; \
16 (__sn) = sys_ ## __lname ## _peek_next(__sn))
19#define Z_GENLIST_ITERATE_FROM_NODE(__lname, __l, __sn) \
20 for ((__sn) = (__sn) ? sys_ ## __lname ## _peek_next_no_check(__sn) \
21 : sys_ ## __lname ## _peek_head(__l); \
23 (__sn) = sys_ ## __lname ## _peek_next(__sn))
25#define Z_GENLIST_FOR_EACH_NODE_SAFE(__lname, __l, __sn, __sns) \
26 for ((__sn) = sys_ ## __lname ## _peek_head(__l), \
27 (__sns) = sys_ ## __lname ## _peek_next(__sn); \
28 (__sn) != NULL ; (__sn) = (__sns), \
29 (__sns) = sys_ ## __lname ## _peek_next(__sn))
31#define Z_GENLIST_CONTAINER(__ln, __cn, __n) \
32 ((__ln) ? CONTAINER_OF((__ln), __typeof__(*(__cn)), __n) : NULL)
34#define Z_GENLIST_PEEK_HEAD_CONTAINER(__lname, __l, __cn, __n) \
35 Z_GENLIST_CONTAINER(sys_ ## __lname ## _peek_head(__l), __cn, __n)
37#define Z_GENLIST_PEEK_TAIL_CONTAINER(__lname, __l, __cn, __n) \
38 Z_GENLIST_CONTAINER(sys_ ## __lname ## _peek_tail(__l), __cn, __n)
40#define Z_GENLIST_PEEK_NEXT_CONTAINER(__lname, __cn, __n) \
41 ((__cn) ? Z_GENLIST_CONTAINER( \
42 sys_ ## __lname ## _peek_next(&((__cn)->__n)), \
45#define Z_GENLIST_FOR_EACH_CONTAINER(__lname, __l, __cn, __n) \
46 for ((__cn) = Z_GENLIST_PEEK_HEAD_CONTAINER(__lname, __l, __cn, \
49 (__cn) = Z_GENLIST_PEEK_NEXT_CONTAINER(__lname, __cn, __n))
51#define Z_GENLIST_FOR_EACH_CONTAINER_SAFE(__lname, __l, __cn, __cns, __n) \
52 for ((__cn) = Z_GENLIST_PEEK_HEAD_CONTAINER(__lname, __l, __cn, __n), \
53 (__cns) = Z_GENLIST_PEEK_NEXT_CONTAINER(__lname, __cn, __n); \
54 (__cn) != NULL; (__cn) = (__cns), \
55 (__cns) = Z_GENLIST_PEEK_NEXT_CONTAINER(__lname, __cn, __n))
57#define Z_GENLIST_IS_EMPTY(__lname) \
59 sys_ ## __lname ## _is_empty(sys_ ## __lname ## _t *list) \
61 return (sys_ ## __lname ## _peek_head(list) == NULL); \
64#define Z_GENLIST_PEEK_NEXT_NO_CHECK(__lname, __nname) \
65 static inline sys_ ## __nname ## _t * \
66 sys_ ## __lname ## _peek_next_no_check(sys_ ## __nname ## _t *node) \
68 return z_ ## __nname ## _next_peek(node); \
71#define Z_GENLIST_PEEK_NEXT(__lname, __nname) \
72 static inline sys_ ## __nname ## _t * \
73 sys_ ## __lname ## _peek_next(sys_ ## __nname ## _t *node) \
75 return (node != NULL) ? \
76 sys_ ## __lname ## _peek_next_no_check(node) : \
80#define Z_GENLIST_PREPEND(__lname, __nname) \
82 sys_ ## __lname ## _prepend(sys_ ## __lname ## _t *list, \
83 sys_ ## __nname ## _t *node) \
85 z_ ## __nname ## _next_set(node, \
86 sys_ ## __lname ## _peek_head(list)); \
87 z_ ## __lname ## _head_set(list, node); \
89 if (sys_ ## __lname ## _peek_tail(list) == NULL) { \
90 z_ ## __lname ## _tail_set(list, \
91 sys_ ## __lname ## _peek_head(list)); \
95#define Z_GENLIST_APPEND(__lname, __nname) \
97 sys_ ## __lname ## _append(sys_ ## __lname ## _t *list, \
98 sys_ ## __nname ## _t *node) \
100 z_ ## __nname ## _next_set(node, NULL); \
102 if (sys_ ## __lname ## _peek_tail(list) == NULL) { \
103 z_ ## __lname ## _tail_set(list, node); \
104 z_ ## __lname ## _head_set(list, node); \
106 z_ ## __nname ## _next_set( \
107 sys_ ## __lname ## _peek_tail(list), \
109 z_ ## __lname ## _tail_set(list, node); \
113#define Z_GENLIST_APPEND_LIST(__lname, __nname) \
115 sys_ ## __lname ## _append_list(sys_ ## __lname ## _t *list, \
116 void *head, void *tail) \
118 if (head != NULL && tail != NULL) { \
119 if (sys_ ## __lname ## _peek_tail(list) == NULL) { \
120 z_ ## __lname ## _head_set(list, \
121 (sys_ ## __nname ## _t *)head); \
123 z_ ## __nname ## _next_set( \
124 sys_ ## __lname ## _peek_tail(list), \
125 (sys_ ## __nname ## _t *)head); \
127 z_ ## __lname ## _tail_set(list, \
128 (sys_ ## __nname ## _t *)tail); \
132#define Z_GENLIST_MERGE_LIST(__lname, __nname) \
134 sys_ ## __lname ## _merge_ ## __lname ( \
135 sys_ ## __lname ## _t *list, \
136 sys_ ## __lname ## _t *list_to_append) \
138 sys_ ## __nname ## _t *head, *tail; \
139 head = sys_ ## __lname ## _peek_head(list_to_append); \
140 tail = sys_ ## __lname ## _peek_tail(list_to_append); \
141 sys_ ## __lname ## _append_list(list, head, tail); \
142 sys_ ## __lname ## _init(list_to_append); \
145#define Z_GENLIST_INSERT(__lname, __nname) \
147 sys_ ## __lname ## _insert(sys_ ## __lname ## _t *list, \
148 sys_ ## __nname ## _t *prev, \
149 sys_ ## __nname ## _t *node) \
151 if (prev == NULL) { \
152 sys_ ## __lname ## _prepend(list, node); \
153 } else if (z_ ## __nname ## _next_peek(prev) == NULL) { \
154 sys_ ## __lname ## _append(list, node); \
156 z_ ## __nname ## _next_set(node, \
157 z_ ## __nname ## _next_peek(prev)); \
158 z_ ## __nname ## _next_set(prev, node); \
162#define Z_GENLIST_GET_NOT_EMPTY(__lname, __nname) \
163 static inline sys_ ## __nname ## _t * \
164 sys_ ## __lname ## _get_not_empty(sys_ ## __lname ## _t *list) \
166 sys_ ## __nname ## _t *node = \
167 sys_ ## __lname ## _peek_head(list); \
169 z_ ## __lname ## _head_set(list, \
170 z_ ## __nname ## _next_peek(node)); \
171 if (sys_ ## __lname ## _peek_tail(list) == node) { \
172 z_ ## __lname ## _tail_set(list, \
173 sys_ ## __lname ## _peek_head(list)); \
179#define Z_GENLIST_GET(__lname, __nname) \
180 static inline sys_ ## __nname ## _t * \
181 sys_ ## __lname ## _get(sys_ ## __lname ## _t *list) \
183 return sys_ ## __lname ## _is_empty(list) ? NULL : \
184 sys_ ## __lname ## _get_not_empty(list); \
187#define Z_GENLIST_REMOVE(__lname, __nname) \
189 sys_ ## __lname ## _remove(sys_ ## __lname ## _t *list, \
190 sys_ ## __nname ## _t *prev_node, \
191 sys_ ## __nname ## _t *node) \
193 if (prev_node == NULL) { \
194 z_ ## __lname ## _head_set(list, \
195 z_ ## __nname ## _next_peek(node)); \
198 if (sys_ ## __lname ## _peek_tail(list) == node) { \
199 z_ ## __lname ## _tail_set(list, \
200 sys_ ## __lname ## _peek_head(list)); \
203 z_ ## __nname ## _next_set(prev_node, \
204 z_ ## __nname ## _next_peek(node)); \
207 if (sys_ ## __lname ## _peek_tail(list) == node) { \
208 z_ ## __lname ## _tail_set(list, \
213 z_ ## __nname ## _next_set(node, NULL); \
216#define Z_GENLIST_FIND_AND_REMOVE(__lname, __nname) \
218 sys_ ## __lname ## _find_and_remove(sys_ ## __lname ## _t *list, \
219 sys_ ## __nname ## _t *node) \
221 sys_ ## __nname ## _t *prev = NULL; \
222 sys_ ## __nname ## _t *test; \
224 Z_GENLIST_FOR_EACH_NODE(__lname, list, test) { \
225 if (test == node) { \
226 sys_ ## __lname ## _remove(list, prev, \
237#define Z_GENLIST_FIND(__lname, __nname) \
238 static inline bool sys_##__lname##_find( \
239 sys_##__lname##_t *list, sys_##__nname##_t *node, sys_##__nname##_t **prev) \
241 sys_##__nname##_t *current = NULL; \
242 sys_##__nname##_t *previous = NULL; \
244 Z_GENLIST_FOR_EACH_NODE(__lname, list, current) { \
245 if (current == node) { \
246 if (prev != NULL) { \
252 previous = current; \
255 if (prev != NULL) { \
262#define Z_GENLIST_LEN(__lname, __nname) \
263 static inline size_t sys_##__lname##_len(sys_##__lname##_t * list) \
266 static sys_##__nname##_t * node; \
267 Z_GENLIST_FOR_EACH_NODE(__lname, list, node) { \