validate: Protect init function with a recursive mutex
authorThibault Saunier <tsaunier@igalia.com>
Wed, 1 Mar 2023 03:56:51 +0000 (00:56 -0300)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 2 Mar 2023 10:57:45 +0000 (10:57 +0000)
In tests in the rust bindings we end up with 2 thread initializing
concurrently, and it should not be a problem, -validate should be MT
safe.

Using a recursive mutex as we might recursively init for some reason
and we are not on the hot path here in any case.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4097>

subprojects/gst-devtools/validate/gst/validate/validate.c

index a6e8bdf..0367ad8 100644 (file)
@@ -55,6 +55,8 @@ GST_DEBUG_CATEGORY (gstvalidate_debug);
 static GMutex _gst_validate_registry_mutex;
 static GstRegistry *_gst_validate_registry_default = NULL;
 
+static GRecMutex init_lock = { 0, };
+
 G_LOCK_DEFINE_STATIC (all_configs_lock);
 static GList *all_configs = NULL;
 static gboolean got_configs = FALSE;
@@ -469,7 +471,9 @@ gst_validate_init_debug (void)
 void
 gst_validate_init (void)
 {
+  g_rec_mutex_lock (&init_lock);
   if (validate_initialized) {
+    g_rec_mutex_unlock (&init_lock);
     return;
   }
   gst_validate_init_debug ();
@@ -493,6 +497,7 @@ gst_validate_init (void)
   gst_validate_flow_init ();
   gst_validate_init_plugins ();
   gst_validate_init_runner ();
+  g_rec_mutex_unlock (&init_lock);
 }
 
 void