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 <stddef.h> | 8 #include <stddef.h> |
9 #include <sys/prctl.h> | 9 #include <sys/prctl.h> |
10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "jni/ThreadUtils_jni.h" | 21 #include "jni/ThreadUtils_jni.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 | 24 |
25 namespace internal { | 25 namespace internal { |
26 | 26 |
27 // - BACKGROUND is 9 due to it being the nicest value we can use that's still | 27 // - BACKGROUND is 9 due to it being the nicest value we can use that's still |
28 // above an Android system threshold that enables heavy throttling starting at | 28 // above an Android system threshold that enables heavy throttling starting at |
29 // 10; we want to be lower-priority than Chrome's other threads without | 29 // 10; we want to be lower-priority than Chrome's other threads without |
30 // incurring this behavior. | 30 // incurring this behavior. |
31 // - DISPLAY is -6 due to being midway between Android's DISPLAY (-4) and | 31 // - DISPLAY corresponds to Android's PRIORITY_DISPLAY = -4 value. |
32 // URGENT_DISPLAY (-8). | |
33 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value. | 32 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value. |
34 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
35 {ThreadPriority::BACKGROUND, 9}, | 34 {ThreadPriority::BACKGROUND, 9}, |
36 {ThreadPriority::NORMAL, 0}, | 35 {ThreadPriority::NORMAL, 0}, |
37 {ThreadPriority::DISPLAY, -6}, | 36 {ThreadPriority::DISPLAY, -4}, |
38 {ThreadPriority::REALTIME_AUDIO, -16}, | 37 {ThreadPriority::REALTIME_AUDIO, -16}, |
39 }; | 38 }; |
40 | 39 |
41 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { | 40 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
42 // On Android, we set the Audio priority through JNI as Audio priority | 41 // On Android, we set the Audio priority through JNI as Audio priority |
43 // will also allow the process to run while it is backgrounded. | 42 // will also allow the process to run while it is backgrounded. |
44 if (priority == ThreadPriority::REALTIME_AUDIO) { | 43 if (priority == ThreadPriority::REALTIME_AUDIO) { |
45 JNIEnv* env = base::android::AttachCurrentThread(); | 44 JNIEnv* env = base::android::AttachCurrentThread(); |
46 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); | 45 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); |
47 return true; | 46 return true; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). | 95 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). |
97 return 2 * (1 << 20); // 2Mb | 96 return 2 * (1 << 20); // 2Mb |
98 #endif | 97 #endif |
99 } | 98 } |
100 | 99 |
101 bool RegisterThreadUtils(JNIEnv* env) { | 100 bool RegisterThreadUtils(JNIEnv* env) { |
102 return RegisterNativesImpl(env); | 101 return RegisterNativesImpl(env); |
103 } | 102 } |
104 | 103 |
105 } // namespace base | 104 } // namespace base |
OLD | NEW |