| 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 <sys/prctl.h> | 8 #include <sys/prctl.h> |
| 9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Process.THREAD_PRIORITY_DEFAULT = 0; | 30 // Process.THREAD_PRIORITY_DEFAULT = 0; |
| 31 // Process.THREAD_PRIORITY_DISPLAY = -4; | 31 // Process.THREAD_PRIORITY_DISPLAY = -4; |
| 32 // Process.THREAD_PRIORITY_FOREGROUND = -2; | 32 // Process.THREAD_PRIORITY_FOREGROUND = -2; |
| 33 // Process.THREAD_PRIORITY_LESS_FAVORABLE = 1; | 33 // Process.THREAD_PRIORITY_LESS_FAVORABLE = 1; |
| 34 // Process.THREAD_PRIORITY_LOWEST = 19; | 34 // Process.THREAD_PRIORITY_LOWEST = 19; |
| 35 // Process.THREAD_PRIORITY_MORE_FAVORABLE = -1; | 35 // Process.THREAD_PRIORITY_MORE_FAVORABLE = -1; |
| 36 // Process.THREAD_PRIORITY_URGENT_AUDIO = -19; | 36 // Process.THREAD_PRIORITY_URGENT_AUDIO = -19; |
| 37 // Process.THREAD_PRIORITY_URGENT_DISPLAY = -8; | 37 // Process.THREAD_PRIORITY_URGENT_DISPLAY = -8; |
| 38 // We use -6 for display, but we may want to split this into urgent (-8) and | 38 // We use -6 for display, but we may want to split this into urgent (-8) and |
| 39 // non-urgent (-4). | 39 // non-urgent (-4). |
| 40 |
| 40 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 41 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
| 41 {kThreadPriority_RealtimeAudio, -16}, | 42 {ThreadPriority::BACKGROUND, 10}, |
| 42 {kThreadPriority_Background, 10}, | 43 {ThreadPriority::NORMAL, 0}, |
| 43 {kThreadPriority_Normal, 0}, | 44 {ThreadPriority::DISPLAY, -6}, |
| 44 {kThreadPriority_Display, -6}, | 45 {ThreadPriority::REALTIMEAUDIO, -16}, |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, | 48 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, |
| 48 ThreadPriority priority) { | 49 ThreadPriority priority) { |
| 49 // On Android, we set the Audio priority through JNI as Audio priority | 50 // On Android, we set the Audio priority through JNI as Audio priority |
| 50 // will also allow the process to run while it is backgrounded. | 51 // will also allow the process to run while it is backgrounded. |
| 51 if (priority == kThreadPriority_RealtimeAudio) { | 52 if (priority == ThreadPriority::REALTIMEAUDIO) { |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); | 53 JNIEnv* env = base::android::AttachCurrentThread(); |
| 53 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); | 54 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); |
| 54 return true; | 55 return true; |
| 55 } | 56 } |
| 56 return false; | 57 return false; |
| 57 } | 58 } |
| 58 | 59 |
| 59 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, | 60 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, |
| 60 ThreadPriority* priority) { | 61 ThreadPriority* priority) { |
| 61 NOTIMPLEMENTED(); | 62 NOTIMPLEMENTED(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 } | 83 } |
| 83 | 84 |
| 84 | 85 |
| 85 void InitThreading() { | 86 void InitThreading() { |
| 86 } | 87 } |
| 87 | 88 |
| 88 void InitOnThread() { | 89 void InitOnThread() { |
| 89 // Threads on linux/android may inherit their priority from the thread | 90 // Threads on linux/android may inherit their priority from the thread |
| 90 // where they were created. This sets all new threads to the default. | 91 // where they were created. This sets all new threads to the default. |
| 91 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), | 92 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), |
| 92 kThreadPriority_Normal); | 93 ThreadPriority::NORMAL); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void TerminateOnThread() { | 96 void TerminateOnThread() { |
| 96 base::android::DetachFromVM(); | 97 base::android::DetachFromVM(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 100 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
| 100 #if !defined(ADDRESS_SANITIZER) | 101 #if !defined(ADDRESS_SANITIZER) |
| 101 return 0; | 102 return 0; |
| 102 #else | 103 #else |
| 103 // AddressSanitizer bloats the stack approximately 2x. Default stack size of | 104 // AddressSanitizer bloats the stack approximately 2x. Default stack size of |
| 104 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). | 105 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). |
| 105 return 2 * (1 << 20); // 2Mb | 106 return 2 * (1 << 20); // 2Mb |
| 106 #endif | 107 #endif |
| 107 } | 108 } |
| 108 | 109 |
| 109 bool RegisterThreadUtils(JNIEnv* env) { | 110 bool RegisterThreadUtils(JNIEnv* env) { |
| 110 return RegisterNativesImpl(env); | 111 return RegisterNativesImpl(env); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace base | 114 } // namespace base |
| OLD | NEW |