wpe: Make threaded view singleton creation thread safe
authorThibault Saunier <tsaunier@igalia.com>
Thu, 15 Apr 2021 17:28:42 +0000 (13:28 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Thu, 15 Apr 2021 17:29:43 +0000 (13:29 -0400)
It was leading to interesting failures.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2165>

ext/wpe/WPEThreadedView.cpp

index ec30741..b2c81da 100644 (file)
@@ -66,9 +66,14 @@ static WPEContextThread *s_view = NULL;
 
 WPEContextThread& WPEContextThread::singleton()
 {
-    if (!s_view)
+    static gsize initialized = 0;
+
+    if (g_once_init_enter (&initialized)) {
         s_view = new WPEContextThread;
 
+        g_once_init_leave (&initialized, 1);
+    }
+
     return *s_view;
 }