From dc45054fe8ea9b4a58708616d0bc019c76ce6c32 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Tue, 20 Sep 2005 18:54:20 +0000 Subject: Add some macros. --- btpd/queue.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/btpd/queue.h b/btpd/queue.h index 9027eb1..7406017 100644 --- a/btpd/queue.h +++ b/btpd/queue.h @@ -28,8 +28,14 @@ struct { \ #define BTPDQ_FIRST(head) ((head)->tqh_first) +#define BTPDQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + #define BTPDQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define BTPDQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + #define BTPDQ_FOREACH(var, head, field) \ for ((var) = BTPDQ_FIRST((head)); \ (var); \ @@ -51,6 +57,13 @@ struct { \ (elm)->field.tqe_prev = &BTPDQ_NEXT((listelm), field); \ } while (0) +#define BTPDQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + BTPDQ_NEXT((elm), field) = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &BTPDQ_NEXT((elm), field); \ +} while (0) + #define BTPDQ_INSERT_HEAD(head, elm, field) do { \ if ((BTPDQ_NEXT((elm), field) = BTPDQ_FIRST((head))) != NULL) \ BTPDQ_FIRST((head))->field.tqe_prev = \ -- cgit 1.4.1