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

Unified Diff: base/threading/platform_thread_posix.cc

Issue 1193303002: base/threading: restrict to set only current thread priority (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: two more android fix and review #2 Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: base/threading/platform_thread_posix.cc
diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc
index 0d821a9b7ad803099817e16be62a6014a79f9e04..bcf6a1c8e8876572e133481d0993b960105b01c3 100644
--- a/base/threading/platform_thread_posix.cc
+++ b/base/threading/platform_thread_posix.cc
@@ -59,8 +59,7 @@ void* ThreadFunc(void* params) {
base::ThreadRestrictions::SetSingletonAllowed(false);
if (thread_params->priority != ThreadPriority::NORMAL) {
- PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(),
- thread_params->priority);
+ PlatformThread::SetCurrentThreadPriority(thread_params->priority);
}
// Stash the id in the handle so the calling thread has a complete
@@ -231,16 +230,15 @@ void PlatformThread::Join(PlatformThreadHandle thread_handle) {
CHECK_EQ(0, pthread_join(thread_handle.platform_handle(), NULL));
}
-// Mac has its own Set/GetThreadPriority() implementations.
+// Mac has its own Set/GetCurrentThreadPriority() implementations.
#if !defined(OS_MACOSX)
// static
-void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
- ThreadPriority priority) {
+void PlatformThread::SetCurrentThreadPriority(ThreadPriority priority) {
#if defined(OS_NACL)
NOTIMPLEMENTED();
#else
- if (internal::SetThreadPriorityForPlatform(handle, priority))
+ if (internal::SetCurrentThreadPriorityForPlatform(priority))
return;
// setpriority(2) should change the whole thread group's (i.e. process)
@@ -249,39 +247,36 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
// Linux/NPTL implementation of POSIX threads, the nice value is a per-thread
// attribute". Also, 0 is prefered to the current thread id since it is
// equivalent but makes sandboxing easier (https://crbug.com/399473).
- DCHECK_NE(handle.id(), kInvalidThreadId);
const int nice_setting = internal::ThreadPriorityToNiceValue(priority);
- const PlatformThreadId current_id = PlatformThread::CurrentId();
- if (setpriority(PRIO_PROCESS, handle.id() == current_id ? 0 : handle.id(),
- nice_setting)) {
- DVPLOG(1) << "Failed to set nice value of thread (" << handle.id()
+ if (setpriority(PRIO_PROCESS, 0, nice_setting)) {
+ DVPLOG(1) << "Failed to set nice value of thread ("
+ << PlatformThread::CurrentHandle().id()
gab 2015/06/23 17:01:32 If I'm not mistaken this is the only use of Platfo
Takashi Toyoshima 2015/06/24 04:15:39 Thread::thread_id() still calls it, so it isn't as
<< ") to " << nice_setting;
}
#endif // defined(OS_NACL)
}
// static
-ThreadPriority PlatformThread::GetThreadPriority(PlatformThreadHandle handle) {
+ThreadPriority PlatformThread::GetCurrentThreadPriority() {
#if defined(OS_NACL)
NOTIMPLEMENTED();
return ThreadPriority::NORMAL;
#else
- // Mirrors SetThreadPriority()'s implementation.
+ // Mirrors SetCurrentThreadPriority()'s implementation.
ThreadPriority platform_specific_priority;
- if (internal::GetThreadPriorityForPlatform(handle,
- &platform_specific_priority)) {
+ if (internal::GetCurrentThreadPriorityForPlatform(
+ &platform_specific_priority)) {
return platform_specific_priority;
}
- DCHECK_NE(handle.id(), kInvalidThreadId);
- const PlatformThreadId current_id = PlatformThread::CurrentId();
// Need to clear errno before calling getpriority():
// http://man7.org/linux/man-pages/man2/getpriority.2.html
errno = 0;
- int nice_value =
- getpriority(PRIO_PROCESS, handle.id() == current_id ? 0 : handle.id());
+ int nice_value = getpriority(PRIO_PROCESS, 0);
if (errno != 0) {
- DVPLOG(1) << "Failed to get nice value of thread (" << handle.id() << ")";
+ DVPLOG(1) << "Failed to get nice value of thread ("
+ << PlatformThread::CurrentHandle().id()
+ << ")";
return ThreadPriority::NORMAL;
}

Powered by Google App Engine
This is Rietveld 408576698