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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/debug/profiler.h" | 10 #include "base/debug/profiler.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/threading/thread_id_name_manager.h" | 12 #include "base/threading/thread_id_name_manager.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "base/tracked_objects.h" | 14 #include "base/tracked_objects.h" |
15 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
16 #include "base/win/windows_version.h" | |
17 | 16 |
18 namespace base { | 17 namespace base { |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // The information on how to set the thread name comes from | 21 // The information on how to set the thread name comes from |
23 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx | 22 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx |
24 const DWORD kVCThreadNameException = 0x406D1388; | 23 const DWORD kVCThreadNameException = 0x406D1388; |
25 | 24 |
26 typedef struct tagTHREADNAME_INFO { | 25 typedef struct tagTHREADNAME_INFO { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 92 } |
94 | 93 |
95 // CreateThreadInternal() matches PlatformThread::CreateWithPriority(), except | 94 // CreateThreadInternal() matches PlatformThread::CreateWithPriority(), except |
96 // that |out_thread_handle| may be nullptr, in which case a non-joinable thread | 95 // that |out_thread_handle| may be nullptr, in which case a non-joinable thread |
97 // is created. | 96 // is created. |
98 bool CreateThreadInternal(size_t stack_size, | 97 bool CreateThreadInternal(size_t stack_size, |
99 PlatformThread::Delegate* delegate, | 98 PlatformThread::Delegate* delegate, |
100 PlatformThreadHandle* out_thread_handle, | 99 PlatformThreadHandle* out_thread_handle, |
101 ThreadPriority priority) { | 100 ThreadPriority priority) { |
102 unsigned int flags = 0; | 101 unsigned int flags = 0; |
103 if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) { | 102 if (stack_size > 0) { |
104 flags = STACK_SIZE_PARAM_IS_A_RESERVATION; | 103 flags = STACK_SIZE_PARAM_IS_A_RESERVATION; |
105 } else { | |
106 stack_size = 0; | |
107 } | 104 } |
108 | 105 |
109 ThreadParams* params = new ThreadParams; | 106 ThreadParams* params = new ThreadParams; |
110 params->delegate = delegate; | 107 params->delegate = delegate; |
111 params->joinable = out_thread_handle != nullptr; | 108 params->joinable = out_thread_handle != nullptr; |
112 params->priority = priority; | 109 params->priority = priority; |
113 | 110 |
114 // Using CreateThread here vs _beginthreadex makes thread creation a bit | 111 // Using CreateThread here vs _beginthreadex makes thread creation a bit |
115 // faster and doesn't require the loader lock to be available. Our code will | 112 // faster and doesn't require the loader lock to be available. Our code will |
116 // have to work running on CreateThread() threads anyway, since we run code | 113 // have to work running on CreateThread() threads anyway, since we run code |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return ThreadPriority::REALTIME_AUDIO; | 270 return ThreadPriority::REALTIME_AUDIO; |
274 case THREAD_PRIORITY_ERROR_RETURN: | 271 case THREAD_PRIORITY_ERROR_RETURN: |
275 DPCHECK(false) << "GetThreadPriority error"; // Falls through. | 272 DPCHECK(false) << "GetThreadPriority error"; // Falls through. |
276 default: | 273 default: |
277 NOTREACHED() << "Unexpected priority: " << priority; | 274 NOTREACHED() << "Unexpected priority: " << priority; |
278 return ThreadPriority::NORMAL; | 275 return ThreadPriority::NORMAL; |
279 } | 276 } |
280 } | 277 } |
281 | 278 |
282 } // namespace base | 279 } // namespace base |
OLD | NEW |