Index: base/threading/platform_thread_posix.cc |
diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc |
index 5c5023b1c27a996b2b4c617653d7bbefd57ca904..3dbdc9808752c2b1411aa516fcf5b8bf328fa88c 100644 |
--- a/base/threading/platform_thread_posix.cc |
+++ b/base/threading/platform_thread_posix.cc |
@@ -39,7 +39,7 @@ struct ThreadParams { |
ThreadParams() |
: delegate(NULL), |
joinable(false), |
- priority(kThreadPriority_Normal), |
+ priority(ThreadPriority::NORMAL), |
handle(NULL), |
handle_set(false, false) { |
} |
@@ -59,7 +59,7 @@ void* ThreadFunc(void* params) { |
if (!thread_params->joinable) |
base::ThreadRestrictions::SetSingletonAllowed(false); |
- if (thread_params->priority != kThreadPriority_Normal) { |
+ if (thread_params->priority != ThreadPriority::NORMAL) { |
PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), |
thread_params->priority); |
} |
@@ -201,7 +201,7 @@ bool PlatformThread::Create(size_t stack_size, Delegate* delegate, |
PlatformThreadHandle* thread_handle) { |
base::ThreadRestrictions::ScopedAllowWait allow_wait; |
return CreateThread(stack_size, true /* joinable thread */, |
- delegate, thread_handle, kThreadPriority_Normal); |
+ delegate, thread_handle, ThreadPriority::NORMAL); |
} |
// static |
@@ -219,7 +219,7 @@ bool PlatformThread::CreateNonJoinable(size_t stack_size, Delegate* delegate) { |
base::ThreadRestrictions::ScopedAllowWait allow_wait; |
bool result = CreateThread(stack_size, false /* non-joinable thread */, |
- delegate, &unused, kThreadPriority_Normal); |
+ delegate, &unused, ThreadPriority::NORMAL); |
return result; |
} |
@@ -232,13 +232,16 @@ void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL)); |
} |
-// Mac has its own SetThreadPriority() implementation. |
+// Mac has its own Set/GetThreadPriority() implementations. |
#if !defined(OS_MACOSX) |
+ |
// static |
void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, |
ThreadPriority priority) { |
-#if !defined(OS_NACL) |
- if (internal::HandleSetThreadPriorityForPlatform(handle, priority)) |
+#if defined(OS_NACL) |
+ NOTIMPLEMENTED(); |
+#else |
+ if (internal::SetThreadPriorityForPlatform(handle, priority)) |
return; |
// setpriority(2) should change the whole thread group's (i.e. process) |
@@ -255,8 +258,38 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, |
DVPLOG(1) << "Failed to set nice value of thread (" << handle.id_ << ") to " |
<< nice_setting; |
} |
+#endif // defined(OS_NACL) |
+} |
+ |
+// static |
+ThreadPriority PlatformThread::GetThreadPriority(PlatformThreadHandle handle) { |
+#if defined(OS_NACL) |
+ NOTIMPLEMENTED(); |
+ return ThreadPriority::NORMAL; |
+#else |
+ // Mirrors SetThreadPriority()'s implementation. |
+ ThreadPriority platform_specific_priority; |
+ if (internal::GetThreadPriorityForPlatform(handle, |
+ &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_); |
+ if (errno != 0) { |
+ DVPLOG(1) << "Failed to get nice value of thread (" << handle.id_ << ")"; |
+ return ThreadPriority::NORMAL; |
+ } |
+ |
+ return internal::NiceValueToThreadPriority(nice_value); |
#endif // !defined(OS_NACL) |
} |
+ |
#endif // !defined(OS_MACOSX) |
} // namespace base |