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/qdbusmetatype_p.h | |
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/qdbusmetatype_p.h')
-rw-r--r-- | src/dbus/qdbusmetatype_p.h | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/dbus/qdbusmetatype_p.h b/src/dbus/qdbusmetatype_p.h index 8239657232..8814408cc1 100644 --- a/src/dbus/qdbusmetatype_p.h +++ b/src/dbus/qdbusmetatype_p.h @@ -55,21 +55,56 @@ #include <qdbusmetatype.h> +#include <qdbusmessage.h> +#include <qdbusargument.h> +#include <qdbusextratypes.h> +#include <qdbuserror.h> +#include <qdbusunixfiledescriptor.h> + QT_BEGIN_NAMESPACE struct QDBusMetaTypeId { - static int message; // QDBusMessage - static int argument; // QDBusArgument - static int variant; // QDBusVariant - static int objectpath; // QDBusObjectPath - static int signature; // QDBusSignature - static int error; // QDBusError - static int unixfd; // QDBusUnixFileDescriptor + static int message(); // QDBusMessage + static int argument(); // QDBusArgument + static int variant(); // QDBusVariant + static int objectpath(); // QDBusObjectPath + static int signature(); // QDBusSignature + static int error(); // QDBusError + static int unixfd(); // QDBusUnixFileDescriptor static void init(); }; +inline int QDBusMetaTypeId::message() +#ifdef QT_BOOTSTRAPPED +{ return qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >() + 1; } +#else +{ return qMetaTypeId<QDBusMessage>(); } +#endif + +inline int QDBusMetaTypeId::argument() +{ return qMetaTypeId<QDBusArgument>(); } + +inline int QDBusMetaTypeId::variant() +{ return qMetaTypeId<QDBusVariant>(); } + +inline int QDBusMetaTypeId::objectpath() +{ return qMetaTypeId<QDBusObjectPath>(); } + +inline int QDBusMetaTypeId::signature() +{ return qMetaTypeId<QDBusSignature>(); } + +inline int QDBusMetaTypeId::error() +#ifdef QT_BOOTSTRAPPED +{ return qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >() + 2; } +#else +{ return qMetaTypeId<QDBusError>(); } +#endif + +inline int QDBusMetaTypeId::unixfd() +{ return qMetaTypeId<QDBusUnixFileDescriptor>(); } + QT_END_NAMESPACE #endif |