File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,19 @@ typedef struct tagTHREADNAME_INFO
116
116
void SetThreadName (const char * name)
117
117
{
118
118
#if BOOST_OS_WINDOWS
119
+ using SetThreadDescription_t = HRESULT (*)(HANDLE hThread, PCWSTR lpThreadDescription);
120
+ static SetThreadDescription_t pSetThreadDescription = nullptr ;
121
+ if (!pSetThreadDescription)
122
+ pSetThreadDescription = (SetThreadDescription_t)GetProcAddress (LoadLibraryW (L" Kernel32.dll" ), " SetThreadDescription" );
123
+ if (pSetThreadDescription)
124
+ {
125
+ size_t len = strlen (name) * 2 + 1 ;
126
+ auto threadDescription = new wchar_t [len];
127
+ if (boost::nowide::widen (threadDescription, len, name))
128
+ pSetThreadDescription (GetCurrentThread (), threadDescription);
129
+ delete[] threadDescription;
130
+ }
131
+ #ifdef _MSC_VER
119
132
THREADNAME_INFO info;
120
133
info.dwType = 0x1000 ;
121
134
info.szName = name;
@@ -129,6 +142,7 @@ void SetThreadName(const char* name)
129
142
__except (EXCEPTION_EXECUTE_HANDLER) {
130
143
}
131
144
#pragma warning(pop)
145
+ #endif
132
146
#elif BOOST_OS_MACOS
133
147
pthread_setname_np (name);
134
148
#else
You can’t perform that action at this time.
0 commit comments