cutils: list: add list_for_each_safe
For when you want to modify the list whilst iterating over it.
Change-Id: I84432892890987c218e56883c35e52c9ff0240a3
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
diff --git a/include/cutils/list.h b/include/cutils/list.h
index 3881fc9..72395f4 100644
--- a/include/cutils/list.h
+++ b/include/cutils/list.h
@@ -44,6 +44,11 @@
#define list_for_each_reverse(node, list) \
for (node = (list)->prev; node != (list); node = node->prev)
+#define list_for_each_safe(node, next, list) \
+ for (node = (list)->next, next = node->next; \
+ node != (list); \
+ node = next, next = node->next)
+
void list_init(struct listnode *list);
void list_add_tail(struct listnode *list, struct listnode *item);
void list_remove(struct listnode *item);