|
|
@@ -8,6 +8,10 @@
|
|
|
|
|
|
#if BX_CONFIG_SUPPORTS_THREADING
|
|
|
|
|
|
+#if BX_PLATFORM_WINDOWS && !BX_CRT_NONE
|
|
|
+# include <bx/string.h>
|
|
|
+#endif
|
|
|
+
|
|
|
#if BX_CRT_NONE
|
|
|
# include "crt0.h"
|
|
|
#elif BX_PLATFORM_ANDROID \
|
|
|
@@ -240,33 +244,46 @@ namespace bx
|
|
|
# else
|
|
|
pthread_set_name_np(ti->m_handle, _name);
|
|
|
# endif // defined(__NetBSD__)
|
|
|
-#elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
|
|
|
-# pragma pack(push, 8)
|
|
|
- struct ThreadName
|
|
|
- {
|
|
|
- DWORD type;
|
|
|
- LPCSTR name;
|
|
|
- DWORD id;
|
|
|
- DWORD flags;
|
|
|
- };
|
|
|
-# pragma pack(pop)
|
|
|
- ThreadName tn;
|
|
|
- tn.type = 0x1000;
|
|
|
- tn.name = _name;
|
|
|
- tn.id = ti->m_threadId;
|
|
|
- tn.flags = 0;
|
|
|
-
|
|
|
- __try
|
|
|
- {
|
|
|
- RaiseException(0x406d1388
|
|
|
- , 0
|
|
|
- , sizeof(tn)/4
|
|
|
- , reinterpret_cast<ULONG_PTR*>(&tn)
|
|
|
- );
|
|
|
- }
|
|
|
- __except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
+#elif BX_PLATFORM_WINDOWS
|
|
|
+ // Try to use the new thread naming API from Win10 Creators update onwards if we have it
|
|
|
+ typedef HRESULT (WINAPI *SetThreadDescriptionProc)(HANDLE, PCWSTR);
|
|
|
+ SetThreadDescriptionProc SetThreadDescription = (SetThreadDescriptionProc)(GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetThreadDescription"));
|
|
|
+ if (SetThreadDescription)
|
|
|
{
|
|
|
+ uint32_t length = (uint32_t)bx::strLen(_name)+1;
|
|
|
+ uint32_t size = length*sizeof(wchar_t);
|
|
|
+ wchar_t* name = (wchar_t*)alloca(size);
|
|
|
+ mbstowcs(name, _name, size-2);
|
|
|
+ SetThreadDescription(ti->m_handle, name);
|
|
|
}
|
|
|
+# if BX_COMPILER_MSVC
|
|
|
+# pragma pack(push, 8)
|
|
|
+ struct ThreadName
|
|
|
+ {
|
|
|
+ DWORD type;
|
|
|
+ LPCSTR name;
|
|
|
+ DWORD id;
|
|
|
+ DWORD flags;
|
|
|
+ };
|
|
|
+# pragma pack(pop)
|
|
|
+ ThreadName tn;
|
|
|
+ tn.type = 0x1000;
|
|
|
+ tn.name = _name;
|
|
|
+ tn.id = ti->m_threadId;
|
|
|
+ tn.flags = 0;
|
|
|
+
|
|
|
+ __try
|
|
|
+ {
|
|
|
+ RaiseException(0x406d1388
|
|
|
+ , 0
|
|
|
+ , sizeof(tn)/4
|
|
|
+ , reinterpret_cast<ULONG_PTR*>(&tn)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ __except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
+ {
|
|
|
+ }
|
|
|
+# endif // BX_COMPILER_MSVC
|
|
|
#else
|
|
|
BX_UNUSED(_name);
|
|
|
#endif // BX_PLATFORM_
|