Mercurial > dovecot > core-2.2
changeset 13288:eaee3b8a98cf
liblib: Added _FULL versions of all linked list handling macros with prev and next params.
This allows putting structs into multiple linked lists.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 25 Aug 2011 03:54:18 +0300 |
parents | 957060ca5b69 |
children | 4317429862e1 |
files | src/lib/llist.h |
diffstat | 1 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/llist.h Thu Aug 25 01:16:11 2011 +0300 +++ b/src/lib/llist.h Thu Aug 25 03:54:18 2011 +0300 @@ -2,14 +2,17 @@ #define LLIST_H /* Doubly linked list */ -#define DLLIST_PREPEND(list, item) STMT_START { \ +#define DLLIST_PREPEND_FULL(list, item, prev, next) STMT_START { \ (item)->prev = NULL; \ (item)->next = *(list); \ if (*(list) != NULL) (*(list))->prev = (item); \ *(list) = (item); \ } STMT_END -#define DLLIST_REMOVE(list, item) STMT_START { \ +#define DLLIST_PREPEND(list, item) \ + DLLIST_PREPEND_FULL(list, item, prev, next) + +#define DLLIST_REMOVE_FULL(list, item, prev, next) STMT_START { \ if ((item)->prev == NULL) \ *(list) = (item)->next; \ else \ @@ -21,22 +24,31 @@ (item)->prev = NULL; \ } STMT_END +#define DLLIST_REMOVE(list, item) \ + DLLIST_REMOVE_FULL(list, item, prev, next) + /* Doubly linked list with head and tail */ -#define DLLIST2_PREPEND(head, tail, item) STMT_START { \ +#define DLLIST2_PREPEND_FULL(head, tail, item, prev, next) STMT_START { \ (item)->prev = NULL; \ (item)->next = *(head); \ if (*(head) != NULL) (*(head))->prev = (item); else (*tail) = (item); \ *(head) = (item); \ } STMT_END -#define DLLIST2_APPEND(head, tail, item) STMT_START { \ +#define DLLIST2_PREPEND(head, tail, item) \ + DLLIST2_PREPEND_FULL(head, tail, item, prev, next) + +#define DLLIST2_APPEND_FULL(head, tail, item, prev, next) STMT_START { \ (item)->prev = *(tail); \ (item)->next = NULL; \ if (*(tail) != NULL) (*(tail))->next = (item); else (*head) = (item); \ *(tail) = (item); \ } STMT_END -#define DLLIST2_REMOVE(head, tail, item) STMT_START { \ +#define DLLIST2_APPEND(head, tail, item) \ + DLLIST2_APPEND_FULL(head, tail, item, prev, next) + +#define DLLIST2_REMOVE_FULL(head, tail, item, prev, next) STMT_START { \ if ((item)->prev == NULL) \ *(head) = (item)->next; \ else \ @@ -50,4 +62,7 @@ (item)->prev = NULL; \ } STMT_END +#define DLLIST2_REMOVE(head, tail, item) \ + DLLIST2_REMOVE_FULL(head, tail, item, prev, next) + #endif