Simplify the mutexpool used in QObject.
authorOlivier Goffart <olivier.goffart@nokia.com>
Tue, 26 Jul 2011 08:44:55 +0000 (10:44 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 29 Jul 2011 08:32:16 +0000 (10:32 +0200)
Since we now have QBasicMutex as a POD, we can simplify the mutexpool.
This remove the call the the Q_GLOBAL_STATIC and some others tests that
are taking CPU cycles when activating a signal.

The QMutexPool class itself can't be simplified because its mutex are
recursive mutexes, and the size is dynamic. also it is harder to get all
the mutexes initialized to 0.

Change-Id: Ie781655635907d2ad620eb189099cba14638414f
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/2171
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
src/corelib/kernel/qobject.cpp

index ab9314c..076744e 100644 (file)
@@ -60,7 +60,6 @@
 #include <qsharedpointer.h>
 
 #include <private/qorderedmutexlocker_p.h>
-#include <private/qmutexpool_p.h>
 
 #include <new>
 
@@ -95,35 +94,22 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
     return types;
 }
 
-static QBasicAtomicPointer<QMutexPool> signalSlotMutexes = Q_BASIC_ATOMIC_INITIALIZER(0);
-static QBasicAtomicInt objectCount = Q_BASIC_ATOMIC_INITIALIZER(0);
+static QBasicMutex _q_ObjectMutexPool[131];
 
 /** \internal
  * mutex to be locked when accessing the connectionlists or the senders list
  */
 static inline QMutex *signalSlotLock(const QObject *o)
 {
-    if (!signalSlotMutexes) {
-        QMutexPool *mp = new QMutexPool;
-        if (!signalSlotMutexes.testAndSetOrdered(0, mp)) {
-            delete mp;
-        }
-    }
-    return signalSlotMutexes->get(o);
+    return static_cast<QMutex *>(&_q_ObjectMutexPool[
+        uint(quintptr(o)) % sizeof(_q_ObjectMutexPool)/sizeof(QBasicMutex)]);
 }
 
 extern "C" Q_CORE_EXPORT void qt_addObject(QObject *)
-{
-    objectCount.ref();
-}
+{}
 
 extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *)
-{
-    if(!objectCount.deref()) {
-        QMutexPool *old = signalSlotMutexes.fetchAndStoreAcquire(0);
-        delete old;
-    }
-}
+{}
 
 struct QConnectionSenderSwitcher {
     QObject *receiver;