QDBusMetaTypeId: don't cache the result of qMetaTypeId<>() in static ints
authorMarc Mutz <marc.mutz@kdab.com>
Fri, 24 Aug 2012 10:06:03 +0000 (12:06 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 22 Sep 2012 17:19:37 +0000 (19:19 +0200)
commit373a7277db0583fbbb8ed61f9f61d6f77ed95da4
treef530a3e205770802a2580789e8e5eb487065fedb
parentf799e57151dbd236f30d4ffb20d6c331b6e1a388
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>
12 files changed:
src/dbus/qdbusabstractadaptor.cpp
src/dbus/qdbusintegrator.cpp
src/dbus/qdbusinterface.cpp
src/dbus/qdbusinternalfilters.cpp
src/dbus/qdbusmarshaller.cpp
src/dbus/qdbusmetatype.cpp
src/dbus/qdbusmetatype_p.h
src/dbus/qdbusmisc.cpp
src/dbus/qdbuspendingcall.cpp
src/dbus/qdbusreply.cpp
src/dbus/qdbusxmlgenerator.cpp
src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp