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

Unified Diff: base/threading/platform_thread_linux.cc

Issue 1015503002: Deduplicate PlatformThread's POSIX implementations of SetThreadPriority. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@background_threads
Patch Set: tweak comment 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
« no previous file with comments | « base/threading/platform_thread_internal_posix.cc ('k') | base/threading/platform_thread_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_linux.cc
diff --git a/base/threading/platform_thread_linux.cc b/base/threading/platform_thread_linux.cc
index d97a3f4db5086171f28babda4e18d1f4303ff7ba..623a3dee678352aaf8a61b402c431a1727aa2fd9 100644
--- a/base/threading/platform_thread_linux.cc
+++ b/base/threading/platform_thread_linux.cc
@@ -9,43 +9,45 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/safe_strerror_posix.h"
+#include "base/threading/platform_thread_internal_posix.h"
#include "base/threading/thread_id_name_manager.h"
-#include "base/threading/thread_restrictions.h"
#include "base/tracked_objects.h"
#if !defined(OS_NACL)
+#include <pthread.h>
#include <sys/prctl.h>
-#include <sys/resource.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
+#include <sys/types.h>
#include <unistd.h>
#endif
namespace base {
+namespace internal {
+
namespace {
+#if !defined(OS_NACL)
+const struct sched_param kRealTimePrio = {8};
+#endif
+} // namespace
+const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
+ {kThreadPriority_RealtimeAudio, -10},
+ {kThreadPriority_Background, 10},
+ {kThreadPriority_Normal, 0},
+ {kThreadPriority_Display, -6},
+};
+
+bool HandleSetThreadPriorityForPlatform(PlatformThreadHandle handle,
+ ThreadPriority priority) {
#if !defined(OS_NACL)
-int ThreadNiceValue(ThreadPriority priority) {
- switch (priority) {
- case kThreadPriority_RealtimeAudio:
- return -10;
- case kThreadPriority_Background:
- return 10;
- case kThreadPriority_Normal:
- return 0;
- case kThreadPriority_Display:
- return -6;
- default:
- NOTREACHED() << "Unknown priority.";
- return 0;
- }
+ return priority == kThreadPriority_RealtimeAudio &&
+ pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0;
+#else
+ return false;
+#endif
}
-#endif // !defined(OS_NACL)
-} // namespace
+} // namespace internal
// static
void PlatformThread::SetName(const char* name) {
@@ -72,36 +74,6 @@ void PlatformThread::SetName(const char* name) {
#endif // !defined(OS_NACL)
}
-// static
-void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
- ThreadPriority priority) {
-#if !defined(OS_NACL)
- if (priority == kThreadPriority_RealtimeAudio) {
- const struct sched_param kRealTimePrio = {8};
- if (pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0) {
- // Got real time priority, no need to set nice level.
- return;
- }
- }
-
- // setpriority(2) should change the whole thread group's (i.e. process)
- // priority. however, on linux it will only change the target thread's
- // priority. see the bugs section in
- // http://man7.org/linux/man-pages/man2/getpriority.2.html.
- // we prefer using 0 rather than the current thread id since they are
- // equivalent but it makes sandboxing easier (https://crbug.com/399473).
- DCHECK_NE(handle.id_, kInvalidThreadId);
- const int kNiceSetting = ThreadNiceValue(priority);
- const PlatformThreadId current_id = PlatformThread::CurrentId();
- if (setpriority(PRIO_PROCESS,
- handle.id_ == current_id ? 0 : handle.id_,
- kNiceSetting)) {
- DVPLOG(1) << "Failed to set nice value of thread (" << handle.id_ << ") to "
- << kNiceSetting;
- }
-#endif // !defined(OS_NACL)
-}
-
void InitThreading() {}
void InitOnThread() {}
« no previous file with comments | « base/threading/platform_thread_internal_posix.cc ('k') | base/threading/platform_thread_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698