mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-07-08 00:06:53 -04:00
client: Add wl_proxy_unref helper
Rather than open-coded decrement-and-maybe-free, introduce a wl_proxy_unref helper to do this for us. This will come in useful for future patches, where we may also have to free a zombie object. Signed-off-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com> Cc: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
parent
b39d893397
commit
430c7820c3
1 changed files with 17 additions and 20 deletions
|
|
@ -222,6 +222,19 @@ wl_event_queue_init(struct wl_event_queue *queue, struct wl_display *display)
|
||||||
queue->display = display;
|
queue->display = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_proxy_unref(struct wl_proxy *proxy)
|
||||||
|
{
|
||||||
|
assert(proxy->refcount > 0);
|
||||||
|
if (--proxy->refcount > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* If we get here, the client must have explicitly requested
|
||||||
|
* deletion. */
|
||||||
|
assert(proxy->flags & WL_PROXY_FLAG_DESTROYED);
|
||||||
|
free(proxy);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
decrease_closure_args_refcount(struct wl_closure *closure)
|
decrease_closure_args_refcount(struct wl_closure *closure)
|
||||||
{
|
{
|
||||||
|
|
@ -241,10 +254,7 @@ decrease_closure_args_refcount(struct wl_closure *closure)
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
if (proxy->flags & WL_PROXY_FLAG_DESTROYED)
|
if (proxy->flags & WL_PROXY_FLAG_DESTROYED)
|
||||||
closure->args[i].o = NULL;
|
closure->args[i].o = NULL;
|
||||||
|
wl_proxy_unref(proxy);
|
||||||
proxy->refcount--;
|
|
||||||
if (!proxy->refcount)
|
|
||||||
free(proxy);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -257,20 +267,13 @@ static void
|
||||||
wl_event_queue_release(struct wl_event_queue *queue)
|
wl_event_queue_release(struct wl_event_queue *queue)
|
||||||
{
|
{
|
||||||
struct wl_closure *closure;
|
struct wl_closure *closure;
|
||||||
struct wl_proxy *proxy;
|
|
||||||
|
|
||||||
while (!wl_list_empty(&queue->event_list)) {
|
while (!wl_list_empty(&queue->event_list)) {
|
||||||
closure = container_of(queue->event_list.next,
|
closure = container_of(queue->event_list.next,
|
||||||
struct wl_closure, link);
|
struct wl_closure, link);
|
||||||
wl_list_remove(&closure->link);
|
wl_list_remove(&closure->link);
|
||||||
|
|
||||||
decrease_closure_args_refcount(closure);
|
decrease_closure_args_refcount(closure);
|
||||||
|
wl_proxy_unref(closure->proxy);
|
||||||
proxy = closure->proxy;
|
|
||||||
proxy->refcount--;
|
|
||||||
if (!proxy->refcount)
|
|
||||||
free(proxy);
|
|
||||||
|
|
||||||
wl_closure_destroy(closure);
|
wl_closure_destroy(closure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -416,9 +419,7 @@ proxy_destroy(struct wl_proxy *proxy)
|
||||||
|
|
||||||
proxy->flags |= WL_PROXY_FLAG_DESTROYED;
|
proxy->flags |= WL_PROXY_FLAG_DESTROYED;
|
||||||
|
|
||||||
proxy->refcount--;
|
wl_proxy_unref(proxy);
|
||||||
if (!proxy->refcount)
|
|
||||||
free(proxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Destroy a proxy object
|
/** Destroy a proxy object
|
||||||
|
|
@ -1305,11 +1306,7 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue)
|
||||||
decrease_closure_args_refcount(closure);
|
decrease_closure_args_refcount(closure);
|
||||||
proxy = closure->proxy;
|
proxy = closure->proxy;
|
||||||
proxy_destroyed = !!(proxy->flags & WL_PROXY_FLAG_DESTROYED);
|
proxy_destroyed = !!(proxy->flags & WL_PROXY_FLAG_DESTROYED);
|
||||||
|
wl_proxy_unref(proxy);
|
||||||
proxy->refcount--;
|
|
||||||
if (!proxy->refcount)
|
|
||||||
free(proxy);
|
|
||||||
|
|
||||||
if (proxy_destroyed) {
|
if (proxy_destroyed) {
|
||||||
wl_closure_destroy(closure);
|
wl_closure_destroy(closure);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue