From ac97145b404df2b80144c46cdec1bccc3949bcd0 Mon Sep 17 00:00:00 2001 From: michalbiesek Date: Fri, 14 Jun 2019 15:36:03 +0200 Subject: [PATCH] cc: extend queue module - add function to reinit tailq which supports pointer arithmetics --- include/cc_queue.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/cc_queue.h b/include/cc_queue.h index c8f8a5ce..4349f510 100644 --- a/include/cc_queue.h +++ b/include/cc_queue.h @@ -127,6 +127,7 @@ extern "C" { * _INSERT_TAIL - - + + + * _REMOVE_HEAD + - + - - * _REMOVE + + + + + + * _REINIT - - - + - * */ @@ -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. */