From 682d057aabd3efc9348d921d6864bae08ca1161a Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 28 Feb 2024 11:06:57 +0100 Subject: [PATCH] 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 Reviewed-by: Thiago Macieira --- src/corelib/thread/qthread_win.cpp | 14 +++++++++++--- 1 file 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 -#include + +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(threadName.utf16())); -#endif emit thr->started(QThread::QPrivateSignal()); QThread::setTerminationEnabled(true);