Return correct threadId in all cases

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 <volker.hilsheimer@qt.io>
This commit is contained in:
Samuli Piippo 2020-05-29 08:50:13 +03:00
parent 71e3b04282
commit 10a0dc6600

View File

@ -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
@ -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)