glsl: Use a new foreach_two_lists macro for walking two lists at once.
[mesa.git] / src / glsl / list.h
index 3197b03cf2832a51fd9044e72f9debb55f33cb8f..f9eb60ec7c4f07d6dbe428341d759252172cd5be 100644 (file)
 
 #ifndef __cplusplus
 #include <stddef.h>
-#include <talloc.h>
-#else
-extern "C" {
-#include <talloc.h>
-}
 #endif
-
 #include <assert.h>
 
+#include "ralloc.h"
+
 struct exec_node {
    struct exec_node *next;
    struct exec_node *prev;
 
 #ifdef __cplusplus
-   /* Callers of this talloc-based new need not call delete. It's
-    * easier to just talloc_free 'ctx' (or any of its ancestors). */
-   static void* operator new(size_t size, void *ctx)
-   {
-      void *node;
-
-      node = talloc_size(ctx, size);
-      assert(node != NULL);
-
-      return node;
-   }
-
-   /* If the user *does* call delete, that's OK, we will just
-    * talloc_free in that case. */
-   static void operator delete(void *node)
-   {
-      talloc_free(node);
-   }
+   DECLARE_RALLOC_CXX_OPERATORS(exec_node)
 
    exec_node() : next(NULL), prev(NULL)
    {
@@ -289,24 +268,7 @@ struct exec_list {
    struct exec_node *tail_pred;
 
 #ifdef __cplusplus
-   /* Callers of this talloc-based new need not call delete. It's
-    * easier to just talloc_free 'ctx' (or any of its ancestors). */
-   static void* operator new(size_t size, void *ctx)
-   {
-      void *node;
-
-      node = talloc_size(ctx, size);
-      assert(node != NULL);
-
-      return node;
-   }
-
-   /* If the user *does* call delete, that's OK, we will just
-    * talloc_free in that case. */
-   static void operator delete(void *node)
-   {
-      talloc_free(node);
-   }
+   DECLARE_RALLOC_CXX_OPERATORS(exec_list)
 
    exec_list()
    {
@@ -485,6 +447,22 @@ inline void exec_node::insert_before(exec_list *before)
        ; (__node)->next != NULL                        \
        ; (__node) = (__node)->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.
+ */
+#define foreach_two_lists(__node1, __list1, __node2, __list2) \
+   for (exec_node * __node1 = (__list1)->head,                \
+                  * __node2 = (__list2)->head,                \
+                  * __next1 = __node1->next,                  \
+                  * __next2 = __node2->next                   \
+       ; __next1 != NULL && __next2 != NULL                  \
+       ; __node1 = __next1,                                  \
+          __node2 = __next2,                                  \
+          __next1 = __next1->next,                            \
+          __next2 = __next2->next)
+
 #define foreach_list_const(__node, __list)             \
    for (const exec_node * __node = (__list)->head      \
        ; (__node)->next != NULL                        \