From 942f1d88431d394ac661af7b192154ba7aa68c29 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Wed, 21 Jul 2021 16:03:12 -0500 Subject: [PATCH] client: Refactor wl_proxy_destroy critical section Split wl_proxy_destroy into two pieces, wl_proxy_destroy_unlocked which performs the critical section code with no locking, and wl_proxy_destroy which locks before calling that. We'll use the new unlocked variant later in code that already holds the lock. There is a slight functional change - an aborting check is now called with the lock held. This should be harmless as wl_abort() performs no locking. Signed-off-by: Derek Foreman --- src/wayland-client.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/wayland-client.c b/src/wayland-client.c index 34814d4e..d4c8cfa0 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -514,12 +514,26 @@ proxy_destroy(struct wl_proxy *proxy) wl_proxy_unref(proxy); } +static void +wl_proxy_destroy_caller_locks(struct wl_proxy *proxy) +{ + if (proxy->flags & WL_PROXY_FLAG_WRAPPER) + wl_abort("Tried to destroy wrapper with wl_proxy_destroy()\n"); + + proxy_destroy(proxy); +} + /** Destroy a proxy object * * \param proxy The proxy to be destroyed * * \c proxy must not be a proxy wrapper. * + * \note This function will abort in response to egregious + * errors, and will do so with the display lock held. This means + * SIGABRT handlers must not perform any actions that would + * attempt to take that lock, or a deadlock would occur. + * * \memberof wl_proxy */ WL_EXPORT void @@ -527,11 +541,10 @@ wl_proxy_destroy(struct wl_proxy *proxy) { struct wl_display *display = proxy->display; - if (proxy->flags & WL_PROXY_FLAG_WRAPPER) - wl_abort("Tried to destroy wrapper with wl_proxy_destroy()\n"); - pthread_mutex_lock(&display->mutex); - proxy_destroy(proxy); + + wl_proxy_destroy_caller_locks(proxy); + pthread_mutex_unlock(&display->mutex); }