From 10a0dc6600ac039ca94defc461d7b1c714d86387 Mon Sep 17 00:00:00 2001 From: Samuli Piippo Date: Fri, 29 May 2020 08:50:13 +0300 Subject: [PATCH] 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 --- src/corelib/thread/qthread_unix.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 727d72a334d..96c3f5c45c0 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -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 ¤tThreadData; -#endif } #if defined(QT_LINUXBASE) && !defined(_SC_NPROCESSORS_ONLN)