aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-27 10:03:00 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-05-31 17:23:09 +0200
commit0434e54b55d9a31c3b5331856bab639b7149058c (patch)
tree306dd5766f4dbb12c0242d09d1d8c742485f1620 /src
parentc98c2c08a5f926b67c40b6363274d23066bfe341 (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. Pick-to: 6.3 6.2 5.15 Change-Id: I0305ab55be86a0e286016a3d1d97ee9bc0e28070 Reviewed-by: Ulf Hermann <ulf.hermann@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 5619a5fe3e..4044612793 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 dabe6bfabe..0077e655bb 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 9123fc79e2..1a19c852b4 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -160,7 +160,7 @@ QT_BEGIN_NAMESPACE
\endcode
*/
-bool QQmlEnginePrivate::qml_debugging_enabled = false;
+Q_CONSTINIT std::atomic<bool> QQmlEnginePrivate::qml_debugging_enabled{false};
bool QQmlEnginePrivate::s_designerMode = false;
bool QQmlEnginePrivate::designerMode()
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h
index b914afdaf1..e8211b1a38 100644
--- a/src/qml/qml/qqmlengine_p.h
+++ b/src/qml/qml/qqmlengine_p.h
@@ -80,6 +80,8 @@
#include <QtCore/qstring.h>
#include <QtCore/qthread.h>
+#include <atomic>
+
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
@@ -236,7 +238,7 @@ public:
static bool designerMode();
static void activateDesignerMode();
- static bool qml_debugging_enabled;
+ static std::atomic<bool> qml_debugging_enabled;
mutable QMutex networkAccessManagerMutex;