diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-03-01 11:51:21 +0100 |
---|---|---|
committer | MÃ¥rten Nordheim <marten.nordheim@qt.io> | 2021-03-23 06:42:16 +0100 |
commit | 22c66e12e4c6841d51f505073a01e60917cf3174 (patch) | |
tree | b4b0d06ca430d00e5a2a928b4135141613162de0 /src/corelib/thread | |
parent | 47abdbea81bbfbdb32cf0f53f6b8c42ada4b8bba (diff) |
Provide an inline implementation of currentThreadId() on Windows
As this method is rather critical for performance of some central
parts of Qt, it really should be inline whereever possible. This
commit adds an inline implementation for Windows 32 and 64 bit.
Amends 5e9b2ade678f37e43bfc2e3484f54cbbb5844d2e
Change-Id: Iea51ef905b1cb7f91ca64b718d79bdc4f5c02c3a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r-- | src/corelib/thread/qthread.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/thread/qthread.h b/src/corelib/thread/qthread.h index ab32891a59..e5db44638d 100644 --- a/src/corelib/thread/qthread.h +++ b/src/corelib/thread/qthread.h @@ -49,6 +49,10 @@ # include <future> // for std::async # include <functional> // for std::invoke; no guard needed as it's a C++98 header #endif +// internal compiler error with mingw 8.1 +#if defined(Q_CC_MSVC) && defined(Q_PROCESSOR_X86) +#include <intrin.h> +#endif QT_BEGIN_NAMESPACE @@ -194,6 +198,27 @@ inline Qt::HANDLE QThread::currentThreadId() noexcept #elif defined(Q_PROCESSOR_X86_64) && (defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)) && !defined(Q_OS_ANDROID) // x86_64 Linux, BSD uses FS __asm__("movq %%fs:0, %0" : "=r" (tid) : : ); +#elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_WIN) + // See https://en.wikipedia.org/wiki/Win32_Thread_Information_Block + // First get the pointer to the TIB + quint8 *tib; +# if defined(Q_CC_MINGW) // internal compiler error when using the intrinsics + __asm__("movq %%gs:0x30, %0" : "=r" (tib) : :); +# else + tib = reinterpret_cast<quint8 *>(__readgsqword(0x30)); +# endif + // Then read the thread ID + tid = *reinterpret_cast<Qt::HANDLE *>(tib + 0x48); +#elif defined(Q_PROCESSOR_X86_32) && defined(Q_OS_WIN) + // First get the pointer to the TIB + quint8 *tib; +# if defined(Q_CC_MINGW) // internal compiler error when using the intrinsics + __asm__("movl %%fs:0x18, %0" : "=r" (tib) : :); +# else + tib = reinterpret_cast<quint8 *>(__readfsdword(0x18)); +# endif + // Then read the thread ID + tid = *reinterpret_cast<Qt::HANDLE *>(tib + 0x24); #else tid = currentThreadIdImpl(); #endif |