]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: lists: list_for_each_entry{_safe}_from functions
authorWilliam Lallemand <wlallemand@haproxy.com>
Sun, 24 Sep 2017 09:26:02 +0000 (11:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 02:44:11 +0000 (03:44 +0100)
Add list_for_each_entry_from and list_for_each_entry_safe_from which
allows to iterate in a list starting from a specific item.

include/common/mini-clist.h

index da24b3379d4cc1d18d0356e9d947e16b80a7f840..2988d2c20fb4bd3780d632823125cade7448c0c8 100644 (file)
@@ -127,6 +127,16 @@ struct cond_wordlist {
             &item->member != (list_head);                                \
             item = LIST_ELEM(item->member.n, typeof(item), member))
 
+/*
+ * Same as list_for_each_entry but starting from current point
+ * Iterates <item> through the list starting from <item>
+ * It's basically the same macro but without initializing item to the head of
+ * the list.
+ */
+#define list_for_each_entry_from(item, list_head, member) \
+       for ( ; &item->member != (list_head); \
+            item = LIST_ELEM(item->member.n, typeof(item), member))
+
 /*
  * Simpler FOREACH_ITEM_SAFE macro inspired from Linux sources.
  * Iterates <item> through a list of items of type "typeof(*item)" which are
@@ -142,4 +152,16 @@ struct cond_wordlist {
             item = back, back = LIST_ELEM(back->member.n, typeof(back), member))
 
 
+/*
+ * Same as list_for_each_entry_safe but starting from current point
+ * Iterates <item> through the list starting from <item>
+ * It's basically the same macro but without initializing item to the head of
+ * the list.
+ */
+#define list_for_each_entry_safe_from(item, back, list_head, member) \
+       for (back = LIST_ELEM(item->member.n, typeof(item), member);     \
+            &item->member != (list_head);                                \
+            item = back, back = LIST_ELEM(back->member.n, typeof(back), member))
+
+
 #endif /* _COMMON_MINI_CLIST_H */