diff --git a/rtc_base/platform_thread_types.cc b/rtc_base/platform_thread_types.cc index 67bb0542e9..ed4a228262 100644 --- a/rtc_base/platform_thread_types.cc +++ b/rtc_base/platform_thread_types.cc @@ -58,18 +58,25 @@ bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) { void SetCurrentThreadName(const char* name) { #if defined(WEBRTC_WIN) + // For details see: + // https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code +#pragma pack(push, 8) struct { DWORD dwType; LPCSTR szName; DWORD dwThreadID; DWORD dwFlags; } threadname_info = {0x1000, name, static_cast(-1), 0}; +#pragma pack(pop) +#pragma warning(push) +#pragma warning(disable : 6320 6322) __try { - ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(DWORD), + ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(ULONG_PTR), reinterpret_cast(&threadname_info)); } __except (EXCEPTION_EXECUTE_HANDLER) { // NOLINT } +#pragma warning(pop) #elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) prctl(PR_SET_NAME, reinterpret_cast(name)); // NOLINT #elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS)