diff options
author | Thibault Saunier <tsaunier@igalia.com> | 2023-03-01 00:56:51 -0300 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2023-03-02 10:57:45 +0000 |
commit | e66d636fd1e7b2a9fbebb5c05767215666f66d00 (patch) | |
tree | a5eecf92b44cd5568059f19659a6525cc0353ad4 | |
parent | 85d363f4e2312bbfd7b807910a54ceb1046063e8 (diff) |
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4097>
-rw-r--r-- | subprojects/gst-devtools/validate/gst/validate/validate.c | 5 |
1 files changed, 5 insertions, 0 deletions
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 |