Chromium Code Reviews| Index: src/platform-win32.cc |
| diff --git a/src/platform-win32.cc b/src/platform-win32.cc |
| index fe84bcd3fff234bd69b2e834f8bda105f29f148b..36fdf6c13c42b84e23d11fd8958bd5d5d222bc62 100644 |
| --- a/src/platform-win32.cc |
| +++ b/src/platform-win32.cc |
| @@ -1423,12 +1423,39 @@ bool VirtualMemory::HasLazyCommits() { |
| // Definition of invalid thread handle and id. |
| static const HANDLE kNoThread = INVALID_HANDLE_VALUE; |
| +static void SetCurThreadName(const char* name) { |
|
Benedikt Meurer
2014/03/31 06:57:02
Nit: Use SetCurrentThreadName()
Jarin
2014/03/31 07:46:00
How about taking the code from Chromium? See https
|
| + // Reference: http://www.codeproject.com/KB/threads/Name_threads_in_debugger.aspx |
|
Jarin
2014/03/31 07:46:00
I would prefer to link Microsoft rather than codep
|
| + |
| + typedef struct tagTHREADNAME_INFO { |
| + 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; |
| + |
| + THREADNAME_INFO info; |
| + { |
|
Benedikt Meurer
2014/03/31 06:57:02
Nit: no need for a {}-block here.
|
| + info.dwType = 0x1000; |
| + info.szName = name; |
| + info.dwThreadID = (DWORD)-1; |
|
Benedikt Meurer
2014/03/31 06:57:02
Use static_cast<DWORD>(-1)
|
| + info.dwFlags = 0; |
| + } |
| + |
| + __try { |
| + RaiseException( |
| + 0x406D1388 /* MSVC EXCEPTION */, 0, |
| + sizeof(info)/sizeof(DWORD), reinterpret_cast<ULONG_PTR*>(&info)); |
|
Jarin
2014/03/31 07:46:00
The Microsoft article says the third arg should be
|
| + } |
| + __except(EXCEPTION_CONTINUE_EXECUTION) {} |
| +} |
| + |
| // Entry point for threads. The supplied argument is a pointer to the thread |
| // object. The entry function dispatches to the run method in the thread |
| // object. It is important that this function has __stdcall calling |
| // convention. |
| static unsigned int __stdcall ThreadEntry(void* arg) { |
| Thread* thread = reinterpret_cast<Thread*>(arg); |
| + SetCurThreadName(thread->name()); |
| thread->NotifyStartedAndRun(); |
| return 0; |
| } |