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> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 | 13 |
14 #include "base/android/jni_android.h" | 14 #include "base/android/jni_android.h" |
15 #include "base/android/thread_utils.h" | 15 #include "base/android/thread_utils.h" |
16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/threading/platform_thread_internal_posix.h" | 18 #include "base/threading/platform_thread_internal_posix.h" |
19 #include "base/threading/thread_id_name_manager.h" | 19 #include "base/threading/thread_id_name_manager.h" |
20 #include "base/tracked_objects.h" | 20 #include "base/tracked_objects.h" |
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 corresponds to Android's PRIORITY_BACKGROUND = 10 value and can |
aelias_OOO_until_Jul13
2016/02/23 23:01:40
Could you write in the comment here that this prio
reveman
2016/02/24 17:08:54
Done.
| |
28 // above an Android system threshold that enables heavy throttling starting at | 28 // result in heavy throttling. |
29 // 10; we want to be lower-priority than Chrome's other threads without | |
30 // incurring this behavior. | |
31 // - DISPLAY is -6 due to being midway between Android's DISPLAY (-4) and | 29 // - DISPLAY is -6 due to being midway between Android's DISPLAY (-4) and |
32 // URGENT_DISPLAY (-8). | 30 // URGENT_DISPLAY (-8). |
33 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value. | 31 // - REALTIME_AUDIO corresponds to Android's PRIORITY_AUDIO = -16 value. |
34 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 32 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
35 {ThreadPriority::BACKGROUND, 9}, | 33 {ThreadPriority::BACKGROUND, 10}, |
36 {ThreadPriority::NORMAL, 0}, | 34 {ThreadPriority::NORMAL, 0}, |
37 {ThreadPriority::DISPLAY, -6}, | 35 {ThreadPriority::DISPLAY, -6}, |
38 {ThreadPriority::REALTIME_AUDIO, -16}, | 36 {ThreadPriority::REALTIME_AUDIO, -16}, |
39 }; | 37 }; |
40 | 38 |
41 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { | 39 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
42 // On Android, we set the Audio priority through JNI as Audio priority | 40 // On Android, we set the Audio priority through JNI as Audio priority |
43 // will also allow the process to run while it is backgrounded. | 41 // will also allow the process to run while it is backgrounded. |
44 if (priority == ThreadPriority::REALTIME_AUDIO) { | 42 if (priority == ThreadPriority::REALTIME_AUDIO) { |
45 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
(...skipping 50 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). | 94 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). |
97 return 2 * (1 << 20); // 2Mb | 95 return 2 * (1 << 20); // 2Mb |
98 #endif | 96 #endif |
99 } | 97 } |
100 | 98 |
101 bool RegisterThreadUtils(JNIEnv* env) { | 99 bool RegisterThreadUtils(JNIEnv* env) { |
102 return RegisterNativesImpl(env); | 100 return RegisterNativesImpl(env); |
103 } | 101 } |
104 | 102 |
105 } // namespace base | 103 } // namespace base |
OLD | NEW |