From 3aafef7955a9df429db2daa527577c94cbc6bd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 9 Jul 2022 17:04:07 +0300 Subject: [PATCH] gst: Protect initialization state with a recursive mutex. Otherwise a gst_init() call from a plugin would deadlock if the plugin is loaded as part of registry updating. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/940 Part-of: --- subprojects/gstreamer/gst/gst.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/subprojects/gstreamer/gst/gst.c b/subprojects/gstreamer/gst/gst.c index 19e2cb0171..cd1f8f8d80 100644 --- a/subprojects/gstreamer/gst/gst.c +++ b/subprojects/gstreamer/gst/gst.c @@ -131,7 +131,7 @@ static gboolean gst_initialized = FALSE; static gboolean gst_deinitialized = FALSE; -static GMutex init_lock; +static GRecMutex init_lock; GstClockTime _priv_gst_start_time; @@ -415,11 +415,10 @@ gst_init_check (int *argc, char **argv[], GError ** error) #endif gboolean res; - g_mutex_lock (&init_lock); - + g_rec_mutex_lock (&init_lock); if (gst_initialized) { GST_DEBUG ("already initialized gst"); - g_mutex_unlock (&init_lock); + g_rec_mutex_unlock (&init_lock); return TRUE; } #ifndef GST_DISABLE_OPTION_PARSING @@ -438,7 +437,7 @@ gst_init_check (int *argc, char **argv[], GError ** error) gst_initialized = res; - g_mutex_unlock (&init_lock); + g_rec_mutex_unlock (&init_lock); return res; } @@ -1104,10 +1103,10 @@ gst_deinit (void) { GstBinClass *bin_class; - g_mutex_lock (&init_lock); + g_rec_mutex_lock (&init_lock); if (!gst_initialized) { - g_mutex_unlock (&init_lock); + g_rec_mutex_unlock (&init_lock); return; } if (gst_deinitialized) { @@ -1260,7 +1259,7 @@ gst_deinit (void) gst_deinitialized = TRUE; GST_INFO ("deinitialized GStreamer"); - g_mutex_unlock (&init_lock); + g_rec_mutex_unlock (&init_lock); #ifndef GST_DISABLE_GST_DEBUG /* Doing this as the very last step to allow the above GST_INFO() to work