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