QtDBus: optimize handling of isDebugging

This is part of a series of patches deprecating implicit conversions
of QAtomic<T> 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 <david.faure@kdab.com>
bb10
Marc Mutz 2019-06-26 07:38:31 +02:00 committed by Marc Mutz
parent e4186b2b28
commit 360f3de390
1 changed files with 4 additions and 4 deletions

View File

@ -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