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 <thiago.macieira@intel.com>
bb10
Ievgenii Meshcheriakov 2023-08-16 13:50:33 +02:00
parent 51d331b13b
commit 57410e5d7d
1 changed files with 2 additions and 6 deletions

View File

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