Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: base/threading/platform_thread_win.cc

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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) {
236 DCHECK(!handle.is_null());
237
238 int desired_priority = THREAD_PRIORITY_ERROR_RETURN;
237 switch (priority) { 239 switch (priority) {
238 case kThreadPriority_Normal: 240 case ThreadPriority::BACKGROUND:
239 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_NORMAL); 241 desired_priority = THREAD_PRIORITY_LOWEST;
240 break; 242 break;
241 case kThreadPriority_RealtimeAudio: 243 case ThreadPriority::NORMAL:
242 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL); 244 desired_priority = THREAD_PRIORITY_NORMAL;
245 break;
246 case ThreadPriority::DISPLAY:
247 desired_priority = THREAD_PRIORITY_ABOVE_NORMAL;
248 break;
249 case ThreadPriority::REALTIME_AUDIO:
250 desired_priority = THREAD_PRIORITY_TIME_CRITICAL;
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);
257
258 #ifndef NDEBUG
259 const BOOL success =
260 #endif
261 ::SetThreadPriority(handle.handle_, desired_priority);
262 DPLOG_IF(ERROR, !success) << "Failed to set thread priority to "
263 << desired_priority;
264 }
265
266 // static
267 ThreadPriority PlatformThread::GetThreadPriority(PlatformThreadHandle handle) {
268 DCHECK(!handle.is_null());
269
270 int priority = ::GetThreadPriority(handle.handle_);
271 switch (priority) {
272 case THREAD_PRIORITY_LOWEST:
273 return ThreadPriority::BACKGROUND;
274 case THREAD_PRIORITY_NORMAL:
275 return ThreadPriority::NORMAL;
276 case THREAD_PRIORITY_ABOVE_NORMAL:
277 return ThreadPriority::DISPLAY;
278 case THREAD_PRIORITY_TIME_CRITICAL:
279 return ThreadPriority::REALTIME_AUDIO;
280 case THREAD_PRIORITY_ERROR_RETURN:
281 DPCHECK(false) << "GetThreadPriority error"; // Falls through.
282 default:
283 NOTREACHED() << "Unexpected priority: " << priority;
284 return ThreadPriority::NORMAL;
285 }
248 } 286 }
249 287
250 } // namespace base 288 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698