6 /* Some macros for maintaining doubly linked lists */
8 /* The head of the linked list. Use this in the structure that shall
9 * contain the head of the linked list */
10 #define FLX_LLIST_HEAD(t,name) t *name
12 /* The pointers in the linked list's items. Use this in the item structure */
13 #define FLX_LLIST_FIELDS(t,name) t *name##_next, *name##_prev
15 /* Initialize the list's head */
16 #define FLX_LLIST_HEAD_INIT(t,head) do { (head) = NULL; } while(0)
18 /* Initialize a list item */
19 #define FLX_LLIST_INIT(t,name,item) do { \
22 _item->name##_prev = _item->name##_next = NULL; \
25 /* Prepend an item to the list */
26 #define FLX_LLIST_PREPEND(t,name,head,item) do { \
27 t **_head = &(head), *_item = (item); \
29 if ((_item->name##_next = *_head)) \
30 _item->name##_next->name##_prev = _item; \
31 _item->name##_prev = NULL; \
35 /* Remove an item from the list */
36 #define FLX_LLIST_REMOVE(t,name,head,item) do { \
37 t **_head = &(head), *_item = (item); \
39 if (_item->name##_next) \
40 _item->name##_next->name##_prev = _item->name##_prev; \
41 if (_item->name##_prev) \
42 _item->name##_prev->name##_next = _item->name##_next; \
44 g_assert(*_head == _item); \
45 *_head = _item->name##_next; \
47 _item->name##_next = _item->name##_prev = NULL; \