diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2011-03-28 16:54:06 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2011-03-31 14:32:42 (GMT) |
commit | df9491b302f6404ad2ccc6dc2eb3377176d994c6 (patch) | |
tree | ea041707bfae4eb5586b3b67c7f24b9a262e09c0 /src | |
parent | 3ae213cdeffae107ffa5a4b552c6351123dcc5cb (diff) | |
download | Qt-df9491b302f6404ad2ccc6dc2eb3377176d994c6.zip Qt-df9491b302f6404ad2ccc6dc2eb3377176d994c6.tar.gz Qt-df9491b302f6404ad2ccc6dc2eb3377176d994c6.tar.bz2 |
Optimize QMetaObject::activate (remove call to QThreadData::current)
QThreadData::current is too slow, it needs to access the TLS
The currentThreadId is much faster.
Reviewed-by: Brad
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 4 | ||||
-rw-r--r-- | src/corelib/thread/qthread.cpp | 2 | ||||
-rw-r--r-- | src/corelib/thread/qthread_p.h | 2 | ||||
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 3 | ||||
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 2 |
5 files changed, 9 insertions, 4 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index c6153cb..7ad9f9b 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -3478,7 +3478,7 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign argv ? argv : empty_argv); } - QThreadData *currentThreadData = QThreadData::current(); + Qt::HANDLE currentThreadId = QThread::currentThreadId(); QMutexLocker locker(signalSlotLock(sender)); QObjectConnectionListVector *connectionLists = sender->d_func()->connectionLists; @@ -3506,7 +3506,7 @@ void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_sign QObject * const receiver = c->receiver; const int method = c->method; - const bool receiverInSameThread = currentThreadData == receiver->d_func()->threadData; + const bool receiverInSameThread = currentThreadId == receiver->d_func()->threadData->threadId; // determine if this connection should be sent immediately or // put into the event queue diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 817e73e..acf0fce 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -77,7 +77,7 @@ QT_BEGIN_NAMESPACE */ QThreadData::QThreadData(int initialRefCount) - : _ref(initialRefCount), thread(0), + : _ref(initialRefCount), thread(0), threadId(0), quitNow(false), loopLevel(0), eventDispatcher(0), canWait(true), isAdopted(false) { // fprintf(stderr, "QThreadData %p created\n", this); diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h index 2413452..b43a456 100644 --- a/src/corelib/thread/qthread_p.h +++ b/src/corelib/thread/qthread_p.h @@ -146,6 +146,7 @@ public: #else static void finish(void *); #endif + #endif // Q_OS_UNIX #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) @@ -201,6 +202,7 @@ public: void deref(); QThread *thread; + Qt::HANDLE threadId; bool quitNow; int loopLevel; QAbstractEventDispatcher *eventDispatcher; diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 484b455..787c909 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -261,6 +261,7 @@ QThreadData *QThreadData::current() data->deref(); } data->isAdopted = true; + data->threadId = (Qt::HANDLE)pthread_self(); if (!QCoreApplicationPrivate::theMainThread) QCoreApplicationPrivate::theMainThread = data->thread; } @@ -344,7 +345,7 @@ void *QThreadPrivate::start(void *arg) // attribute of the thread again once the app gains control in run() User::SetCritical(User::EProcessCritical); #endif - + data->threadId = (Qt::HANDLE)pthread_self(); set_thread_data(data); data->ref(); diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index b9c55b0..bab6cf8 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -125,6 +125,7 @@ QThreadData *QThreadData::current() threadData->deref(); } threadData->isAdopted = true; + threadData->threadId = (Qt::HANDLE)GetCurrentThreadId(); if (!QCoreApplicationPrivate::theMainThread) { QCoreApplicationPrivate::theMainThread = threadData->thread; @@ -306,6 +307,7 @@ unsigned int __stdcall QThreadPrivate::start(void *arg) qt_create_tls(); TlsSetValue(qt_current_thread_data_tls_index, data); + data->threadId = (Qt::HANDLE)GetCurrentThreadId(); QThread::setTerminationEnabled(false); |