It is derived from BSD with only the MACRO names being prefixed with DWC_. This is because a few of these names conflict with those on Linux. For documentation on use, see the inline comments in the source code. The original license for this source code applies and is preserved in the dwc_list.h source file.
#define DWC_LIST_INIT | ( | link | ) |
Value:
do{ \ (link)->next = (link); \ (link)->prev = (link); \ } while(0)
#define DWC_LIST_ENTRY | ( | link, | |||
type, | |||||
field | ) |
Value:
(type *) \ ((uint8_t *)(link) - (size_t)(&((type *)0)->field))
#define DWC_LIST_INSERT_HEAD | ( | list, | |||
link | ) |
Value:
do { \ (link)->next = (list)->next; \ (link)->prev = (list); \ (list)->next->prev = link; \ (list)->next = link; \ } while(0)
#define DWC_LIST_INSERT_TAIL | ( | list, | |||
link | ) |
Value:
do { \ (link)->next = list; \ (link)->prev = (list)->prev; \ (list)->prev->next = link; \ (list)->prev = link; \ } while(0)
#define DWC_LIST_REMOVE | ( | link | ) |
Value:
do { \ (link)->next->prev = (link)->prev; \ (link)->prev->next = (link)->next; \ } while(0)
#define DWC_LIST_REMOVE_INIT | ( | link | ) |
Value:
do { \ DWC_LIST_REMOVE(link); \ DWC_LIST_INIT(link); \ } while(0)
#define DWC_LIST_MOVE_HEAD | ( | list, | |||
link | ) |
Value:
do { \ DWC_LIST_REMOVE(link); \ DWC_LIST_INSERT_HEAD(list, link); \ } while(0)
#define DWC_LIST_MOVE_TAIL | ( | list, | |||
link | ) |
Value:
do { \ DWC_LIST_REMOVE(link); \ DWC_LIST_INSERT_TAIL(list, link); \ } while(0)
#define DWC_LIST_FOREACH | ( | var, | |||
list | ) |
Value:
for((var) = DWC_LIST_FIRST(list); \
(var) != DWC_LIST_END(list); \
(var) = DWC_LIST_NEXT(var))
#define DWC_LIST_FOREACH_SAFE | ( | var, | |||
var2, | |||||
list | ) |
Value:
for((var) = DWC_LIST_FIRST(list), var2 = DWC_LIST_NEXT(var); \
(var) != DWC_LIST_END(list); \
(var) = (var2), var2 = DWC_LIST_NEXT(var2))
#define DWC_LIST_FOREACH_REVERSE | ( | var, | |||
list | ) |
Value:
for((var) = DWC_LIST_LAST(list); \
(var) != DWC_LIST_END(list); \
(var) = DWC_LIST_PREV(var))
#define DWC_SLIST_HEAD | ( | name, | |||
type | ) |
Value:
struct name { \ struct type *slh_first; /* first element */ \ }
#define DWC_SLIST_ENTRY | ( | type | ) |
Value:
struct { \ struct type *sle_next; /* next element */ \ }
#define DWC_SLIST_FOREACH | ( | var, | |||
head, | |||||
field | ) |
Value:
for((var) = SLIST_FIRST(head); \
(var) != SLIST_END(head); \
(var) = SLIST_NEXT(var, field))
#define DWC_SLIST_FOREACH_PREVPTR | ( | var, | |||
varp, | |||||
head, | |||||
field | ) |
Value:
for ((varp) = &SLIST_FIRST((head)); \
((var) = *(varp)) != SLIST_END(head); \
(varp) = &SLIST_NEXT((var), field))
#define DWC_SLIST_INIT | ( | head | ) |
Value:
{ \ SLIST_FIRST(head) = SLIST_END(head); \ }
#define DWC_SLIST_INSERT_AFTER | ( | slistelm, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.sle_next = (slistelm)->field.sle_next; \ (slistelm)->field.sle_next = (elm); \ } while (0)
#define DWC_SLIST_INSERT_HEAD | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.sle_next = (head)->slh_first; \ (head)->slh_first = (elm); \ } while (0)
#define DWC_SLIST_REMOVE_NEXT | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ } while (0)
#define DWC_SLIST_REMOVE_HEAD | ( | head, | |||
field | ) |
Value:
do { \ (head)->slh_first = (head)->slh_first->field.sle_next; \ } while (0)
#define DWC_SLIST_REMOVE | ( | head, | |||
elm, | |||||
type, | |||||
field | ) |
Value:
do { \ if ((head)->slh_first == (elm)) { \ SLIST_REMOVE_HEAD((head), field); \ } \ else { \ struct type *curelm = (head)->slh_first; \ while( curelm->field.sle_next != (elm) ) \ curelm = curelm->field.sle_next; \ curelm->field.sle_next = \ curelm->field.sle_next->field.sle_next; \ } \ } while (0)
#define DWC_SIMPLEQ_HEAD | ( | name, | |||
type | ) |
Value:
struct name { \ struct type *sqh_first; /* first element */ \ struct type **sqh_last; /* addr of last next element */ \ }
#define DWC_SIMPLEQ_ENTRY | ( | type | ) |
Value:
struct { \ struct type *sqe_next; /* next element */ \ }
#define DWC_SIMPLEQ_FOREACH | ( | var, | |||
head, | |||||
field | ) |
Value:
for((var) = SIMPLEQ_FIRST(head); \
(var) != SIMPLEQ_END(head); \
(var) = SIMPLEQ_NEXT(var, field))
#define DWC_SIMPLEQ_INIT | ( | head | ) |
Value:
do { \ (head)->sqh_first = NULL; \ (head)->sqh_last = &(head)->sqh_first; \ } while (0)
#define DWC_SIMPLEQ_INSERT_HEAD | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ (head)->sqh_last = &(elm)->field.sqe_next; \ (head)->sqh_first = (elm); \ } while (0)
#define DWC_SIMPLEQ_INSERT_TAIL | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.sqe_next = NULL; \ *(head)->sqh_last = (elm); \ (head)->sqh_last = &(elm)->field.sqe_next; \ } while (0)
#define DWC_SIMPLEQ_INSERT_AFTER | ( | head, | |||
listelm, | |||||
elm, | |||||
field | ) |
Value:
do { \ if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ (head)->sqh_last = &(elm)->field.sqe_next; \ (listelm)->field.sqe_next = (elm); \ } while (0)
#define DWC_SIMPLEQ_REMOVE_HEAD | ( | head, | |||
field | ) |
Value:
do { \ if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ (head)->sqh_last = &(head)->sqh_first; \ } while (0)
#define DWC_TAILQ_HEAD | ( | name, | |||
type | ) |
Value:
struct name { \ struct type *tqh_first; /* first element */ \ struct type **tqh_last; /* addr of last next element */ \ }
#define DWC_TAILQ_ENTRY | ( | type | ) |
Value:
struct { \ struct type *tqe_next; /* next element */ \ struct type **tqe_prev; /* address of previous next element */ \ }
#define DWC_TAILQ_FOREACH | ( | var, | |||
head, | |||||
field | ) |
Value:
for((var) = TAILQ_FIRST(head); \
(var) != TAILQ_END(head); \
(var) = TAILQ_NEXT(var, field))
#define DWC_TAILQ_FOREACH_REVERSE | ( | var, | |||
head, | |||||
headname, | |||||
field | ) |
Value:
for((var) = TAILQ_LAST(head, headname); \
(var) != TAILQ_END(head); \
(var) = TAILQ_PREV(var, headname, field))
#define DWC_TAILQ_INIT | ( | head | ) |
Value:
do { \ (head)->tqh_first = NULL; \ (head)->tqh_last = &(head)->tqh_first; \ } while (0)
#define DWC_TAILQ_INSERT_HEAD | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ (head)->tqh_first->field.tqe_prev = \ &(elm)->field.tqe_next; \ else \ (head)->tqh_last = &(elm)->field.tqe_next; \ (head)->tqh_first = (elm); \ (elm)->field.tqe_prev = &(head)->tqh_first; \ } while (0)
#define DWC_TAILQ_INSERT_TAIL | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.tqe_next = NULL; \ (elm)->field.tqe_prev = (head)->tqh_last; \ *(head)->tqh_last = (elm); \ (head)->tqh_last = &(elm)->field.tqe_next; \ } while (0)
#define DWC_TAILQ_INSERT_AFTER | ( | head, | |||
listelm, | |||||
elm, | |||||
field | ) |
Value:
do { \ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ (elm)->field.tqe_next->field.tqe_prev = \ &(elm)->field.tqe_next; \ else \ (head)->tqh_last = &(elm)->field.tqe_next; \ (listelm)->field.tqe_next = (elm); \ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ } while (0)
#define DWC_TAILQ_INSERT_BEFORE | ( | listelm, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ (elm)->field.tqe_next = (listelm); \ *(listelm)->field.tqe_prev = (elm); \ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ } while (0)
#define DWC_TAILQ_REMOVE | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ if (((elm)->field.tqe_next) != NULL) \ (elm)->field.tqe_next->field.tqe_prev = \ (elm)->field.tqe_prev; \ else \ (head)->tqh_last = (elm)->field.tqe_prev; \ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ } while (0)
#define DWC_TAILQ_REPLACE | ( | head, | |||
elm, | |||||
elm2, | |||||
field | ) |
Value:
do { \ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ (elm2)->field.tqe_next->field.tqe_prev = \ &(elm2)->field.tqe_next; \ else \ (head)->tqh_last = &(elm2)->field.tqe_next; \ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ *(elm2)->field.tqe_prev = (elm2); \ } while (0)
#define DWC_CIRCLEQ_HEAD | ( | name, | |||
type | ) |
Value:
struct name { \ struct type *cqh_first; /* first element */ \ struct type *cqh_last; /* last element */ \ }
#define DWC_CIRCLEQ_ENTRY | ( | type | ) |
Value:
struct { \ struct type *cqe_next; /* next element */ \ struct type *cqe_prev; /* previous element */ \ }
#define DWC_CIRCLEQ_FOREACH | ( | var, | |||
head, | |||||
field | ) |
Value:
for((var) = DWC_CIRCLEQ_FIRST(head); \
(var) != DWC_CIRCLEQ_END(head); \
(var) = DWC_CIRCLEQ_NEXT(var, field))
#define DWC_CIRCLEQ_FOREACH_SAFE | ( | var, | |||
var2, | |||||
head, | |||||
field | ) |
Value:
for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
(var) != DWC_CIRCLEQ_END(head); \
(var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
#define DWC_CIRCLEQ_FOREACH_REVERSE | ( | var, | |||
head, | |||||
field | ) |
Value:
for((var) = DWC_CIRCLEQ_LAST(head); \
(var) != DWC_CIRCLEQ_END(head); \
(var) = DWC_CIRCLEQ_PREV(var, field))
#define DWC_CIRCLEQ_INIT | ( | head | ) |
Value:
do { \ (head)->cqh_first = DWC_CIRCLEQ_END(head); \ (head)->cqh_last = DWC_CIRCLEQ_END(head); \ } while (0)
#define DWC_CIRCLEQ_INIT_ENTRY | ( | elm, | |||
field | ) |
Value:
do { \ (elm)->field.cqe_next = NULL; \ (elm)->field.cqe_prev = NULL; \ } while (0)
#define DWC_CIRCLEQ_INSERT_AFTER | ( | head, | |||
listelm, | |||||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.cqe_next = (listelm)->field.cqe_next; \ (elm)->field.cqe_prev = (listelm); \ if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \ (head)->cqh_last = (elm); \ else \ (listelm)->field.cqe_next->field.cqe_prev = (elm); \ (listelm)->field.cqe_next = (elm); \ } while (0)
#define DWC_CIRCLEQ_INSERT_BEFORE | ( | head, | |||
listelm, | |||||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.cqe_next = (listelm); \ (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \ (head)->cqh_first = (elm); \ else \ (listelm)->field.cqe_prev->field.cqe_next = (elm); \ (listelm)->field.cqe_prev = (elm); \ } while (0)
#define DWC_CIRCLEQ_INSERT_HEAD | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.cqe_next = (head)->cqh_first; \ (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \ if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \ (head)->cqh_last = (elm); \ else \ (head)->cqh_first->field.cqe_prev = (elm); \ (head)->cqh_first = (elm); \ } while (0)
#define DWC_CIRCLEQ_INSERT_TAIL | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \ (elm)->field.cqe_prev = (head)->cqh_last; \ if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \ (head)->cqh_first = (elm); \ else \ (head)->cqh_last->field.cqe_next = (elm); \ (head)->cqh_last = (elm); \ } while (0)
#define DWC_CIRCLEQ_REMOVE | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \ (head)->cqh_last = (elm)->field.cqe_prev; \ else \ (elm)->field.cqe_next->field.cqe_prev = \ (elm)->field.cqe_prev; \ if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \ (head)->cqh_first = (elm)->field.cqe_next; \ else \ (elm)->field.cqe_prev->field.cqe_next = \ (elm)->field.cqe_next; \ } while (0)
#define DWC_CIRCLEQ_REMOVE_INIT | ( | head, | |||
elm, | |||||
field | ) |
Value:
do { \ DWC_CIRCLEQ_REMOVE(head, elm, field); \ DWC_CIRCLEQ_INIT_ENTRY(elm, field); \ } while (0)
#define DWC_CIRCLEQ_REPLACE | ( | head, | |||
elm, | |||||
elm2, | |||||
field | ) |
Value:
do { \ if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \ DWC_CIRCLEQ_END(head)) \ (head).cqh_last = (elm2); \ else \ (elm2)->field.cqe_next->field.cqe_prev = (elm2); \ if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \ DWC_CIRCLEQ_END(head)) \ (head).cqh_first = (elm2); \ else \ (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ } while (0)