summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthread_win.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-02-28 11:06:57 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-03-08 16:44:18 +0000
commit682d057aabd3efc9348d921d6864bae08ca1161a (patch)
tree0a8122557cccd9216447a865bbc8cd5c38de43c1 /src/corelib/thread/qthread_win.cpp
parent6e0c438a41a61a3d0a93954f00f46951c4399224 (diff)
QThread/Win: set the thread name on non-MSVC also
SetThreadDescription is a Win32 API provided by Kernel32.dll, the only thing that MinGW is missing is the declaration of the function. We can provide it ourselves. Change-Id: Iad5fc6cb7b6eb190310f5888326b65f50ddbdca8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread/qthread_win.cpp')
-rw-r--r--src/corelib/thread/qthread_win.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index 793c7cdc68..ee3b94dc3b 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -18,7 +18,17 @@
# define _MT
#endif // _MT
#include <process.h>
-#include <processthreadsapi.h>
+
+extern "C" {
+// MinGW is missing the declaration of SetThreadDescription:
+WINBASEAPI
+HRESULT
+WINAPI
+SetThreadDescription(
+ _In_ HANDLE hThread,
+ _In_ PCWSTR lpThreadDescription
+ );
+}
QT_BEGIN_NAMESPACE
@@ -246,13 +256,11 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi
data->ensureEventDispatcher();
data->eventDispatcher.loadRelaxed()->startingUp();
-#if defined(Q_CC_MSVC)
// sets the name of the current thread.
QString threadName = std::exchange(thr->d_func()->objectName, {});
if (Q_LIKELY(threadName.isEmpty()))
threadName = QString::fromUtf8(thr->metaObject()->className());
SetThreadDescription(GetCurrentThread(), reinterpret_cast<const wchar_t *>(threadName.utf16()));
-#endif
emit thr->started(QThread::QPrivateSignal());
QThread::setTerminationEnabled(true);