Skip to content

Commit

Permalink
cc: extend queue module
Browse files Browse the repository at this point in the history
- add function to reinit tailq which supports pointer arithmetics
  • Loading branch information
michalbiesek committed Jun 14, 2019
1 parent 6c98c8e commit 328ca05
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions deps/ccommon/include/cc_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ extern "C" {
* _INSERT_TAIL - - + + +
* _REMOVE_HEAD + - + - -
* _REMOVE + + + + +
* _REINIT - - - + -
*
*/

Expand Down Expand Up @@ -691,6 +692,23 @@ struct { \
(head2)->tqh_last = &(head2)->tqh_first; \
} while (0)

#define TAILQ_REINIT(head, var, field, offset) do { \
TAILQ_FIRST((head)) = var; \
*(head)->tqh_last = NULL; \
TAILQ_FOREACH(var, head, s_tqe) { \
if ((TAILQ_NEXT((var), field)) != NULL) { \
TAILQ_NEXT((var), field) = \
(void *)((char *)(TAILQ_NEXT((var), field)) + (offset));\
} \
if ((var) == TAILQ_FIRST(head)) { \
(var)->field.tqe_prev = &TAILQ_FIRST(head); \
} else { \
(var)->field.tqe_prev = \
(void *)((char *)((var)->field.tqe_prev) + (offset)); \
} \
} \
} while (0)

/*
* Circular queue declarations.
*/
Expand Down

0 comments on commit 328ca05

Please sign in to comment.