diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-08-24 12:06:03 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-22 19:19:37 +0200 |
commit | 373a7277db0583fbbb8ed61f9f61d6f77ed95da4 (patch) | |
tree | f530a3e205770802a2580789e8e5eb487065fedb /src/dbus/qdbusintegrator.cpp | |
parent | f799e57151dbd236f30d4ffb20d6c331b6e1a388 (diff) |
QDBusMetaTypeId: don't cache the result of qMetaTypeId<>() in static ints
There's not much point in caching the result of qMetaTypeId<>,
because it's already internally memoised.
In addition, the code that initialised the static int caches wasn't
protected against concurrent access under the assumption that the
operations performed were thread-safe.
That is true for most of them, but not for the stores to the static ints,
which race against each other:
// Thread A // Thread B
r1 = initialized /*=false*/
r1 = initialized /*=false*/
r2 = qMetaTypeId<...>();
r2 = qMetaTypeId<...>();
message = r2; message = r2; // race, ditto for all other ints
To fix, turn the ints into inline functions that just call the respective
qMetaTypeId<>() function.
Change-Id: I5aa80c624872c3867232abc26ffdcde70cd54022
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/dbus/qdbusintegrator.cpp')
-rw-r--r-- | src/dbus/qdbusintegrator.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index ff6927ccfe..aa794d6cd9 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -667,7 +667,7 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, metaTypes[0] = returnType; bool hasMessage = false; if (inputCount > 0 && - metaTypes.at(inputCount) == QDBusMetaTypeId::message) { + metaTypes.at(inputCount) == QDBusMetaTypeId::message()) { // "no input parameters" is allowed as long as the message meta type is there hasMessage = true; --inputCount; @@ -738,7 +738,7 @@ QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPriv Q_UNUSED(object); int n = metaTypes.count() - 1; - if (metaTypes[n] == QDBusMetaTypeId::message) + if (metaTypes[n] == QDBusMetaTypeId::message()) --n; if (msg.arguments().count() < n) @@ -838,7 +838,7 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu // try with no parameters, but with a QDBusMessage slotData.slotIdx = ::findSlot(mo, memberName, flags, QString(), slotData.metaTypes); if (slotData.metaTypes.count() != 2 || - slotData.metaTypes.at(1) != QDBusMetaTypeId::message) { + slotData.metaTypes.at(1) != QDBusMetaTypeId::message()) { // not found // save the negative lookup slotData.slotIdx = -1; @@ -889,7 +889,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q int pCount = qMin(msg.arguments().count(), metaTypes.count() - 1); for (i = 1; i <= pCount; ++i) { int id = metaTypes[i]; - if (id == QDBusMetaTypeId::message) + if (id == QDBusMetaTypeId::message()) break; const QVariant &arg = msg.arguments().at(i - 1); @@ -918,7 +918,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q } } - if (metaTypes.count() > i && metaTypes[i] == QDBusMetaTypeId::message) { + if (metaTypes.count() > i && metaTypes[i] == QDBusMetaTypeId::message()) { params.append(const_cast<void*>(static_cast<const void*>(&msg))); ++i; } @@ -1298,7 +1298,7 @@ bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hoo if (buildSignature) { hook.signature.clear(); for (int i = 1; i < hook.params.count(); ++i) - if (hook.params.at(i) != QDBusMetaTypeId::message) + if (hook.params.at(i) != QDBusMetaTypeId::message()) hook.signature += QLatin1String( QDBusMetaType::typeToSignature( hook.params.at(i) ) ); } |