[PATCH wayland] wayland-server: Add a wl_resource_for_each_safe macro

Rob Bradford robert.bradford at intel.com
Fri Sep 6 09:56:27 PDT 2013


From: Rob Bradford <rob at linux.intel.com>

A version of wl_resource_for_each that is safe for iteration when items
in the list are removed.
---
 src/wayland-server.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/wayland-server.h b/src/wayland-server.h
index d77050d..c0365c0 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -313,6 +313,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 *
-- 
1.8.3.1



More information about the wayland-devel mailing list