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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 ThreadPriority priority; | 49 ThreadPriority priority; |
50 }; | 50 }; |
51 | 51 |
52 DWORD __stdcall ThreadFunc(void* params) { | 52 DWORD __stdcall ThreadFunc(void* params) { |
53 ThreadParams* thread_params = static_cast<ThreadParams*>(params); | 53 ThreadParams* thread_params = static_cast<ThreadParams*>(params); |
54 PlatformThread::Delegate* delegate = thread_params->delegate; | 54 PlatformThread::Delegate* delegate = thread_params->delegate; |
55 if (!thread_params->joinable) | 55 if (!thread_params->joinable) |
56 base::ThreadRestrictions::SetSingletonAllowed(false); | 56 base::ThreadRestrictions::SetSingletonAllowed(false); |
57 | 57 |
58 if (thread_params->priority != ThreadPriority::NORMAL) { | 58 if (thread_params->priority != ThreadPriority::NORMAL) { |
59 PlatformThread::SetThreadPriority( | 59 PlatformThread::SetCurrentThreadPriority(thread_params->priority); |
60 PlatformThread::CurrentHandle(), thread_params->priority); | |
61 } | 60 } |
gab
2015/06/26 15:57:13
nit: can remove {}
Takashi Toyoshima
2015/06/29 05:48:51
Done.
| |
62 | 61 |
63 // Retrieve a copy of the thread handle to use as the key in the | 62 // Retrieve a copy of the thread handle to use as the key in the |
64 // thread name mapping. | 63 // thread name mapping. |
65 PlatformThreadHandle::Handle platform_handle; | 64 PlatformThreadHandle::Handle platform_handle; |
66 BOOL did_dup = DuplicateHandle(GetCurrentProcess(), | 65 BOOL did_dup = DuplicateHandle(GetCurrentProcess(), |
67 GetCurrentThread(), | 66 GetCurrentThread(), |
68 GetCurrentProcess(), | 67 GetCurrentProcess(), |
69 &platform_handle, | 68 &platform_handle, |
70 0, | 69 0, |
71 FALSE, | 70 FALSE, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 DWORD error = GetLastError(); | 230 DWORD error = GetLastError(); |
232 debug::Alias(&error); | 231 debug::Alias(&error); |
233 debug::Alias(&result); | 232 debug::Alias(&result); |
234 CHECK(false); | 233 CHECK(false); |
235 } | 234 } |
236 | 235 |
237 CloseHandle(thread_handle.platform_handle()); | 236 CloseHandle(thread_handle.platform_handle()); |
238 } | 237 } |
239 | 238 |
240 // static | 239 // static |
241 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, | 240 void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) { |
242 ThreadPriority priority) { | |
243 DCHECK(!handle.is_null()); | 241 DCHECK(!handle.is_null()); |
244 | 242 |
245 int desired_priority = THREAD_PRIORITY_ERROR_RETURN; | 243 int desired_priority = THREAD_PRIORITY_ERROR_RETURN; |
246 switch (priority) { | 244 switch (priority) { |
247 case ThreadPriority::BACKGROUND: | 245 case ThreadPriority::BACKGROUND: |
248 desired_priority = THREAD_PRIORITY_LOWEST; | 246 desired_priority = THREAD_PRIORITY_LOWEST; |
249 break; | 247 break; |
250 case ThreadPriority::NORMAL: | 248 case ThreadPriority::NORMAL: |
251 desired_priority = THREAD_PRIORITY_NORMAL; | 249 desired_priority = THREAD_PRIORITY_NORMAL; |
252 break; | 250 break; |
253 case ThreadPriority::DISPLAY: | 251 case ThreadPriority::DISPLAY: |
254 desired_priority = THREAD_PRIORITY_ABOVE_NORMAL; | 252 desired_priority = THREAD_PRIORITY_ABOVE_NORMAL; |
255 break; | 253 break; |
256 case ThreadPriority::REALTIME_AUDIO: | 254 case ThreadPriority::REALTIME_AUDIO: |
257 desired_priority = THREAD_PRIORITY_TIME_CRITICAL; | 255 desired_priority = THREAD_PRIORITY_TIME_CRITICAL; |
258 break; | 256 break; |
259 default: | 257 default: |
260 NOTREACHED() << "Unknown priority."; | 258 NOTREACHED() << "Unknown priority."; |
261 break; | 259 break; |
262 } | 260 } |
263 DCHECK_NE(desired_priority, THREAD_PRIORITY_ERROR_RETURN); | 261 DCHECK_NE(desired_priority, THREAD_PRIORITY_ERROR_RETURN); |
264 | 262 |
265 #ifndef NDEBUG | 263 #ifndef NDEBUG |
266 const BOOL success = | 264 const BOOL success = |
267 #endif | 265 #endif |
268 ::SetThreadPriority(handle.platform_handle(), desired_priority); | 266 ::SetThreadPriority(PlatformThread::CurrentHandle().platform_handle(), |
267 desired_priority); | |
269 DPLOG_IF(ERROR, !success) << "Failed to set thread priority to " | 268 DPLOG_IF(ERROR, !success) << "Failed to set thread priority to " |
270 << desired_priority; | 269 << desired_priority; |
271 } | 270 } |
272 | 271 |
273 // static | 272 // static |
274 ThreadPriority PlatformThread::GetThreadPriority(PlatformThreadHandle handle) { | 273 ThreadPriority PlatformThread::GetCurrentThreadPriority() { |
275 DCHECK(!handle.is_null()); | 274 DCHECK(!handle.is_null()); |
276 | 275 |
277 int priority = ::GetThreadPriority(handle.platform_handle()); | 276 int priority = |
277 ::GetThreadPriority(PlatformThread::CurrentHandle().platform_handle()); | |
278 switch (priority) { | 278 switch (priority) { |
279 case THREAD_PRIORITY_LOWEST: | 279 case THREAD_PRIORITY_LOWEST: |
280 return ThreadPriority::BACKGROUND; | 280 return ThreadPriority::BACKGROUND; |
281 case THREAD_PRIORITY_NORMAL: | 281 case THREAD_PRIORITY_NORMAL: |
282 return ThreadPriority::NORMAL; | 282 return ThreadPriority::NORMAL; |
283 case THREAD_PRIORITY_ABOVE_NORMAL: | 283 case THREAD_PRIORITY_ABOVE_NORMAL: |
284 return ThreadPriority::DISPLAY; | 284 return ThreadPriority::DISPLAY; |
285 case THREAD_PRIORITY_TIME_CRITICAL: | 285 case THREAD_PRIORITY_TIME_CRITICAL: |
286 return ThreadPriority::REALTIME_AUDIO; | 286 return ThreadPriority::REALTIME_AUDIO; |
287 case THREAD_PRIORITY_ERROR_RETURN: | 287 case THREAD_PRIORITY_ERROR_RETURN: |
288 DPCHECK(false) << "GetThreadPriority error"; // Falls through. | 288 DPCHECK(false) << "GetThreadPriority error"; // Falls through. |
289 default: | 289 default: |
290 NOTREACHED() << "Unexpected priority: " << priority; | 290 NOTREACHED() << "Unexpected priority: " << priority; |
291 return ThreadPriority::NORMAL; | 291 return ThreadPriority::NORMAL; |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 } // namespace base | 295 } // namespace base |
OLD | NEW |