From ae0d231c96ab93ec36c7202c268507314eb40116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 2 Oct 2023 16:31:50 +0200 Subject: [PATCH] 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 Reviewed-by: Edward Welbourne --- src/testlib/qsignaldumper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testlib/qsignaldumper.cpp b/src/testlib/qsignaldumper.cpp index 86c6c521ff..f0c35b92f9 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, ignoreClasses) -static int iLevel = 0; +Q_CONSTINIT thread_local int iLevel = 0; static int ignoreLevel = 0; enum { IndentSpacesCount = 4 };