Index: base/threading/platform_thread_posix.cc |
diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc |
index 42b416d4a38fa1727d2e7043fd3ccd9a3e9e1a7e..9a55760a4c069812665b9b65018147c3ac45ed11 100644 |
--- a/base/threading/platform_thread_posix.cc |
+++ b/base/threading/platform_thread_posix.cc |
@@ -5,28 +5,25 @@ |
#include "base/threading/platform_thread.h" |
#include <errno.h> |
+#include <pthread.h> |
#include <sched.h> |
+#include <sys/resource.h> |
+#include <sys/time.h> |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/safe_strerror_posix.h" |
#include "base/synchronization/waitable_event.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_MACOSX) |
-#include <sys/resource.h> |
-#include <algorithm> |
-#endif |
- |
#if defined(OS_LINUX) |
-#include <sys/prctl.h> |
-#include <sys/resource.h> |
#include <sys/syscall.h> |
-#include <sys/time.h> |
-#include <unistd.h> |
+#elif defined(OS_ANDROID) |
+#include <sys/types.h> |
#endif |
namespace base { |
@@ -235,4 +232,31 @@ void PlatformThread::Join(PlatformThreadHandle thread_handle) { |
CHECK_EQ(0, pthread_join(thread_handle.handle_, NULL)); |
} |
+// Mac has its own SetThreadPriority() implementation. |
+#if !defined(OS_MACOSX) |
+// static |
+void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, |
+ ThreadPriority priority) { |
+#if !defined(OS_NACL) |
+ if (internal::HandleSetThreadPriorityForPlatform(handle, priority)) |
+ return; |
+ |
+ // setpriority(2) should change the whole thread group's (i.e. process) |
+ // priority. However, under the current Linux/NPTL implementation of POSIX |
rvargas (doing something else)
2015/03/17 22:15:21
tiny nit: Remove the Linux part?
gab
2015/03/18 19:01:06
This was copy-pasted verbatim from http://linux.di
rvargas (doing something else)
2015/03/18 22:54:23
Yes, and that's what the comment said on the _linu
gab
2015/03/19 15:32:50
Fair enough, tweaked comment.
|
+ // threads, the nice value is a per-thread attribute. 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 |
rvargas (doing something else)
2015/03/17 22:15:22
is using 0 also equivalent on bsd? just checking
gab
2015/03/18 19:01:06
I asssume so, the only reason the current implemen
rvargas (doing something else)
2015/03/18 22:54:23
Acknowledged.
|
+ // sandboxing easier (https://crbug.com/399473). |
+ DCHECK_NE(handle.id_, kInvalidThreadId); |
+ const int nice_setting = internal::ThreadPriorityToNiceValue(priority); |
rvargas (doing something else)
2015/03/17 22:15:21
nit: either remove const (preferred) or name the v
gab
2015/03/18 19:01:06
If by "name the variables as constant" you mean kN
rvargas (doing something else)
2015/03/18 22:54:23
ok, up to you.
That's kind of a pet peeve of mine
|
+ const PlatformThreadId current_id = PlatformThread::CurrentId(); |
+ if (setpriority(PRIO_PROCESS, handle.id_ == current_id ? 0 : handle.id_, |
+ nice_setting)) { |
+ DVPLOG(1) << "Failed to set nice value of thread (" << handle.id_ << ") to " |
+ << nice_setting; |
+ } |
+#endif // !defined(OS_NACL) |
+} |
+#endif // !defined(OS_MACOSX) |
+ |
} // namespace base |