aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-27 10:03:00 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-06-09 21:01:52 +0000
commit15f637ebe729cfb10309fce67bc7f8d29f12a5c4 (patch)
tree346a2e4faa30944090bd1a95e886c7c4350d7f55 /src
parent4cc5822d188e070501005a0bf508af1968cc826d (diff)
Fix race condition on QQmlEnginePrivate::qml_debugging_enabled
C++11 allows static dynamic initialization from different TUs to happen concurrently, which means the QQmlDebuggingEnabler ctor must be re-entrant and synchronized with other users of qml_debugging_enabled. Thankfully, this is just a flag, so the fix is to simply make it atomic<> and use relaxed loads and stores on it. Manual conflict resolutions: - dropped the Q_CONSTINIT (doesn't exist in 5.15) - actual line conflicts in src/qml/qml/qqmlengine_p.h Change-Id: I0305ab55be86a0e286016a3d1d97ee9bc0e28070 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 0434e54b55d9a31c3b5331856bab639b7149058c) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/debugger/qqmldebug.cpp2
-rw-r--r--src/qml/debugger/qqmldebugconnector.cpp2
-rw-r--r--src/qml/qml/qqmlengine.cpp2
-rw-r--r--src/qml/qml/qqmlengine_p.h4
4 files changed, 6 insertions, 4 deletions
diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp
index 6bf49b9671..4af711171a 100644
--- a/src/qml/debugger/qqmldebug.cpp
+++ b/src/qml/debugger/qqmldebug.cpp
@@ -63,7 +63,7 @@ QQmlDebuggingEnabler::QQmlDebuggingEnabler(bool printWarning)
{
if (printWarning && !s_printedWarning.test_and_set(std::memory_order_relaxed))
fprintf(stderr, "QML debugging is enabled. Only use this in a safe environment.\n");
- QQmlEnginePrivate::qml_debugging_enabled = true;
+ QQmlEnginePrivate::qml_debugging_enabled.store(true, std::memory_order_relaxed);
}
/*!
diff --git a/src/qml/debugger/qqmldebugconnector.cpp b/src/qml/debugger/qqmldebugconnector.cpp
index 690d98c17f..72043ecd1f 100644
--- a/src/qml/debugger/qqmldebugconnector.cpp
+++ b/src/qml/debugger/qqmldebugconnector.cpp
@@ -111,7 +111,7 @@ QQmlDebugConnector *QQmlDebugConnector::instance()
if (!params)
return nullptr;
- if (!QQmlEnginePrivate::qml_debugging_enabled) {
+ if (!QQmlEnginePrivate::qml_debugging_enabled.load(std::memory_order_relaxed)) {
if (!params->arguments.isEmpty()) {
qWarning().noquote() << QString::fromLatin1(
"QML Debugger: Ignoring \"-qmljsdebugger=%1\". Debugging "
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index ba87c9810f..5c6a7b1f37 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -193,7 +193,7 @@ int qmlRegisterUncreatableMetaObject(const QMetaObject &staticMetaObject,
\endcode
*/
-bool QQmlEnginePrivate::qml_debugging_enabled = false;
+std::atomic<bool> QQmlEnginePrivate::qml_debugging_enabled{false};
bool QQmlEnginePrivate::s_designerMode = false;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h
index 5e78471a5b..147024044c 100644
--- a/src/qml/qml/qqmlengine_p.h
+++ b/src/qml/qml/qqmlengine_p.h
@@ -80,6 +80,8 @@
#include <private/qjsengine_p.h>
#include <private/qqmldirparser_p.h>
+#include <atomic>
+
QT_BEGIN_NAMESPACE
class QQmlContext;
@@ -267,7 +269,7 @@ public:
static bool designerMode();
static void activateDesignerMode();
- static bool qml_debugging_enabled;
+ static std::atomic<bool> qml_debugging_enabled;
mutable QMutex networkAccessManagerMutex;