about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--btpd/queue.h13
1 files changed, 13 insertions, 0 deletions
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 =			\