From f9ce3946a1942e974c9d5b645550219c14b79cf6 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Thu, 15 Apr 2021 13:28:42 -0400 Subject: [PATCH] wpe: Make threaded view singleton creation thread safe It was leading to interesting failures. Part-of: --- ext/wpe/WPEThreadedView.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/wpe/WPEThreadedView.cpp b/ext/wpe/WPEThreadedView.cpp index ec30741..b2c81da 100644 --- a/ext/wpe/WPEThreadedView.cpp +++ b/ext/wpe/WPEThreadedView.cpp @@ -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; } -- 2.7.4