summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-07-09 09:41:49 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-08-08 21:59:52 +0200
commit7b38f466e0e78c3c7f73877c633bf9c847f6513b (patch)
treec71a55565e8f3e2081fe54182a59b4f2073ecaba /src/corelib/thread
parent8b1b07c872bc7457ab1381c9c826d53fbc7ad359 (diff)
QProperty: Only try to avoid TLS access if currentThreadId is faster
We will not gain anything if we have to do multiple function calls to obtain the thread id. Therefore we introduce a macro to signal that we have a fast implementation of currentThreadId, and only use the function if it is defined. Change-Id: I3347489ea91992896bb753b796ae26e391c2c99c Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 5889985c8c8e8cc676de4480ad95979287860b96)
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h
index 51cd3eadcc..e48354dedb 100644
--- a/src/corelib/thread/qthread.h
+++ b/src/corelib/thread/qthread.h
@@ -186,6 +186,8 @@ QThread *QThread::create(Function &&f, Args &&... args)
*/
inline Qt::HANDLE QThread::currentThreadId() noexcept
{
+ // define is undefed if we have to fall back to currentThreadIdImpl
+#define QT_HAS_FAST_CURRENT_THREAD_ID
Qt::HANDLE tid; // typedef to void*
static_assert(sizeof(tid) == sizeof(void*));
// See https://akkadia.org/drepper/tls.pdf for x86 ABI
@@ -219,6 +221,7 @@ inline Qt::HANDLE QThread::currentThreadId() noexcept
// Then read the thread ID
tid = *reinterpret_cast<Qt::HANDLE *>(tib + 0x24);
#else
+#undef QT_HAS_FAST_CURRENT_THREAD_ID
tid = currentThreadIdImpl();
#endif
return tid;