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/debug/alias.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
9 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
10 | 11 |
11 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 static ThreadLocalPointer<char> current_thread_name; | 18 static ThreadLocalPointer<char> current_thread_name; |
18 | 19 |
19 // The information on how to set the thread name comes from | 20 // The information on how to set the thread name comes from |
20 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx | 21 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx |
21 const DWORD kVCThreadNameException = 0x406D1388; | 22 const DWORD kVCThreadNameException = 0x406D1388; |
22 | 23 |
23 typedef struct tagTHREADNAME_INFO { | 24 typedef struct tagTHREADNAME_INFO { |
24 DWORD dwType; // Must be 0x1000. | 25 DWORD dwType; // Must be 0x1000. |
25 LPCSTR szName; // Pointer to name (in user addr space). | 26 LPCSTR szName; // Pointer to name (in user addr space). |
26 DWORD dwThreadID; // Thread ID (-1=caller thread). | 27 DWORD dwThreadID; // Thread ID (-1=caller thread). |
27 DWORD dwFlags; // Reserved for future use, must be zero. | 28 DWORD dwFlags; // Reserved for future use, must be zero. |
28 } THREADNAME_INFO; | 29 } THREADNAME_INFO; |
29 | 30 |
30 struct ThreadParams { | 31 struct ThreadParams { |
31 PlatformThread::Delegate* delegate; | 32 PlatformThread::Delegate* delegate; |
32 bool joinable; | 33 bool joinable; |
33 }; | 34 }; |
34 | 35 |
35 DWORD __stdcall ThreadFunc(void* params) { | 36 DWORD __stdcall ThreadFunc(void* params) { |
| 37 // TODO(apatrick): Remove this ASAP. This ensures that if the |
| 38 // TerminateProcess entry point has been patched to point into a third party |
| 39 // DLL, this is visible on the stack and the DLL in question can be |
| 40 // determined. |
| 41 typedef BOOL (WINAPI *TerminateProcessPtr)(HANDLE, UINT); |
| 42 TerminateProcessPtr terminate_process = TerminateProcess; |
| 43 base::debug::Alias(&terminate_process); |
| 44 |
36 ThreadParams* thread_params = static_cast<ThreadParams*>(params); | 45 ThreadParams* thread_params = static_cast<ThreadParams*>(params); |
37 PlatformThread::Delegate* delegate = thread_params->delegate; | 46 PlatformThread::Delegate* delegate = thread_params->delegate; |
38 if (!thread_params->joinable) | 47 if (!thread_params->joinable) |
39 base::ThreadRestrictions::SetSingletonAllowed(false); | 48 base::ThreadRestrictions::SetSingletonAllowed(false); |
40 delete thread_params; | 49 delete thread_params; |
41 delegate->ThreadMain(); | 50 delegate->ThreadMain(); |
42 return NULL; | 51 return NULL; |
43 } | 52 } |
44 | 53 |
45 // CreateThreadInternal() matches PlatformThread::Create(), except that | 54 // CreateThreadInternal() matches PlatformThread::Create(), except that |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 CloseHandle(thread_handle); | 164 CloseHandle(thread_handle); |
156 } | 165 } |
157 | 166 |
158 // static | 167 // static |
159 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 168 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
160 // TODO(crogers): implement | 169 // TODO(crogers): implement |
161 NOTIMPLEMENTED(); | 170 NOTIMPLEMENTED(); |
162 } | 171 } |
163 | 172 |
164 } // namespace base | 173 } // namespace base |
OLD | NEW |