gst: Protect initialization state with a recursive mutex.
authorSebastian Dröge <sebastian@centricular.com>
Sat, 9 Jul 2022 14:04:07 +0000 (17:04 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 10 Aug 2022 11:31:50 +0000 (11:31 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2740>

subprojects/gstreamer/gst/gst.c

index f074ff5..ddfc178 100644 (file)
 
 static gboolean gst_initialized = FALSE;
 static gboolean gst_deinitialized = FALSE;
-static GMutex init_lock;
+static GRecMutex init_lock;
 
 GstClockTime _priv_gst_start_time;
 
@@ -405,11 +405,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
@@ -428,7 +427,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;
 }
@@ -1088,10 +1087,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) {
@@ -1244,7 +1243,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