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 <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>
This commit is contained in:
parent
86a237929e
commit
ddf444d31a
@ -60,7 +60,6 @@
|
|||||||
#include <qsharedpointer.h>
|
#include <qsharedpointer.h>
|
||||||
|
|
||||||
#include <private/qorderedmutexlocker_p.h>
|
#include <private/qorderedmutexlocker_p.h>
|
||||||
#include <private/qmutexpool_p.h>
|
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
@ -95,35 +94,22 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QBasicAtomicPointer<QMutexPool> signalSlotMutexes = Q_BASIC_ATOMIC_INITIALIZER(0);
|
static QBasicMutex _q_ObjectMutexPool[131];
|
||||||
static QBasicAtomicInt objectCount = Q_BASIC_ATOMIC_INITIALIZER(0);
|
|
||||||
|
|
||||||
/** \internal
|
/** \internal
|
||||||
* mutex to be locked when accessing the connectionlists or the senders list
|
* mutex to be locked when accessing the connectionlists or the senders list
|
||||||
*/
|
*/
|
||||||
static inline QMutex *signalSlotLock(const QObject *o)
|
static inline QMutex *signalSlotLock(const QObject *o)
|
||||||
{
|
{
|
||||||
if (!signalSlotMutexes) {
|
return static_cast<QMutex *>(&_q_ObjectMutexPool[
|
||||||
QMutexPool *mp = new QMutexPool;
|
uint(quintptr(o)) % sizeof(_q_ObjectMutexPool)/sizeof(QBasicMutex)]);
|
||||||
if (!signalSlotMutexes.testAndSetOrdered(0, mp)) {
|
|
||||||
delete mp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return signalSlotMutexes->get(o);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" Q_CORE_EXPORT void qt_addObject(QObject *)
|
extern "C" Q_CORE_EXPORT void qt_addObject(QObject *)
|
||||||
{
|
{}
|
||||||
objectCount.ref();
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *)
|
extern "C" Q_CORE_EXPORT void qt_removeObject(QObject *)
|
||||||
{
|
{}
|
||||||
if(!objectCount.deref()) {
|
|
||||||
QMutexPool *old = signalSlotMutexes.fetchAndStoreAcquire(0);
|
|
||||||
delete old;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct QConnectionSenderSwitcher {
|
struct QConnectionSenderSwitcher {
|
||||||
QObject *receiver;
|
QObject *receiver;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user