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>bb10
parent
6e0c438a41
commit
682d057aab
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue