summaryrefslogtreecommitdiff
path: root/src/os/windows
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2016-10-30 18:22:55 +0000
committermichi_cc <michi_cc@openttd.org>2016-10-30 18:22:55 +0000
commitc83306391e78d660b4c7b1bfef4008ccd5c7e172 (patch)
tree017d634c46d1344a498e441b811972601f162028 /src/os/windows
parentb2fe2c6e3d5570861fcca497da4c7dc8d94078cf (diff)
downloadopenttd-c83306391e78d660b4c7b1bfef4008ccd5c7e172.tar.xz
(svn r27673) -Add: [Win32] Thread names for windows debuggers.
Diffstat (limited to 'src/os/windows')
-rw-r--r--src/os/windows/win32.cpp33
-rw-r--r--src/os/windows/win32.h6
2 files changed, 39 insertions, 0 deletions
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp
index 344d24314..3fd1777fa 100644
--- a/src/os/windows/win32.cpp
+++ b/src/os/windows/win32.cpp
@@ -785,3 +785,36 @@ uint GetCPUCoreCount()
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
+
+#ifdef _MSC_VER
+/* Code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
+const DWORD MS_VC_EXCEPTION = 0x406D1388;
+#pragma pack(push,8)
+typedef struct {
+ 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)
+
+/**
+ * Signal thread name to any attached debuggers.
+ */
+void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
+{
+ THREADNAME_INFO info;
+ info.dwType = 0x1000;
+ info.szName = threadName;
+ info.dwThreadID = dwThreadID;
+ info.dwFlags = 0;
+
+#pragma warning(push)
+#pragma warning(disable: 6320 6322)
+ __try {
+ RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
+ } __except (EXCEPTION_EXECUTE_HANDLER) {
+ }
+#pragma warning(pop)
+}
+#endif
diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h
index 4e53879cf..c3ded817a 100644
--- a/src/os/windows/win32.h
+++ b/src/os/windows/win32.h
@@ -39,4 +39,10 @@ HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
#define SHGFP_TYPE_CURRENT 0
#endif /* __MINGW32__ */
+#ifdef _MSC_VER
+void SetWin32ThreadName(DWORD dwThreadID, const char* threadName);
+#else
+void SetWin32ThreadName(DWORD dwThreadID, const char* threadName) {}
+#endif
+
#endif /* WIN32_H */