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 *);
26 void list_replace(struct list *, const struct list *);
29 struct list *list_remove(struct list *);
30 struct list *list_pop_front(struct list *);
31 struct list *list_pop_back(struct list *);
34 struct list *list_front(struct list *);
35 struct list *list_back(struct list *);
37 /* List properties. */
38 size_t list_size(const struct list *);
39 bool list_is_empty(const struct list *);
41 #define LIST_ELEM__(ELEM, STRUCT, MEMBER, LIST) \
42 (ELEM != LIST ? CONTAINER_OF(ELEM, STRUCT, MEMBER) : NULL)
43 #define LIST_FOR_EACH(ITER, STRUCT, MEMBER, LIST) \
44 for (ITER = LIST_ELEM__((LIST)->next, STRUCT, MEMBER, LIST); \
46 ITER = LIST_ELEM__((ITER)->MEMBER.next, STRUCT, MEMBER, LIST))
47 #define LIST_FOR_EACH_SAFE(ITER, NEXT, STRUCT, MEMBER, LIST) \
48 for (ITER = LIST_ELEM__((LIST)->next, STRUCT, MEMBER, LIST); \
50 ? (NEXT = LIST_ELEM__((ITER)->MEMBER.next, \
51 STRUCT, MEMBER, LIST), 1) \