wayland-server: Add a wl_resource_for_each_safe macro
authorRob Bradford <rob@linux.intel.com>
Fri, 6 Sep 2013 16:56:27 +0000 (17:56 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 11 Sep 2013 19:03:22 +0000 (12:03 -0700)
A version of wl_resource_for_each that is safe for iteration when items
in the list are removed.

src/wayland-server.h

index 7404c3b..67f3bdd 100644 (file)
@@ -350,6 +350,14 @@ wl_resource_get_destroy_listener(struct wl_resource *resource,
             wl_resource_get_link(resource) != (list);                          \
             resource = wl_resource_from_link(wl_resource_get_link(resource)->next))
 
+#define wl_resource_for_each_safe(resource, tmp, list)                                 \
+       for (resource = 0, tmp = 0,                                                     \
+            resource = wl_resource_from_link((list)->next),    \
+            tmp = wl_resource_from_link((list)->next->next);   \
+            wl_resource_get_link(resource) != (list);                          \
+            resource = tmp,                                                    \
+            tmp = wl_resource_from_link(wl_resource_get_link(resource)->next))
+
 struct wl_shm_buffer;
 
 struct wl_shm_buffer *