diff options
author | michi_cc <michi_cc@openttd.org> | 2016-10-30 18:22:55 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2016-10-30 18:22:55 +0000 |
commit | c83306391e78d660b4c7b1bfef4008ccd5c7e172 (patch) | |
tree | 017d634c46d1344a498e441b811972601f162028 /src/thread | |
parent | b2fe2c6e3d5570861fcca497da4c7dc8d94078cf (diff) | |
download | openttd-c83306391e78d660b4c7b1bfef4008ccd5c7e172.tar.xz |
(svn r27673) -Add: [Win32] Thread names for windows debuggers.
Diffstat (limited to 'src/thread')
-rw-r--r-- | src/thread/thread_win32.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/thread/thread_win32.cpp b/src/thread/thread_win32.cpp index 81a721253..a01ea8e10 100644 --- a/src/thread/thread_win32.cpp +++ b/src/thread/thread_win32.cpp @@ -16,6 +16,7 @@ #include <stdlib.h> #include <windows.h> #include <process.h> +#include "../os/windows/win32.h" #include "../safeguards.h" @@ -29,17 +30,19 @@ private: OTTDThreadFunc proc; ///< External thread procedure. void *param; ///< Parameter for the external thread procedure. bool self_destruct; ///< Free ourselves when done? + const char *name; ///< Thread name. public: /** * Create a win32 thread and start it, calling proc(param). */ - ThreadObject_Win32(OTTDThreadFunc proc, void *param, bool self_destruct) : + ThreadObject_Win32(OTTDThreadFunc proc, void *param, bool self_destruct, const char *name) : thread(NULL), id(0), proc(proc), param(param), - self_destruct(self_destruct) + self_destruct(self_destruct), + name(name) { this->thread = (HANDLE)_beginthreadex(NULL, 0, &stThreadProc, this, CREATE_SUSPENDED, &this->id); if (this->thread == NULL) return; @@ -85,6 +88,10 @@ private: */ void ThreadProc() { +#ifdef _MSC_VER + /* Set thread name for debuggers. Has to be done from the thread due to a race condition in older MS debuggers. */ + SetWin32ThreadName(-1, this->name); +#endif try { this->proc(this->param); } catch (OTTDThreadExitSignal) { @@ -98,7 +105,7 @@ private: /* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name) { - ThreadObject *to = new ThreadObject_Win32(proc, param, thread == NULL); + ThreadObject *to = new ThreadObject_Win32(proc, param, thread == NULL, name); if (thread != NULL) *thread = to; return true; } |