aboutsummaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-02-14 19:44:31 -0500
committerIan Moffett <ian@osmora.org>2024-02-14 19:44:31 -0500
commit1a2a2e12cdb4712f85c929c054abed14b39d3836 (patch)
tree76fa42f4a7656b31a656db5c8b4e32ba3c8e2bfd /sys/include
parent2440a9d67b0785132e303ed6f12dff8e80baa547 (diff)
kernel: queue: Keep track of element count
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/sys/queue.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/sys/include/sys/queue.h b/sys/include/sys/queue.h
index 963e695..ee5c96b 100644
--- a/sys/include/sys/queue.h
+++ b/sys/include/sys/queue.h
@@ -27,6 +27,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/types.h>
+
#define _Q_INVALIDATE(a)
/*
@@ -36,6 +38,7 @@
struct name { \
struct type *tqh_first; /* first element */ \
struct type **tqh_last; /* addr of last next element */ \
+ size_t nelem; /* Number of elements */ \
}
#define TAILQ_HEAD_INITIALIZER(head) \
@@ -50,6 +53,7 @@ struct { \
/*
* Tail queue access methods.
*/
+#define TAILQ_NELEM(head) ((head)->nelem)
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_END(head) NULL
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
@@ -90,6 +94,7 @@ struct { \
#define TAILQ_INIT(head) do { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
+ (head)->nelem = 0; \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
@@ -100,6 +105,7 @@ struct { \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
+ ++(head)->nelem; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
@@ -107,6 +113,7 @@ struct { \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
+ ++(head)->nelem; \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
@@ -117,6 +124,7 @@ struct { \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
+ ++(head)->nelem; \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
@@ -124,6 +132,7 @@ struct { \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
+ ++(head)->nelem; \
} while (0)
#define TAILQ_REMOVE(head, elm, field) do { \
@@ -135,6 +144,7 @@ struct { \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
_Q_INVALIDATE((elm)->field.tqe_prev); \
_Q_INVALIDATE((elm)->field.tqe_next); \
+ --(head)->nelem; \
} while (0)
#define TAILQ_REPLACE(head, elm, elm2, field) do { \