gst: make gst_init() thread-safe
authorTim-Philipp Müller <tim@centricular.com>
Tue, 28 Oct 2014 19:16:52 +0000 (19:16 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 28 Oct 2014 19:16:52 +0000 (19:16 +0000)
Because we can, and there isn't really any
reason not to do so.

gst/gst.c

index 37c6ce9..562a676 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -318,14 +318,18 @@ gst_init_get_option_group (void)
 gboolean
 gst_init_check (int *argc, char **argv[], GError ** err)
 {
+  static GMutex init_lock;
 #ifndef GST_DISABLE_OPTION_PARSING
   GOptionGroup *group;
   GOptionContext *ctx;
 #endif
   gboolean res;
 
+  g_mutex_lock (&init_lock);
+
   if (gst_initialized) {
     GST_DEBUG ("already initialized gst");
+    g_mutex_unlock (&init_lock);
     return TRUE;
   }
 #ifndef GST_DISABLE_OPTION_PARSING
@@ -350,6 +354,8 @@ gst_init_check (int *argc, char **argv[], GError ** err)
     GST_INFO ("failed to initialize GStreamer");
   }
 
+  g_mutex_unlock (&init_lock);
+
   return res;
 }