From 57410e5d7d7e272a325e0e94182f2c180faced1d Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Wed, 16 Aug 2023 13:50:33 +0200 Subject: [PATCH] QDBusAdaptorConnector: Initialize cached index in a thread safe way Move the definition of cachedRelaySlotMethodIndex inside relaySlotMethodIndex() to get thread-safe initialization. Change-Id: I48683078f4dc610e9c7d1591287cf2d1dcfe8778 Reviewed-by: Thiago Macieira --- src/dbus/qdbusabstractadaptor.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/dbus/qdbusabstractadaptor.cpp b/src/dbus/qdbusabstractadaptor.cpp index 9da2fd3886..5a97fc7b68 100644 --- a/src/dbus/qdbusabstractadaptor.cpp +++ b/src/dbus/qdbusabstractadaptor.cpp @@ -22,14 +22,10 @@ QT_BEGIN_NAMESPACE -static int cachedRelaySlotMethodIndex = 0; - int QDBusAdaptorConnector::relaySlotMethodIndex() { - if (cachedRelaySlotMethodIndex == 0) { - cachedRelaySlotMethodIndex = staticMetaObject.indexOfMethod("relaySlot()"); - Q_ASSERT(cachedRelaySlotMethodIndex != 0); // 0 should be deleteLater() or destroyed() - } + static const int cachedRelaySlotMethodIndex = staticMetaObject.indexOfMethod("relaySlot()"); + Q_ASSERT(cachedRelaySlotMethodIndex != 0); // 0 should be deleteLater() or destroyed() return cachedRelaySlotMethodIndex; }