| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/threading/platform_thread.h" | 5 #include "base/threading/platform_thread.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "base/debug/trace_event.h" |
| 10 | 11 |
| 11 namespace base { | 12 namespace base { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // The information on how to set the thread name comes from | 16 // The information on how to set the thread name comes from |
| 16 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx | 17 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx |
| 17 const DWORD kVCThreadNameException = 0x406D1388; | 18 const DWORD kVCThreadNameException = 0x406D1388; |
| 18 | 19 |
| 19 typedef struct tagTHREADNAME_INFO { | 20 typedef struct tagTHREADNAME_INFO { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 ::Sleep(0); | 88 ::Sleep(0); |
| 88 } | 89 } |
| 89 | 90 |
| 90 // static | 91 // static |
| 91 void PlatformThread::Sleep(int duration_ms) { | 92 void PlatformThread::Sleep(int duration_ms) { |
| 92 ::Sleep(duration_ms); | 93 ::Sleep(duration_ms); |
| 93 } | 94 } |
| 94 | 95 |
| 95 // static | 96 // static |
| 96 void PlatformThread::SetName(const char* name) { | 97 void PlatformThread::SetName(const char* name) { |
| 98 base::debug::TraceLog::GetInstance()->SetCurrentThreadName(name); |
| 97 // The debugger needs to be around to catch the name in the exception. If | 99 // The debugger needs to be around to catch the name in the exception. If |
| 98 // there isn't a debugger, we are just needlessly throwing an exception. | 100 // there isn't a debugger, we are just needlessly throwing an exception. |
| 99 if (!::IsDebuggerPresent()) | 101 if (!::IsDebuggerPresent()) |
| 100 return; | 102 return; |
| 101 | 103 |
| 102 THREADNAME_INFO info; | 104 THREADNAME_INFO info; |
| 103 info.dwType = 0x1000; | 105 info.dwType = 0x1000; |
| 104 info.szName = name; | 106 info.szName = name; |
| 105 info.dwThreadID = CurrentId(); | 107 info.dwThreadID = CurrentId(); |
| 106 info.dwFlags = 0; | 108 info.dwFlags = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 CloseHandle(thread_handle); | 146 CloseHandle(thread_handle); |
| 145 } | 147 } |
| 146 | 148 |
| 147 // static | 149 // static |
| 148 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 150 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
| 149 // TODO(crogers): implement | 151 // TODO(crogers): implement |
| 150 NOTIMPLEMENTED(); | 152 NOTIMPLEMENTED(); |
| 151 } | 153 } |
| 152 | 154 |
| 153 } // namespace base | 155 } // namespace base |
| OLD | NEW |