OLD | NEW |
---|---|
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 <sched.h> | 8 #include <sched.h> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 #endif | 41 #endif |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 struct ThreadParams { | 45 struct ThreadParams { |
46 PlatformThread::Delegate* delegate; | 46 PlatformThread::Delegate* delegate; |
47 bool joinable; | 47 bool joinable; |
48 ThreadPriority priority; | 48 ThreadPriority priority; |
49 }; | 49 }; |
50 | 50 |
51 #if defined(OS_LINUX) | |
52 static int SetCurrentThreadRealTime() { | |
53 const int kRealTimePrio = 8; | |
54 | |
55 struct sched_param sched_param; | |
56 memset(&sched_param, 0, sizeof(sched_param)); | |
57 sched_param.sched_priority = kRealTimePrio; | |
58 | |
59 return pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param); | |
60 } | |
61 #endif | |
62 | |
51 void SetCurrentThreadPriority(ThreadPriority priority) { | 63 void SetCurrentThreadPriority(ThreadPriority priority) { |
52 #if defined(OS_LINUX) || defined(OS_ANDROID) | 64 #if defined(OS_LINUX) || defined(OS_ANDROID) |
53 switch (priority) { | 65 switch (priority) { |
54 case kThreadPriority_Normal: | 66 case kThreadPriority_Normal: |
55 NOTREACHED() << "Don't reset priority as not all processes can."; | 67 NOTREACHED() << "Don't reset priority as not all processes can."; |
56 break; | 68 break; |
57 case kThreadPriority_RealtimeAudio: | 69 case kThreadPriority_RealtimeAudio: |
58 #if defined(OS_LINUX) | 70 #if defined(OS_LINUX) |
DaveMoore
2013/05/23 17:20:16
If we're doing something different on OS_CHROMEOS
dgreid
2013/05/23 17:24:47
This change stops switching the niceness of the th
DaveMoore
2013/05/23 18:21:12
Then I think we should explicitly avoid ever setti
dgreid
2013/05/23 18:36:28
We still want to set the nice level if it is posit
DaveMoore
2013/05/23 20:16:31
It's at best misleading, and at worst will lead to
dgreid
2013/05/23 20:37:49
Thanks Dave,
Not sure about the consequences of t
| |
71 if (SetCurrentThreadRealTime() == 0) | |
72 // Got real time priority. | |
73 return; | |
74 | |
75 // Otherwise try to set an advantageous nice level. | |
59 const int kNiceSetting = -10; | 76 const int kNiceSetting = -10; |
60 // Linux isn't posix compliant with setpriority(2), it will set a thread | 77 // Linux isn't posix compliant with setpriority(2), it will set a thread |
61 // priority if it is passed a tid, not affecting the rest of the threads | 78 // priority if it is passed a tid, not affecting the rest of the threads |
62 // in the process. Setting this priority will only succeed if the user | 79 // in the process. Setting this priority will only succeed if the user |
63 // has been granted permission to adjust nice values on the system. | 80 // has been granted permission to adjust nice values on the system. |
64 if (setpriority(PRIO_PROCESS, PlatformThread::CurrentId(), kNiceSetting)) | 81 if (setpriority(PRIO_PROCESS, PlatformThread::CurrentId(), kNiceSetting)) |
65 DVLOG(1) << "Failed to set nice value of thread to " << kNiceSetting; | 82 DVLOG(1) << "Failed to set nice value of thread to " << kNiceSetting; |
66 #elif defined(OS_ANDROID) | 83 #elif defined(OS_ANDROID) |
67 JNIEnv* env = base::android::AttachCurrentThread(); | 84 JNIEnv* env = base::android::AttachCurrentThread(); |
68 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); | 85 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 } | 312 } |
296 #endif | 313 #endif |
297 | 314 |
298 #if defined(OS_ANDROID) | 315 #if defined(OS_ANDROID) |
299 bool RegisterThreadUtils(JNIEnv* env) { | 316 bool RegisterThreadUtils(JNIEnv* env) { |
300 return RegisterNativesImpl(env); | 317 return RegisterNativesImpl(env); |
301 } | 318 } |
302 #endif // defined(OS_ANDROID) | 319 #endif // defined(OS_ANDROID) |
303 | 320 |
304 } // namespace base | 321 } // namespace base |
OLD | NEW |