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

Unified Diff: base/threading/platform_thread_posix.cc

Issue 1006933003: Add full SetThreadPriority support to Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 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..7b20b854e6c277c287ea7defa42274041243460a 100644
--- a/base/threading/platform_thread_posix.cc
+++ b/base/threading/platform_thread_posix.cc
@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/safe_strerror_posix.h"
+#include "base/scoped_clear_errno.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread_internal_posix.h"
#include "base/threading/thread_id_name_manager.h"
@@ -232,12 +233,15 @@ 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 defined(OS_NACL)
+ NOTIMPLEMENTED();
+#else
if (internal::HandleSetThreadPriorityForPlatform(handle, priority))
return;
@@ -255,8 +259,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 kThreadPriority_Normal;
+#else
+ // Mirrors SetThreadPriority()'s implementation.
+ ThreadPriority platform_specific_priority;
+ if (internal::HandleGetThreadPriorityForPlatform(
+ 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
+ ScopedClearErrno clear_errno;
rvargas (doing something else) 2015/03/19 22:19:21 errno = 0 instead?
gab 2015/03/30 20:14:45 I don't know much about Chromium POSIX development
rvargas (doing something else) 2015/03/30 22:31:22 There is no contract on base to preserve errno (or
gab 2015/03/31 14:02:33 Done.
+ 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 kThreadPriority_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