summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2015-04-27 18:56:02 -0700
committerJason Ekstrand <jason.ekstrand@intel.com>2015-05-08 17:16:13 -0700
commitb31d8983ba5d68f3bcb5520b9281a4553d66fb95 (patch)
treefd6a27aff1a951fd5488bed47c98f9b497e7e5d0 /src/util
parent7a30668ad665f3315106e1a959c6186dea79a24a (diff)
util/list: Add C99-based iterator macros
v2: Use LIST_ENTRY instead of container_of in iterators Acked-by: Connor Abbott <cwabbott0@gmail.com> Reviewed-by: Rob Clark <robclark@freedesktop.org>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/list.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/util/list.h b/src/util/list.h
index 191030c47b..287a4946dc 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -143,4 +143,38 @@ static inline void list_delinit(struct list_head *item)
&pos->member != (head); \
pos = container_of(pos->member.prev, pos, member))
+#define list_for_each_entry(type, pos, head, member) \
+ for (type *pos = LIST_ENTRY(type, (head)->next, member); \
+ &pos->member != (head); \
+ pos = LIST_ENTRY(type, pos->member.next, member))
+
+#define list_for_each_entry_safe(type, pos, head, member) \
+ for (type *pos = LIST_ENTRY(type, (head)->next, member), \
+ *__next = LIST_ENTRY(type, pos->member.next, member); \
+ &pos->member != (head); \
+ pos = __next, \
+ __next = LIST_ENTRY(type, __next->member.next, member))
+
+#define list_for_each_entry_rev(type, pos, head, member) \
+ for (type *pos = LIST_ENTRY(type, (head)->prev, member); \
+ &pos->member != (head); \
+ pos = LIST_ENTRY(type, pos->member.prev, member))
+
+#define list_for_each_entry_safe_rev(type, pos, head, member) \
+ for (type *pos = LIST_ENTRY(type, (head)->prev, member), \
+ *__prev = LIST_ENTRY(type, pos->member.prev, member); \
+ &pos->member != (head); \
+ pos = __prev, \
+ __prev = LIST_ENTRY(type, __prev->member.prev, member))
+
+#define list_for_each_entry_from(type, pos, start, head, member) \
+ for (type *pos = LIST_ENTRY(type, (start), member); \
+ &pos->member != (head); \
+ pos = LIST_ENTRY(type, pos->member.next, member))
+
+#define list_for_each_entry_from_rev(type, pos, start, head, member) \
+ for (type *pos = LIST_ENTRY(type, (start), member); \
+ &pos->member != (head); \
+ pos = LIST_ENTRY(type, pos->member.prev, member))
+
#endif /*_UTIL_LIST_H_*/