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

Unified Diff: base/threading/platform_thread_android.cc

Issue 434803003: Linux, Android: fix call to setpriority(2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only substitute the thread id with 0 when appropriate. Created 6 years, 5 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 | « no previous file | base/threading/platform_thread_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_android.cc
diff --git a/base/threading/platform_thread_android.cc b/base/threading/platform_thread_android.cc
index bd0b4b33db74a137fa1dd0508f39586362857d5a..f8395e592215f5feec82b51f98c523ef8c02d999 100644
--- a/base/threading/platform_thread_android.cc
+++ b/base/threading/platform_thread_android.cc
@@ -65,14 +65,20 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
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.
+ // 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);
int kNiceSetting = ThreadNiceValue(priority);
- if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting))
+ const PlatformThreadId current_id = PlatformThread::CurrentId();
+ if (setpriority(PRIO_PROCESS,
+ handle.id_ == current_id ? 0 : handle.id_,
+ kNiceSetting)) {
LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting;
+ }
}
void PlatformThread::SetName(const char* name) {
« no previous file with comments | « no previous file | base/threading/platform_thread_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698