summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <[email protected]>2023-10-02 16:31:50 +0200
committerMarc Mutz <[email protected]>2023-10-17 18:51:16 +0000
commitae0d231c96ab93ec36c7202c268507314eb40116 (patch)
tree4b2aae415b535b34917c5b79de2fce259110547e
parent6544a23603b46c1e2e7c4bd7728ec4dbdb6aec16 (diff)
SignalDumper: fix UB (data race on indentation level)
... by making it thread_local. As a natural (and welcome) side-effect, this makes output look sane in multithreaded scenarios. As for why it should be thread_local instead of an atomic: Since signal emissions and slot invocations on one thread are not necessarily correlated with another thread, they should not affect one another's indentation level. As in, emitting QIODevice::readyRead on a background thread should not make QEventLoop::aboutToBlock on the main thread be indented. The only exception to this is BlockingQueued, where one thread is directly tied to another (QTBUG-118145). But slot invocations are anyway not currently printed for Queued connection (see QTBUG-74099.) Pick-to: 6.6 6.5 Change-Id: Iea1fc522d37626df14af419a3455a732729edf74 Reviewed-by: Marc Mutz <[email protected]> Reviewed-by: Edward Welbourne <[email protected]>
-rw-r--r--src/testlib/qsignaldumper.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/testlib/qsignaldumper.cpp b/src/testlib/qsignaldumper.cpp
index 86c6c521ff4..f0c35b92f9b 100644
--- a/src/testlib/qsignaldumper.cpp
+++ b/src/testlib/qsignaldumper.cpp
@@ -24,7 +24,7 @@ inline static void qPrintMessage(const QByteArray &ba)
}
Q_GLOBAL_STATIC(QList<QByteArray>, ignoreClasses)
-static int iLevel = 0;
+Q_CONSTINIT thread_local int iLevel = 0;
static int ignoreLevel = 0;
enum { IndentSpacesCount = 4 };