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

Unified Diff: base/threading/platform_thread_posix.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 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 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

Powered by Google App Engine
This is Rietveld 408576698