summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2008-05-22 14:40:03 +0000
committered <ed@FreeBSD.org>2008-05-22 14:40:03 +0000
commitd5f58395c36e992d3a854bd647f411bb67b6471b (patch)
treeb0da12855d9e0a37cd43331a956e65edea4624da /sys
parent48d3064e97a093b9da51c6dc8eb2550ce2057454 (diff)
downloadFreeBSD-src-d5f58395c36e992d3a854bd647f411bb67b6471b.zip
FreeBSD-src-d5f58395c36e992d3a854bd647f411bb67b6471b.tar.gz
Introduce REMOVE_NEXT() macro's for SLIST and STAILQ.
Even though single linked lists allow items to be removed at constant time (when the previous element is known), the queue macro's don't allow this. Implement new REMOVE_NEXT() macro's. Because the REMOVE() macro's also contain the same code, make it call REMOVE_NEXT(). The OpenBSD version of SLIST_REMOVE_NEXT() needs a reference to the list head, even though it is unused. We'd better mimic this. The STAILQ version also needs a reference to the list. This means the prototypes of both macro's are the same. Approved by: philip (mentor) PR: kern/121117
Diffstat (limited to 'sys')
-rw-r--r--sys/sys/queue.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
index eefd620..3a0a354 100644
--- a/sys/sys/queue.h
+++ b/sys/sys/queue.h
@@ -97,6 +97,7 @@
* _INSERT_TAIL - - + +
* _CONCAT - - + +
* _REMOVE_HEAD + - + -
+ * _REMOVE_NEXT + - + -
* _REMOVE + + + +
*
*/
@@ -195,12 +196,16 @@ struct { \
struct type *curelm = SLIST_FIRST((head)); \
while (SLIST_NEXT(curelm, field) != (elm)) \
curelm = SLIST_NEXT(curelm, field); \
- SLIST_NEXT(curelm, field) = \
- SLIST_NEXT(SLIST_NEXT(curelm, field), field); \
+ SLIST_REMOVE_NEXT(head, curelm, field); \
} \
TRASHIT((elm)->field.sle_next); \
} while (0)
+#define SLIST_REMOVE_NEXT(head, elm, field) do { \
+ SLIST_NEXT(elm, field) = \
+ SLIST_NEXT(SLIST_NEXT(elm, field), field); \
+} while (0)
+
#define SLIST_REMOVE_HEAD(head, field) do { \
SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \
} while (0)
@@ -287,9 +292,7 @@ struct { \
struct type *curelm = STAILQ_FIRST((head)); \
while (STAILQ_NEXT(curelm, field) != (elm)) \
curelm = STAILQ_NEXT(curelm, field); \
- if ((STAILQ_NEXT(curelm, field) = \
- STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\
- (head)->stqh_last = &STAILQ_NEXT((curelm), field);\
+ STAILQ_REMOVE_NEXT(head, curelm, field); \
} \
TRASHIT((elm)->field.stqe_next); \
} while (0)
@@ -300,6 +303,12 @@ struct { \
(head)->stqh_last = &STAILQ_FIRST((head)); \
} while (0)
+#define STAILQ_REMOVE_NEXT(head, elm, field) do { \
+ if ((STAILQ_NEXT(elm, field) = \
+ STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \
+ (head)->stqh_last = &STAILQ_NEXT((elm), field); \
+} while (0)
+
/*
* List declarations.
*/
OpenPOWER on IntegriCloud