util/list: Add list_foreach_entry_from_safe
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Tue, 17 Sep 2019 01:21:06 +0000 (18:21 -0700)
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 17800e4ed4e9f479653ccd1e9f60489d813108db..d50eb1ea5dde481711d1f726d47323d8544b4d3a 100644 (file)
@@ -241,6 +241,13 @@ static inline void list_validate(const struct list_head *list)
        &pos->member != (head);                                         \
        pos = LIST_ENTRY(type, pos->member.next, member))
 
+#define list_for_each_entry_from_safe(type, pos, start, head, member)   \
+   for (type *pos = LIST_ENTRY(type, (start), 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_from_rev(type, pos, start, head, member)    \
    for (type *pos = LIST_ENTRY(type, (start), member);                  \
        &pos->member != (head);                                         \