From: Matt Turner Date: Tue, 24 Jun 2014 23:32:29 +0000 (-0700) Subject: glsl: Add typed foreach_in_list_safe macro. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=da9f0316e6ea628c085040a0c145580301207489;p=mesa.git glsl: Add typed foreach_in_list_safe macro. Reviewed-by: Ian Romanick --- diff --git a/src/glsl/list.h b/src/glsl/list.h index 914ce962527..a4c64082122 100644 --- a/src/glsl/list.h +++ b/src/glsl/list.h @@ -583,6 +583,15 @@ inline void exec_node::insert_before(exec_list *before) !(__inst)->is_head_sentinel(); \ (__inst) = (__type *)(__inst)->prev) +/** + * This version is safe even if the current node is removed. + */ +#define foreach_in_list_safe(__type, __node, __list) \ + for (__type *__node = (__type *)(__list)->head, \ + *__next = (__type *)__node->next; \ + __next != NULL; \ + __node = __next, __next = (__type *)__next->next) + /** * Iterate through two lists at once. Stops at the end of the shorter list. *