git: 6f48a4acbeb8 - main - ck_queue: add CK_*_FOREACH_FROM

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sat, 25 Feb 2023 15:34:14 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6f48a4acbeb86ebbef90290ad73ea6be83507aa9

commit 6f48a4acbeb86ebbef90290ad73ea6be83507aa9
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-02-25 15:21:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-02-25 15:34:06 +0000

    ck_queue: add CK_*_FOREACH_FROM
    
    This is a variant of CK_*_FOREACH from FreeBSD queue.h which starts
    iteration at the specified item.  If the item pointer is NULL, iteration
    starts from the beginning of the list.
    
    Upstream commit 74366be35a6f4635f248a3c62d2d23245a4eb0f4.
    
    MFC after:      2 weeks
    Sponsored by:   Klara, Inc.
---
 sys/contrib/ck/include/ck_queue.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sys/contrib/ck/include/ck_queue.h b/sys/contrib/ck/include/ck_queue.h
index fd38d8a583fa..3472b0e40ad9 100644
--- a/sys/contrib/ck/include/ck_queue.h
+++ b/sys/contrib/ck/include/ck_queue.h
@@ -153,6 +153,11 @@ struct {									\
 	    (var);								\
 	    (var) = CK_SLIST_NEXT((var), field))
 
+#define	CK_SLIST_FOREACH_FROM(var, head, field)					\
+	for ((var) = ((var) != NULL ? (var) : CK_SLIST_FIRST((head)));		\
+	    (var);								\
+	    (var) = CK_SLIST_NEXT((var), field))
+
 #define	CK_SLIST_FOREACH_SAFE(var, head, field, tvar)				\
 	for ((var) = CK_SLIST_FIRST(head);					\
 	    (var) && ((tvar) = CK_SLIST_NEXT(var, field), 1);			\
@@ -262,6 +267,11 @@ struct {								\
 	   (var);							\
 	   (var) = CK_STAILQ_NEXT((var), field))
 
+#define	CK_STAILQ_FOREACH_FROM(var, head, field)			\
+	for ((var) = ((var) != NULL ? (var) : CK_STAILQ_FIRST((head)));	\
+	    (var);							\
+	    (var) = CK_STAILQ_NEXT((var), field))
+
 #define	CK_STAILQ_FOREACH_SAFE(var, head, field, tvar)			\
 	for ((var) = CK_STAILQ_FIRST((head));				\
 	    (var) && ((tvar) =						\
@@ -374,6 +384,11 @@ struct {									\
 	    (var);								\
 	    (var) = CK_LIST_NEXT((var), field))
 
+#define	CK_LIST_FOREACH_FROM(var, head, field)					\
+	for ((var) = ((var) != NULL ? (var) : CK_LIST_FIRST((head)));		\
+	    (var);								\
+	    (var) = CK_LIST_NEXT((var), field))
+
 #define	CK_LIST_FOREACH_SAFE(var, head, field, tvar)				  \
 	for ((var) = CK_LIST_FIRST((head));					  \
 	    (var) && ((tvar) = CK_LIST_NEXT((var), field), 1);			  \