Skip to content

Commit

Permalink
Return correct threadId in all cases
Browse files Browse the repository at this point in the history
If the assembler code cannot be used to retrieve the threadId, always
use pthread_self() for it. QObject uses QThread::currentThreadId() and
QThreadData::threadId to match threads, which makes address of the
currentThreadData unsuitable as the thread id.

Reading the threadId from currentThreadData is slower than calling
pthread_self(), as tested on Aarch64 linux and x86_64 QNX.

Change-Id: If9afc8ed2810ad1e04bd42ead8f40b43ef3bac30
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
sapiippo committed May 30, 2020
1 parent 71e3b04 commit 10a0dc6
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/corelib/thread/qthread_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,7 @@ void QThreadPrivate::finish(void *arg)
*************************************************************************/

/*
Since each thread is guaranteed to have its own copy of
currenThreadData, the address is guaranteed to be unique for each
running thread (but likely to be reused for newly started threads).
CI tests fails on ARM architectures if we try to use the assembler,
or the address of the thread_local (even with a recent gcc version), so
CI tests fails on ARM architectures if we try to use the assembler, so
stick to the pthread version there. The assembler would be
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0344k/Babeihid.html
Expand All @@ -440,11 +435,7 @@ void QThreadPrivate::finish(void *arg)
*/
Qt::HANDLE QThread::currentThreadIdImpl() noexcept
{
#if defined(Q_PROCESSOR_ARM)
return to_HANDLE(pthread_self());
#else
return &currentThreadData;
#endif
}

#if defined(QT_LINUXBASE) && !defined(_SC_NPROCESSORS_ONLN)
Expand Down

0 comments on commit 10a0dc6

Please sign in to comment.