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

Unified Diff: base/threading/platform_thread_freebsd.cc

Issue 1015503002: Deduplicate PlatformThread's POSIX implementations of SetThreadPriority. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@background_threads
Patch Set: more fixes 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_freebsd.cc
diff --git a/base/threading/platform_thread_freebsd.cc b/base/threading/platform_thread_freebsd.cc
index 7a24f4e055e86eba048271796f88ce5235e0d7b8..dca39eb312cb4f4a6b54803b95a3712eb57f2066 100644
--- a/base/threading/platform_thread_freebsd.cc
+++ b/base/threading/platform_thread_freebsd.cc
@@ -9,39 +9,43 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/safe_strerror_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 <sys/resource.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
+#include <pthread.h>
+#include <sys/prctl.h>
#include <sys/types.h>
#include <unistd.h>
#endif
namespace base {
+namespace internal {
+
namespace {
-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;
- }
+const struct sched_param kRealTimePrio = {8};
rvargas (doing something else) 2015/03/17 22:15:21 nit: { 8 }
gab 2015/03/18 19:01:05 As mentioned in another comment, this is the outpu
+} // 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)
+ // Handle real time priority the Linux way if possible.
rvargas (doing something else) 2015/03/17 22:15:21 nit: This comment sounds weird. Why is pthread_set
gab 2015/03/18 19:01:05 Removed comment, was trying to justify it somehow,
+ return priority == kThreadPriority_RealtimeAudio &&
+ pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio);
+#else
+ return false;
+#endif
}
-} // namespace
+
+} // namespace internal
// static
void PlatformThread::SetName(const char* name) {
@@ -59,31 +63,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) will set a thread's priority if it is passed a tid as
- // the 'process identifier', not affecting the rest of the threads in the
- // process. Setting this priority will only succeed if the user has been
- // granted permission to adjust nice values on the system.
- DCHECK_NE(handle.id_, kInvalidThreadId);
- const int kNiceSetting = ThreadNiceValue(priority);
- if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) {
- DVPLOG(1) << "Failed to set nice value of thread ("
- << handle.id_ << ") to " << kNiceSetting;
- }
-#endif // !defined(OS_NACL)
-}
-
void InitThreading() {}
void InitOnThread() {}

Powered by Google App Engine
This is Rietveld 408576698