diff options
author | Jason Ekstrand <[email protected]> | 2015-04-27 18:56:02 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2015-05-08 17:16:13 -0700 |
commit | b31d8983ba5d68f3bcb5520b9281a4553d66fb95 (patch) | |
tree | fd6a27aff1a951fd5488bed47c98f9b497e7e5d0 | |
parent | 7a30668ad665f3315106e1a959c6186dea79a24a (diff) |
util/list: Add C99-based iterator macros
v2: Use LIST_ENTRY instead of container_of in iterators
Acked-by: Connor Abbott <[email protected]>
Reviewed-by: Rob Clark <[email protected]>
-rw-r--r-- | src/util/list.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/util/list.h b/src/util/list.h index 191030c47bb..287a4946dc6 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_*/ |