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

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

Issue 1784623005: Test dynamic priorities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « base/threading/platform_thread_linux.cc ('k') | base/threading/simple_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <errno.h> 7 #include <errno.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <sched.h> 9 #include <sched.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // equivalent but makes sandboxing easier (https://crbug.com/399473). 226 // equivalent but makes sandboxing easier (https://crbug.com/399473).
227 const int nice_setting = internal::ThreadPriorityToNiceValue(priority); 227 const int nice_setting = internal::ThreadPriorityToNiceValue(priority);
228 if (setpriority(PRIO_PROCESS, 0, nice_setting)) { 228 if (setpriority(PRIO_PROCESS, 0, nice_setting)) {
229 DVPLOG(1) << "Failed to set nice value of thread (" 229 DVPLOG(1) << "Failed to set nice value of thread ("
230 << PlatformThread::CurrentId() << ") to " << nice_setting; 230 << PlatformThread::CurrentId() << ") to " << nice_setting;
231 } 231 }
232 #endif // defined(OS_NACL) 232 #endif // defined(OS_NACL)
233 } 233 }
234 234
235 // static 235 // static
236 bool PlatformThread::SetThreadPriority(PlatformThreadId tid,
237 ThreadPriority priority) {
238 return internal::SetThreadPriority(tid, priority);
239 }
240
241 // static
236 ThreadPriority PlatformThread::GetCurrentThreadPriority() { 242 ThreadPriority PlatformThread::GetCurrentThreadPriority() {
237 #if defined(OS_NACL) 243 #if defined(OS_NACL)
238 NOTIMPLEMENTED(); 244 NOTIMPLEMENTED();
239 return ThreadPriority::NORMAL; 245 return ThreadPriority::NORMAL;
240 #else 246 #else
241 // Mirrors SetCurrentThreadPriority()'s implementation. 247 // Mirrors SetCurrentThreadPriority()'s implementation.
242 ThreadPriority platform_specific_priority; 248 ThreadPriority platform_specific_priority;
243 if (internal::GetCurrentThreadPriorityForPlatform( 249 if (internal::GetCurrentThreadPriorityForPlatform(
244 &platform_specific_priority)) { 250 &platform_specific_priority)) {
245 return platform_specific_priority; 251 return platform_specific_priority;
246 } 252 }
247 253
248 // Need to clear errno before calling getpriority(): 254 // Need to clear errno before calling getpriority():
249 // http://man7.org/linux/man-pages/man2/getpriority.2.html 255 // http://man7.org/linux/man-pages/man2/getpriority.2.html
250 errno = 0; 256 errno = 0;
251 int nice_value = getpriority(PRIO_PROCESS, 0); 257 int nice_value = getpriority(PRIO_PROCESS, 0);
252 if (errno != 0) { 258 if (errno != 0) {
253 DVPLOG(1) << "Failed to get nice value of thread (" 259 DVPLOG(1) << "Failed to get nice value of thread ("
254 << PlatformThread::CurrentId() << ")"; 260 << PlatformThread::CurrentId() << ")";
255 return ThreadPriority::NORMAL; 261 return ThreadPriority::NORMAL;
256 } 262 }
257 263
258 return internal::NiceValueToThreadPriority(nice_value); 264 return internal::NiceValueToThreadPriority(nice_value);
259 #endif // !defined(OS_NACL) 265 #endif // !defined(OS_NACL)
260 } 266 }
261 267
262 #endif // !defined(OS_MACOSX) 268 #endif // !defined(OS_MACOSX)
263 269
264 } // namespace base 270 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_linux.cc ('k') | base/threading/simple_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698