[Mesa-dev] [PATCH 02/16] glsl: Add typed foreach_in_list_safe macro.

Matt Turner mattst88 at gmail.com
Wed Jun 25 11:51:03 PDT 2014


---
 src/glsl/list.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/glsl/list.h b/src/glsl/list.h
index 914ce96..a4c6408 100644
--- a/src/glsl/list.h
+++ b/src/glsl/list.h
@@ -584,6 +584,15 @@ inline void exec_node::insert_before(exec_list *before)
         (__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.
  *
  * This is safe against either current node being removed or replaced.
-- 
1.8.3.2



More information about the mesa-dev mailing list