QThread/Unix: replace some uses of pthread_self() with our code
This code predated the existence of the currentThreadId() and isCurrentThread() functions. Our implementations are slightly faster. Change-Id: Id2b20a7f06e0c2a1bc35fffd4fb4dcf3f20769cd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 8a8e91a7c141994c331d2b9da7d9c5e2129c70b9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
4f85eed8e3
commit
0c2c9ca7f4
@ -214,7 +214,7 @@ QThreadData *QThreadData::current(bool createIfNecessary)
|
||||
}
|
||||
data->deref();
|
||||
data->isAdopted = true;
|
||||
data->threadId.storeRelaxed(to_HANDLE(pthread_self()));
|
||||
data->threadId.storeRelaxed(QThread::currentThreadId());
|
||||
if (!QCoreApplicationPrivate::theMainThreadId.loadAcquire()) {
|
||||
auto *mainThread = data->thread.loadRelaxed();
|
||||
mainThread->setObjectName("Qt mainThread");
|
||||
@ -325,8 +325,7 @@ void *QThreadPrivate::start(void *arg)
|
||||
}
|
||||
|
||||
// threadId is set in QThread::start()
|
||||
Q_ASSERT(pthread_equal(from_HANDLE<pthread_t>(data->threadId.loadRelaxed()),
|
||||
pthread_self()));
|
||||
Q_ASSERT(data->threadId.loadRelaxed() == QThread::currentThreadId());
|
||||
|
||||
data->ref();
|
||||
data->quitNow = thr->d_func()->exited;
|
||||
@ -829,7 +828,7 @@ bool QThread::wait(QDeadlineTimer deadline)
|
||||
Q_D(QThread);
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
if (from_HANDLE<pthread_t>(d->data->threadId.loadRelaxed()) == pthread_self()) {
|
||||
if (isCurrentThread()) {
|
||||
qWarning("QThread::wait: Thread tried to wait on itself");
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user