[+] SetThreadDescription support

This commit is contained in:
Reece Wilson 2022-03-16 16:34:55 +00:00
parent 5213a19362
commit ab76f77871

View File

@ -367,43 +367,60 @@ namespace Aurora::Threading::Threads
void OSThread::UpdateName()
{
#if defined(AURORA_PLATFORM_WIN32)
static const DWORD kMSVCExceptionSetName = 0x406D1388;
#if defined(AURORA_IS_MODERNNT_DERIVED)
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType;
LPCSTR szName;
DWORD dwThreadID;
DWORD dwFlags;
} THREADNAME_INFO;
#pragma pack(pop)
if (handle_ == INVALID_HANDLE_VALUE)
if (this->handle_ == INVALID_HANDLE_VALUE)
{
return;
}
if (!IsDebuggerPresent())
if ((AuBuild::kCurrentPlatform == AuBuild::EPlatform::ePlatformWin32) && (!AuSwInfo::IsWindows10OrGreater()))
{
return;
static const DWORD kMSVCExceptionSetName = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType;
LPCSTR szName;
DWORD dwThreadID;
DWORD dwFlags;
} THREADNAME_INFO;
#pragma pack(pop)
if (!IsDebuggerPresent())
{
return;
}
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = this->name_.c_str();
info.dwThreadID = ::GetThreadId(this->handle_);
info.dwFlags = 0;
__try
{
RaiseException(kMSVCExceptionSetName, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
}
else
{
static HRESULT(WINAPI * SetThreadDescription_f)(HANDLE, PCWSTR);
if (!SetThreadDescription_f)
{
SetThreadDescription_f = AuReinterpretCast<decltype(SetThreadDescription_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "SetThreadDescription"));
}
if (SetThreadDescription_f)
{
SetThreadDescription_f(this->handle_, AuLocale::ConvertFromUTF8(this->name_).c_str());
}
}
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name_.c_str();
info.dwThreadID = ::GetThreadId(handle_);
info.dwFlags = 0;
__try
{
RaiseException(kMSVCExceptionSetName, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
#elif defined(AURORA_HAS_PTHREADS)
pthread_setname_np(handle_, name_.c_str());
@ -411,7 +428,6 @@ namespace Aurora::Threading::Threads
#endif
}
void OSThread::OSAttach()
{
HandleRegister(this);