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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 *out_thread_handle = PlatformThreadHandle(thread_handle); | 119 *out_thread_handle = PlatformThreadHandle(thread_handle); |
120 else | 120 else |
121 CloseHandle(thread_handle); | 121 CloseHandle(thread_handle); |
122 return true; | 122 return true; |
123 } | 123 } |
124 | 124 |
125 } // namespace | 125 } // namespace |
126 | 126 |
127 // static | 127 // static |
128 PlatformThreadId PlatformThread::CurrentId() { | 128 PlatformThreadId PlatformThread::CurrentId() { |
129 return GetCurrentThreadId(); | 129 return ::GetCurrentThreadId(); |
130 } | 130 } |
131 | 131 |
132 // static | 132 // static |
133 PlatformThreadRef PlatformThread::CurrentRef() { | 133 PlatformThreadRef PlatformThread::CurrentRef() { |
134 return PlatformThreadRef(GetCurrentThreadId()); | 134 return PlatformThreadRef(::GetCurrentThreadId()); |
135 } | 135 } |
136 | 136 |
137 // static | 137 // static |
138 PlatformThreadHandle PlatformThread::CurrentHandle() { | 138 PlatformThreadHandle PlatformThread::CurrentHandle() { |
139 NOTIMPLEMENTED(); // See OpenThread() | 139 return PlatformThreadHandle(::GetCurrentThread()); |
140 return PlatformThreadHandle(); | |
141 } | 140 } |
142 | 141 |
143 // static | 142 // static |
144 void PlatformThread::YieldCurrentThread() { | 143 void PlatformThread::YieldCurrentThread() { |
145 ::Sleep(0); | 144 ::Sleep(0); |
146 } | 145 } |
147 | 146 |
148 // static | 147 // static |
149 void PlatformThread::Sleep(TimeDelta duration) { | 148 void PlatformThread::Sleep(TimeDelta duration) { |
150 // When measured with a high resolution clock, Sleep() sometimes returns much | 149 // When measured with a high resolution clock, Sleep() sometimes returns much |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 debug::Alias(&thread_handle.handle_); | 226 debug::Alias(&thread_handle.handle_); |
228 CHECK(false); | 227 CHECK(false); |
229 } | 228 } |
230 | 229 |
231 CloseHandle(thread_handle.handle_); | 230 CloseHandle(thread_handle.handle_); |
232 } | 231 } |
233 | 232 |
234 // static | 233 // static |
235 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, | 234 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, |
236 ThreadPriority priority) { | 235 ThreadPriority priority) { |
237 switch (priority) { | 236 DCHECK(!handle.is_null()); |
237 | |
238 int desired_priority = THREAD_PRIORITY_ERROR_RETURN; | |
239 switch (desired_priority) { | |
238 case kThreadPriority_Normal: | 240 case kThreadPriority_Normal: |
239 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_NORMAL); | 241 desired_priority = THREAD_PRIORITY_NORMAL; |
240 break; | 242 break; |
241 case kThreadPriority_RealtimeAudio: | 243 case kThreadPriority_RealtimeAudio: |
242 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL); | 244 desired_priority = THREAD_PRIORITY_TIME_CRITICAL; |
245 break; | |
246 case kThreadPriority_Display: | |
247 desired_priority = THREAD_PRIORITY_ABOVE_NORMAL; | |
248 break; | |
249 case kThreadPriority_Background: | |
250 desired_priority = THREAD_PRIORITY_LOWEST; | |
243 break; | 251 break; |
244 default: | 252 default: |
245 NOTREACHED() << "Unknown priority."; | 253 NOTREACHED() << "Unknown priority."; |
246 break; | 254 break; |
247 } | 255 } |
256 DCHECK_NE(desired_priority, THREAD_PRIORITY_ERROR_RETURN); | |
rvargas (doing something else)
2015/03/30 22:31:23
Isn't this the same as line 253?
gab
2015/03/31 14:02:33
If all case statements set |desired_priority|, yes
| |
257 | |
258 BOOL success = ::SetThreadPriority(handle.handle_, desired_priority); | |
259 DPCHECK(success); | |
260 } | |
261 | |
262 // static | |
263 ThreadPriority PlatformThread::GetThreadPriority(PlatformThreadHandle handle) { | |
264 DCHECK(!handle.is_null()); | |
265 | |
266 int priority = ::GetThreadPriority(handle.handle_); | |
267 switch (priority) { | |
268 case THREAD_PRIORITY_NORMAL: | |
269 return kThreadPriority_Normal; | |
270 case THREAD_PRIORITY_TIME_CRITICAL: | |
271 return kThreadPriority_RealtimeAudio; | |
272 case THREAD_PRIORITY_ABOVE_NORMAL: | |
273 return kThreadPriority_Display; | |
274 case THREAD_PRIORITY_LOWEST: | |
275 return kThreadPriority_Background; | |
276 case THREAD_PRIORITY_ERROR_RETURN: | |
277 DPCHECK(false) << "GetThreadPriority error"; // Falls through. | |
278 default: | |
279 NOTREACHED() << "Unexpected priority: " << priority; | |
280 return kThreadPriority_Normal; | |
281 } | |
248 } | 282 } |
249 | 283 |
250 } // namespace base | 284 } // namespace base |
OLD | NEW |