[RFC 2/2] server: add WL_GUARD macros
Pekka Paalanen
ppaalanen at gmail.com
Fri Mar 2 04:13:16 PST 2012
From: Pekka Paalanen <ppaalanen at gmail.com>
---
Does this make the code easier to read or not?
I cannot judge it, since I wrote the macros.
src/data-device.c | 5 ++---
src/wayland-server.h | 15 +++++++++++++--
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/data-device.c b/src/data-device.c
index ce55c7a..6d35aad 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -66,7 +66,7 @@ destroy_data_offer(struct wl_resource *resource)
{
struct wl_data_offer *offer = resource->data;
- wl_guard_unset(&offer->source_guard);
+ WL_GUARD_UNSET(offer->source);
free(offer);
}
@@ -101,8 +101,7 @@ wl_data_source_send_offer(struct wl_data_source *source,
offer->resource.data = offer;
wl_list_init(&offer->resource.destroy_listener_list);
- offer->source = source;
- wl_guard_set(&offer->source_guard, &source->resource, &offer->source);
+ WL_GUARD_SET(offer->source, source);
wl_client_add_resource(target->client, &offer->resource);
diff --git a/src/wayland-server.h b/src/wayland-server.h
index af3138f..d7e5e0a 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -150,6 +150,10 @@ struct wl_guard {
void **pointer;
};
+#define WL_GUARDED_POINTER(TYPE, NAME) \
+ TYPE *NAME; \
+ struct wl_guard NAME##_guard;
+
struct wl_surface {
struct wl_resource resource;
};
@@ -186,8 +190,7 @@ struct wl_keyboard_grab {
struct wl_data_offer {
struct wl_resource resource;
- struct wl_data_source *source;
- struct wl_guard source_guard;
+ WL_GUARDED_POINTER(struct wl_data_source, source);
};
struct wl_data_source {
@@ -356,6 +359,14 @@ wl_guard_set(struct wl_guard *guard, struct wl_resource *resource,
void
wl_guard_unset(struct wl_guard *guard);
+#define WL_GUARD_SET(POINTER, OBJECT) do { \
+ POINTER = OBJECT; \
+ wl_guard_set(&(POINTER##_guard), &(OBJECT)->resource, &(POINTER)); \
+} while (0)
+
+#define WL_GUARD_UNSET(POINTER) \
+ wl_guard_unset(&(POINTER##_guard))
+
#ifdef __cplusplus
}
#endif
--
1.7.3.4
More information about the wayland-devel
mailing list