From ddf444d31a7cb961b79190131cb679fd7a6351fd Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 26 Jul 2011 10:44:55 +0200 Subject: Simplify the mutexpool used in QObject. 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 Reviewed-on: http://codereview.qt.nokia.com/2171 Reviewed-by: Qt Sanity Bot Reviewed-by: Olivier Goffart --- src/corelib/kernel/qobject.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index ab9314ce53..076744ee00 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -60,7 +60,6 @@ #include #include -#include #include @@ -95,35 +94,22 @@ static int *queuedConnectionTypes(const QList &typeNames) return types; } -static QBasicAtomicPointer 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(&_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; -- cgit v1.2.3