4 /* Doubly linked list. */
10 /* Doubly linked list head or element. */
13 struct list *prev; /* Previous list element. */
14 struct list *next; /* Next list element. */
17 #define LIST_INITIALIZER(LIST) { LIST, LIST }
19 void list_init(struct list *);
22 void list_insert(struct list *, struct list *);
23 void list_splice(struct list *before, struct list *first, struct list *last);
24 void list_push_front(struct list *, struct list *);
25 void list_push_back(struct list *, struct list *);
28 struct list *list_remove(struct list *);
29 struct list *list_pop_front(struct list *);
30 struct list *list_pop_back(struct list *);
33 struct list *list_front(struct list *);
34 struct list *list_back(struct list *);
36 /* List properties. */
37 size_t list_size(const struct list *);
38 bool list_is_empty(const struct list *);
40 #define LIST_ELEM__(ELEM, STRUCT, MEMBER, LIST) \
41 (ELEM != LIST ? CONTAINER_OF(ELEM, STRUCT, MEMBER) : NULL)
42 #define LIST_FOR_EACH(ITER, STRUCT, MEMBER, LIST) \
43 for (ITER = LIST_ELEM__((LIST)->next, STRUCT, MEMBER, LIST); \
45 ITER = LIST_ELEM__((ITER)->MEMBER.next, STRUCT, MEMBER, LIST))
46 #define LIST_FOR_EACH_SAFE(ITER, NEXT, STRUCT, MEMBER, LIST) \
47 for (ITER = LIST_ELEM__((LIST)->next, STRUCT, MEMBER, LIST); \
49 ? (NEXT = LIST_ELEM__((ITER)->MEMBER.next, STRUCT, MEMBER, LIST), 1) \