From 360f3de3909a14388f27d82bdad50bf370586cfe Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 26 Jun 2019 07:38:31 +0200 Subject: [PATCH] QtDBus: optimize handling of isDebugging This is part of a series of patches deprecating implicit conversions of QAtomic variables to T. Use relaxed atomic loads and stores on the 'isDebugging' variable. The old code used the implict conversions to and from int and therefore loadAcquire/storeRelease. Here, the int is the only value, it's not guarding the construction of any other data, so relaxed loads and stores suffice. A further optimization would be to make the initial value of isDebugging 0, to send it into the BSS instead of the TEXT/DATA segment, but seeing as this is just compiled in for the auto-tests, this patch leaves that particular change for another round (or never). Pick-to: 6.3 Change-Id: Ide92f6c1a12137fcbc3ec15e146f6dcbdb6b481b Reviewed-by: David Faure --- src/dbus/qdbusintegrator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 5c30bc04c0..7970a36a1f 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -85,7 +85,7 @@ QT_IMPL_METATYPE_EXTERN(QDBusSlotCache) static dbus_int32_t server_slot = -1; static QBasicAtomicInt isDebugging = Q_BASIC_ATOMIC_INITIALIZER(-1); -#define qDBusDebug if (::isDebugging == 0); else qDebug +#define qDBusDebug if (::isDebugging.loadRelaxed() == 0); else qDebug static inline QDebug operator<<(QDebug dbg, const QThread *th) { @@ -1039,12 +1039,12 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) isAuthenticated(false) { static const bool threads = q_dbus_threads_init_default(); - if (::isDebugging == -1) - ::isDebugging = qEnvironmentVariableIntValue("QDBUS_DEBUG"); Q_UNUSED(threads); + if (::isDebugging.loadRelaxed() == -1) + ::isDebugging.storeRelaxed(qEnvironmentVariableIntValue("QDBUS_DEBUG")); #ifdef QDBUS_THREAD_DEBUG - if (::isDebugging > 1) + if (::isDebugging.loadRelaxed() > 1) qdbusThreadDebug = qdbusDefaultThreadDebug; #endif