From 308540c2fea54acc9b152e67252812fc530a9768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qian=20Hu=20=28=E8=83=A1=E9=AA=9E=29?= Date: Mon, 24 Feb 2025 09:43:12 +0800 Subject: [PATCH] wayland: add synchronized object destruction function Introduces a new generic destruction function gst_wl_display_object_destroy that ensures all destruction operations are protected by sync_mutex. Part-of: --- .../gst-libs/gst/wayland/gstwldisplay.c | 22 +++++++++++++++++++ .../gst-libs/gst/wayland/gstwldisplay.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.c b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.c index edae01de8b..5142d3ad4b 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.c @@ -558,6 +558,28 @@ gst_wl_display_sync (GstWlDisplay * self, return callback; } +/* gst_wl_display_object_destroy + * + * A syncronized version of `xxx_destroy` that ensures that the + * once this function returns, the destroy_func will either have already completed, + * or will never be called. + */ +void +gst_wl_display_object_destroy (GstWlDisplay * self, + gpointer * object, GDestroyNotify destroy_func) +{ + GstWlDisplayPrivate *priv = gst_wl_display_get_instance_private (self); + + g_rec_mutex_lock (&priv->sync_mutex); + + if (*object) { + destroy_func (*object); + *object = NULL; + } + + g_rec_mutex_unlock (&priv->sync_mutex); +} + /* gst_wl_display_callback_destroy * * A syncronized version of `wl_callback_destroy` that ensures that the diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.h b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.h index 485cf18ac8..b2f0ca35e8 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/wayland/gstwldisplay.h @@ -56,6 +56,9 @@ GST_WL_API struct wl_callback * gst_wl_display_sync(GstWlDisplay * self, const struct wl_callback_listener *listener, gpointer data); +GST_WL_API +void gst_wl_display_object_destroy (GstWlDisplay * self, gpointer *object, GDestroyNotify destroy_func); + GST_WL_API void gst_wl_display_callback_destroy(GstWlDisplay * self, struct wl_callback ** callback);