IXWebSocket/ixwebsocket/windows/IXSetThreadName_windows.cpp

47 lines
1.1 KiB
C++
Raw Normal View History

2019-01-05 00:23:57 +01:00
/*
* IXSetThreadName_windows.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
*/
#include "../IXSetThreadName.h"
2019-09-23 19:25:23 +02:00
2019-05-08 16:43:43 +02:00
#include <Windows.h>
2019-01-05 00:23:57 +01:00
namespace ix
{
2019-05-08 16:43:43 +02:00
const DWORD MS_VC_EXCEPTION = 0x406D1388;
2019-09-23 19:25:23 +02:00
#pragma pack(push, 8)
2019-05-08 16:43:43 +02:00
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
void SetThreadName(DWORD dwThreadID, const char* threadName)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try
{
2019-09-23 19:25:23 +02:00
RaiseException(
MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*) &info);
2019-05-08 16:43:43 +02:00
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
}
2019-01-05 00:23:57 +01:00
void setThreadName(const std::string& name)
{
2019-05-08 16:43:43 +02:00
SetThreadName(-1, name.c_str());
2019-01-05 00:23:57 +01:00
}
2019-09-23 19:25:23 +02:00
} // namespace ix