32typedef struct _snode sys_snode_t;
39typedef struct _slist sys_slist_t;
56#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \
57 for (__sn = sys_slist_peek_head(__sl); __sn; \
58 __sn = sys_slist_peek_next(__sn))
80#define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \
81 for (__sn = __sn ? sys_slist_peek_next_no_check(__sn) \
82 : sys_slist_peek_head(__sl); \
84 __sn = sys_slist_peek_next(__sn))
102#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \
103 for (__sn = sys_slist_peek_head(__sl), \
104 __sns = sys_slist_peek_next(__sn); \
105 __sn; __sn = __sns, \
106 __sns = sys_slist_peek_next(__sn))
116#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \
117 ((__ln) ? CONTAINER_OF((__ln), __typeof__(*(__cn)), __n) : NULL)
125#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \
126 SYS_SLIST_CONTAINER(sys_slist_peek_head(__sl), __cn, __n)
135#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \
136 SYS_SLIST_CONTAINER(sys_slist_peek_tail(__sl), __cn, __n)
145#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \
146 ((__cn) ? SYS_SLIST_CONTAINER(sys_slist_peek_next(&((__cn)->__n)), \
163#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \
164 for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n); __cn; \
165 __cn = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n))
182#define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \
183 for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n), \
184 __cns = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n); __cn; \
185 __cn = __cns, __cns = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n))
192static inline void sys_slist_init(sys_slist_t *list)
198#define SYS_SLIST_STATIC_INIT(ptr_to_list) {NULL, NULL}
207static inline bool sys_slist_is_empty(sys_slist_t *list)
209 return (!list->head);
219static inline sys_snode_t *sys_slist_peek_head(sys_slist_t *list)
231static inline sys_snode_t *sys_slist_peek_tail(sys_slist_t *list)
245static inline sys_snode_t *sys_slist_peek_next_no_check(sys_snode_t *node)
257static inline sys_snode_t *sys_slist_peek_next(sys_snode_t *node)
259 return node ? sys_slist_peek_next_no_check(node) : NULL;
270static inline void sys_slist_prepend(sys_slist_t *list,
273 node->next = list->head;
277 list->tail = list->head;
289static inline void sys_slist_append(sys_slist_t *list,
298 list->tail->next = node;
314static inline void sys_slist_append_list(sys_slist_t *list,
315 void *head,
void *tail)
318 list->head = (sys_snode_t *)head;
319 list->tail = (sys_snode_t *)tail;
321 list->tail->next = (sys_snode_t *)head;
322 list->tail = (sys_snode_t *)tail;
335static inline void sys_slist_merge_slist(sys_slist_t *list,
336 sys_slist_t *list_to_append)
338 sys_slist_append_list(list, list_to_append->head,
339 list_to_append->tail);
340 sys_slist_init(list_to_append);
352static inline void sys_slist_insert(sys_slist_t *list,
357 sys_slist_prepend(list, node);
358 }
else if (!prev->next) {
359 sys_slist_append(list, node);
361 node->next = prev->next;
376static inline sys_snode_t *sys_slist_get_not_empty(sys_slist_t *list)
378 sys_snode_t *node = list->head;
380 list->head = node->next;
381 if (list->tail == node) {
382 list->tail = list->head;
397static inline sys_snode_t *sys_slist_get(sys_slist_t *list)
399 return sys_slist_is_empty(list) ? NULL : sys_slist_get_not_empty(list);
412static inline void sys_slist_remove(sys_slist_t *list,
413 sys_snode_t *prev_node,
417 list->head = node->next;
420 if (list->tail == node) {
421 list->tail = list->head;
424 prev_node->next = node->next;
427 if (list->tail == node) {
428 list->tail = prev_node;
445static inline bool sys_slist_find_and_remove(sys_slist_t *list,
448 sys_snode_t *prev = NULL;
453 sys_slist_remove(list, prev, node);
#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn)
Provide the primitive to iterate on a list Note: the loop is unsafe and thus __sn should not be remov...
Definition slist.h:56