mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-12-11 07:37:01 +00:00
Windows: Use modern API to set thread name if available (#1634)
This commit is contained in:
parent
08609591ae
commit
55a735dcfa
1 changed files with 14 additions and 0 deletions
|
|
@ -116,6 +116,19 @@ typedef struct tagTHREADNAME_INFO
|
|||
void SetThreadName(const char* name)
|
||||
{
|
||||
#if BOOST_OS_WINDOWS
|
||||
using SetThreadDescription_t = HRESULT (*)(HANDLE hThread, PCWSTR lpThreadDescription);
|
||||
static SetThreadDescription_t pSetThreadDescription = nullptr;
|
||||
if (!pSetThreadDescription)
|
||||
pSetThreadDescription = (SetThreadDescription_t)GetProcAddress(LoadLibraryW(L"Kernel32.dll"), "SetThreadDescription");
|
||||
if (pSetThreadDescription)
|
||||
{
|
||||
size_t len = strlen(name) * 2 + 1;
|
||||
auto threadDescription = new wchar_t[len];
|
||||
if (boost::nowide::widen(threadDescription, len, name))
|
||||
pSetThreadDescription(GetCurrentThread(), threadDescription);
|
||||
delete[] threadDescription;
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
THREADNAME_INFO info;
|
||||
info.dwType = 0x1000;
|
||||
info.szName = name;
|
||||
|
|
@ -129,6 +142,7 @@ void SetThreadName(const char* name)
|
|||
__except (EXCEPTION_EXECUTE_HANDLER) {
|
||||
}
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#elif BOOST_OS_MACOS
|
||||
pthread_setname_np(name);
|
||||
#else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue