| 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 29 matching lines...) Expand all Loading... |
| 40 // 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 |
| 41 // will also allow the process to run while it is backgrounded. | 41 // will also allow the process to run while it is backgrounded. |
| 42 if (priority == ThreadPriority::REALTIME_AUDIO) { | 42 if (priority == ThreadPriority::REALTIME_AUDIO) { |
| 43 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
| 44 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); | 44 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SetThreadPriority(PlatformThreadId tid, ThreadPriority priority) { |
| 51 if (priority == ThreadPriority::BACKGROUND) { |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); |
| 53 Java_ThreadUtils_setThreadPriorityBackground(env, tid); |
| 54 return true; |
| 55 } else if (priority == ThreadPriority::NORMAL) { |
| 56 JNIEnv* env = base::android::AttachCurrentThread(); |
| 57 Java_ThreadUtils_setThreadPriorityNormal(env, tid); |
| 58 return true; |
| 59 } |
| 60 return false; |
| 61 } |
| 62 |
| 50 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { | 63 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { |
| 51 DCHECK(priority); | 64 DCHECK(priority); |
| 52 *priority = ThreadPriority::NORMAL; | 65 *priority = ThreadPriority::NORMAL; |
| 53 JNIEnv* env = base::android::AttachCurrentThread(); | 66 JNIEnv* env = base::android::AttachCurrentThread(); |
| 54 if (Java_ThreadUtils_isThreadPriorityAudio( | 67 if (Java_ThreadUtils_isThreadPriorityAudio( |
| 55 env, PlatformThread::CurrentId())) { | 68 env, PlatformThread::CurrentId())) { |
| 56 *priority = ThreadPriority::REALTIME_AUDIO; | 69 *priority = ThreadPriority::REALTIME_AUDIO; |
| 57 return true; | 70 return true; |
| 71 } else if (Java_ThreadUtils_isThreadPriorityNormal( |
| 72 env, PlatformThread::CurrentId())) { |
| 73 *priority = ThreadPriority::NORMAL; |
| 74 return true; |
| 75 } else if (Java_ThreadUtils_isThreadPriorityBackground( |
| 76 env, PlatformThread::CurrentId())) { |
| 77 *priority = ThreadPriority::BACKGROUND; |
| 78 return true; |
| 58 } | 79 } |
| 59 return false; | 80 return false; |
| 60 } | 81 } |
| 61 | 82 |
| 62 } // namespace internal | 83 } // namespace internal |
| 63 | 84 |
| 64 void PlatformThread::SetName(const std::string& name) { | 85 void PlatformThread::SetName(const std::string& name) { |
| 65 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 86 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
| 66 tracked_objects::ThreadData::InitializeThreadContext(name); | 87 tracked_objects::ThreadData::InitializeThreadContext(name); |
| 67 | 88 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 94 // 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). |
| 95 return 2 * (1 << 20); // 2Mb | 116 return 2 * (1 << 20); // 2Mb |
| 96 #endif | 117 #endif |
| 97 } | 118 } |
| 98 | 119 |
| 99 bool RegisterThreadUtils(JNIEnv* env) { | 120 bool RegisterThreadUtils(JNIEnv* env) { |
| 100 return RegisterNativesImpl(env); | 121 return RegisterNativesImpl(env); |
| 101 } | 122 } |
| 102 | 123 |
| 103 } // namespace base | 124 } // namespace base |
| OLD | NEW |