diff --git a/doc/ck_queue b/doc/ck_queue index a27ec15c..df0276a0 100644 --- a/doc/ck_queue +++ b/doc/ck_queue @@ -31,6 +31,7 @@ .Nm CK_LIST_ENTRY , .Nm CK_LIST_FIRST , .Nm CK_LIST_FOREACH , +.Nm CK_LIST_FOREACH_FROM , .Nm CK_LIST_FOREACH_SAFE , .Nm CK_LIST_HEAD , .Nm CK_LIST_HEAD_INITIALIZER , @@ -46,6 +47,7 @@ .Nm CK_SLIST_ENTRY , .Nm CK_SLIST_FIRST , .Nm CK_SLIST_FOREACH , +.Nm CK_SLIST_FOREACH_FROM , .Nm CK_SLIST_FOREACH_PREVPTR , .Nm CK_SLIST_FOREACH_SAFE , .Nm CK_SLIST_HEAD , @@ -64,6 +66,7 @@ .Nm CK_STAILQ_ENTRY , .Nm CK_STAILQ_FIRST , .Nm CK_STAILQ_FOREACH , +.Nm CK_STAILQ_FOREACH_FROM , .Nm CK_STAILQ_FOREACH_SAFE , .Nm CK_STAILQ_HEAD , .Nm CK_STAILQ_HEAD_INITIALIZER , @@ -86,6 +89,7 @@ Concurrency Kit (libck, \-lck) .Fn CK_LIST_ENTRY .Fn CK_LIST_FIRST .Fn CK_LIST_FOREACH +.Fn CK_LIST_FOREACH_FROM .Fn CK_LIST_FOREACH_SAFE .Fn CK_LIST_HEAD .Fn CK_LIST_HEAD_INITIALIZER @@ -101,6 +105,7 @@ Concurrency Kit (libck, \-lck) .Fn CK_SLIST_ENTRY .Fn CK_SLIST_FIRST .Fn CK_SLIST_FOREACH +.Fn CK_SLIST_FOREACH_FROM .Fn CK_SLIST_FOREACH_PREVPTR .Fn CK_SLIST_FOREACH_SAFE .Fn CK_SLIST_HEAD @@ -119,6 +124,7 @@ Concurrency Kit (libck, \-lck) .Fn CK_STAILQ_ENTRY .Fn CK_STAILQ_FIRST .Fn CK_STAILQ_FOREACH +.Fn CK_STAILQ_FOREACH_FROM .Fn CK_STAILQ_FOREACH_SAFE .Fn CK_STAILQ_HEAD .Fn CK_STAILQ_HEAD_INITIALIZER diff --git a/include/ck_queue.h b/include/ck_queue.h index fd38d8a5..3472b0e4 100644 --- a/include/ck_queue.h +++ b/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); \