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

Side by Side 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: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/threading/platform_thread_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/platform_thread.h" 5 #include "base/threading/platform_thread.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/prctl.h> 8 #include <sys/prctl.h>
9 #include <sys/resource.h> 9 #include <sys/resource.h>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, 58 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
59 ThreadPriority priority) { 59 ThreadPriority priority) {
60 // On Android, we set the Audio priority through JNI as Audio priority 60 // On Android, we set the Audio priority through JNI as Audio priority
61 // will also allow the process to run while it is backgrounded. 61 // will also allow the process to run while it is backgrounded.
62 if (priority == kThreadPriority_RealtimeAudio) { 62 if (priority == kThreadPriority_RealtimeAudio) {
63 JNIEnv* env = base::android::AttachCurrentThread(); 63 JNIEnv* env = base::android::AttachCurrentThread();
64 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); 64 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId());
65 return; 65 return;
66 } 66 }
67 67
68 // setpriority(2) will set a thread's priority if it is passed a tid as 68 // setpriority(2) should change the whole thread group's (i.e. process)
69 // the 'process identifier', not affecting the rest of the threads in the 69 // priority. However, on Linux it will only change the current thread. See
70 // process. Setting this priority will only succeed if the user has been 70 // the BUGs section in
71 // granted permission to adjust nice values on the system. 71 // http://man7.org/linux/man-pages/man2/getpriority.2.html.
72 DCHECK_NE(handle.id_, kInvalidThreadId); 72 DCHECK_NE(handle.id_, kInvalidThreadId);
73 int kNiceSetting = ThreadNiceValue(priority); 73 int kNiceSetting = ThreadNiceValue(priority);
74 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) 74 if (setpriority(PRIO_PROCESS, 0, kNiceSetting))
mdempsky 2014/08/01 00:05:32 Can SetThreadPriority() be called by a different t
jln (very slow on Chromium) 2014/08/01 00:39:53 Ooch. I was a little hasty on this one indeed, tha
75 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; 75 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting;
76 } 76 }
77 77
78 void PlatformThread::SetName(const char* name) { 78 void PlatformThread::SetName(const char* name) {
79 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); 79 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
80 tracked_objects::ThreadData::InitializeThreadContext(name); 80 tracked_objects::ThreadData::InitializeThreadContext(name);
81 81
82 // Like linux, on android we can get the thread names to show up in the 82 // Like linux, on android we can get the thread names to show up in the
83 // debugger by setting the process name for the LWP. 83 // debugger by setting the process name for the LWP.
84 // We don't want to do this for the main thread because that would rename 84 // We don't want to do this for the main thread because that would rename
(...skipping 30 matching lines...) Expand all
115 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). 115 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example).
116 return 2 * (1 << 20); // 2Mb 116 return 2 * (1 << 20); // 2Mb
117 #endif 117 #endif
118 } 118 }
119 119
120 bool RegisterThreadUtils(JNIEnv* env) { 120 bool RegisterThreadUtils(JNIEnv* env) {
121 return RegisterNativesImpl(env); 121 return RegisterNativesImpl(env);
122 } 122 }
123 123
124 } // namespace base 124 } // namespace base
OLDNEW
« 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