OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/debug/alias.h" |
8 #include "base/debug/profiler.h" | 8 #include "base/debug/profiler.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/threading/thread_id_name_manager.h" | 10 #include "base/threading/thread_id_name_manager.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 __try { | 39 __try { |
40 RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), | 40 RaiseException(kVCThreadNameException, 0, sizeof(info)/sizeof(DWORD), |
41 reinterpret_cast<DWORD_PTR*>(&info)); | 41 reinterpret_cast<DWORD_PTR*>(&info)); |
42 } __except(EXCEPTION_CONTINUE_EXECUTION) { | 42 } __except(EXCEPTION_CONTINUE_EXECUTION) { |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 struct ThreadParams { | 46 struct ThreadParams { |
47 PlatformThread::Delegate* delegate; | 47 PlatformThread::Delegate* delegate; |
48 bool joinable; | 48 bool joinable; |
49 PlatformThreadHandle* thread_handle; | |
49 }; | 50 }; |
50 | 51 |
51 DWORD __stdcall ThreadFunc(void* params) { | 52 DWORD __stdcall ThreadFunc(void* params) { |
52 ThreadParams* thread_params = static_cast<ThreadParams*>(params); | 53 ThreadParams* thread_params = static_cast<ThreadParams*>(params); |
53 PlatformThread::Delegate* delegate = thread_params->delegate; | 54 PlatformThread::Delegate* delegate = thread_params->delegate; |
54 if (!thread_params->joinable) | 55 if (!thread_params->joinable) |
55 base::ThreadRestrictions::SetSingletonAllowed(false); | 56 base::ThreadRestrictions::SetSingletonAllowed(false); |
57 | |
58 ThreadIdNameManager::GetInstance()->RegisterThread( | |
59 thread_params->thread_handle, | |
60 PlatformThread::CurrentId()); | |
56 delete thread_params; | 61 delete thread_params; |
57 delegate->ThreadMain(); | 62 delegate->ThreadMain(); |
58 return NULL; | 63 return NULL; |
jar (doing other things)
2013/05/22 19:37:56
Wouldn't this be a great place to unregister, just
dsinclair
2013/05/22 20:22:31
The benefit I see from having it in the Join metho
jar (doing other things)
2013/05/22 21:36:48
I think that by the time you hit line 63, any mess
dsinclair
2013/05/23 18:21:53
Done.
| |
59 } | 64 } |
60 | 65 |
61 // CreateThreadInternal() matches PlatformThread::Create(), except that | 66 // CreateThreadInternal() matches PlatformThread::Create(), except that |
62 // |out_thread_handle| may be NULL, in which case a non-joinable thread is | 67 // |out_thread_handle| may be NULL, in which case a non-joinable thread is |
63 // created. | 68 // created. |
64 bool CreateThreadInternal(size_t stack_size, | 69 bool CreateThreadInternal(size_t stack_size, |
65 PlatformThread::Delegate* delegate, | 70 PlatformThread::Delegate* delegate, |
66 PlatformThreadHandle* out_thread_handle) { | 71 PlatformThreadHandle* out_thread_handle) { |
67 PlatformThreadHandle thread_handle; | 72 PlatformThreadHandle thread_handle; |
68 unsigned int flags = 0; | 73 unsigned int flags = 0; |
69 if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) { | 74 if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) { |
70 flags = STACK_SIZE_PARAM_IS_A_RESERVATION; | 75 flags = STACK_SIZE_PARAM_IS_A_RESERVATION; |
71 } else { | 76 } else { |
72 stack_size = 0; | 77 stack_size = 0; |
73 } | 78 } |
74 | 79 |
75 ThreadParams* params = new ThreadParams; | 80 ThreadParams* params = new ThreadParams; |
76 params->delegate = delegate; | 81 params->delegate = delegate; |
77 params->joinable = out_thread_handle != NULL; | 82 params->joinable = out_thread_handle != NULL; |
83 params->thread_handle = out_thread_handle; | |
78 | 84 |
79 // Using CreateThread here vs _beginthreadex makes thread creation a bit | 85 // Using CreateThread here vs _beginthreadex makes thread creation a bit |
80 // faster and doesn't require the loader lock to be available. Our code will | 86 // faster and doesn't require the loader lock to be available. Our code will |
81 // have to work running on CreateThread() threads anyway, since we run code | 87 // have to work running on CreateThread() threads anyway, since we run code |
82 // on the Windows thread pool, etc. For some background on the difference: | 88 // on the Windows thread pool, etc. For some background on the difference: |
83 // http://www.microsoft.com/msj/1099/win32/win321099.aspx | 89 // http://www.microsoft.com/msj/1099/win32/win321099.aspx |
84 thread_handle = CreateThread( | 90 thread_handle = CreateThread( |
85 NULL, stack_size, ThreadFunc, params, flags, NULL); | 91 NULL, stack_size, ThreadFunc, params, flags, NULL); |
86 if (!thread_handle) { | 92 if (!thread_handle) { |
87 delete params; | 93 delete params; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 case kThreadPriority_Normal: | 202 case kThreadPriority_Normal: |
197 ::SetThreadPriority(handle, THREAD_PRIORITY_NORMAL); | 203 ::SetThreadPriority(handle, THREAD_PRIORITY_NORMAL); |
198 break; | 204 break; |
199 case kThreadPriority_RealtimeAudio: | 205 case kThreadPriority_RealtimeAudio: |
200 ::SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); | 206 ::SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); |
201 break; | 207 break; |
202 } | 208 } |
203 } | 209 } |
204 | 210 |
205 } // namespace base | 211 } // namespace base |
OLD | NEW |