From accbcabeead0715be031a8cd4f52af42c97e42f4 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 1 Mar 2023 00:56:51 -0300 Subject: [PATCH] validate: Protect init function with a recursive mutex 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: --- subprojects/gst-devtools/validate/gst/validate/validate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subprojects/gst-devtools/validate/gst/validate/validate.c b/subprojects/gst-devtools/validate/gst/validate/validate.c index a6e8bdfcb1..0367ad8c81 100644 --- a/subprojects/gst-devtools/validate/gst/validate/validate.c +++ b/subprojects/gst-devtools/validate/gst/validate/validate.c @@ -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