util/list: Add a list pair iterator
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 5 Aug 2019 21:19:06 +0000 (16:19 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 13 May 2020 23:36:44 +0000 (23:36 +0000)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5019>

src/util/list.h

index 8a18c4b0d8d8b99f500359082a5d1906b2d1a95b..17800e4ed4e9f479653ccd1e9f60489d813108db 100644 (file)
@@ -246,4 +246,11 @@ static inline void list_validate(const struct list_head *list)
        &pos->member != (head);                                         \
        pos = LIST_ENTRY(type, pos->member.prev, member))
 
+#define list_pair_for_each_entry(type, pos1, pos2, head1, head2, member) \
+   for (type *pos1 = LIST_ENTRY(type, (head1)->next, member),           \
+             *pos2 = LIST_ENTRY(type, (head2)->next, member);           \
+        &pos1->member != (head1) && &pos2->member != (head2);           \
+       pos1 = LIST_ENTRY(type, pos1->member.next, member),               \
+       pos2 = LIST_ENTRY(type, pos2->member.next, member))
+
 #endif /*_UTIL_LIST_H_*/