| 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 26 matching lines...) Expand all Loading... |
| 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 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 40 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
| 41 {ThreadPriority::BACKGROUND, 10}, | 41 {ThreadPriority::BACKGROUND, 10}, |
| 42 {ThreadPriority::NORMAL, 0}, | 42 {ThreadPriority::NORMAL, 0}, |
| 43 {ThreadPriority::DISPLAY, -6}, | 43 {ThreadPriority::DISPLAY, -6}, |
| 44 {ThreadPriority::REALTIME_AUDIO, -16}, | 44 {ThreadPriority::REALTIME_AUDIO, -16}, |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, | 47 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
| 48 ThreadPriority priority) { | |
| 49 // On Android, we set the Audio priority through JNI as Audio priority | 48 // On Android, we set the Audio priority through JNI as Audio priority |
| 50 // will also allow the process to run while it is backgrounded. | 49 // will also allow the process to run while it is backgrounded. |
| 51 if (priority == ThreadPriority::REALTIME_AUDIO) { | 50 if (priority == ThreadPriority::REALTIME_AUDIO) { |
| 52 JNIEnv* env = base::android::AttachCurrentThread(); | 51 JNIEnv* env = base::android::AttachCurrentThread(); |
| 53 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); | 52 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); |
| 54 return true; | 53 return true; |
| 55 } | 54 } |
| 56 return false; | 55 return false; |
| 57 } | 56 } |
| 58 | 57 |
| 59 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, | 58 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { |
| 60 ThreadPriority* priority) { | |
| 61 NOTIMPLEMENTED(); | 59 NOTIMPLEMENTED(); |
| 62 return false; | 60 return false; |
| 63 } | 61 } |
| 64 | 62 |
| 65 } // namespace internal | 63 } // namespace internal |
| 66 | 64 |
| 67 void PlatformThread::SetName(const std::string& name) { | 65 void PlatformThread::SetName(const std::string& name) { |
| 68 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 66 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
| 69 tracked_objects::ThreadData::InitializeThreadContext(name); | 67 tracked_objects::ThreadData::InitializeThreadContext(name); |
| 70 | 68 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; | 79 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
| 82 } | 80 } |
| 83 | 81 |
| 84 | 82 |
| 85 void InitThreading() { | 83 void InitThreading() { |
| 86 } | 84 } |
| 87 | 85 |
| 88 void InitOnThread() { | 86 void InitOnThread() { |
| 89 // Threads on linux/android may inherit their priority from the thread | 87 // Threads on linux/android may inherit their priority from the thread |
| 90 // where they were created. This sets all new threads to the default. | 88 // where they were created. This sets all new threads to the default. |
| 91 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), | 89 PlatformThread::SetCurrentThreadPriority(ThreadPriority::NORMAL); |
| 92 ThreadPriority::NORMAL); | |
| 93 } | 90 } |
| 94 | 91 |
| 95 void TerminateOnThread() { | 92 void TerminateOnThread() { |
| 96 base::android::DetachFromVM(); | 93 base::android::DetachFromVM(); |
| 97 } | 94 } |
| 98 | 95 |
| 99 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 96 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
| 100 #if !defined(ADDRESS_SANITIZER) | 97 #if !defined(ADDRESS_SANITIZER) |
| 101 return 0; | 98 return 0; |
| 102 #else | 99 #else |
| 103 // AddressSanitizer bloats the stack approximately 2x. Default stack size of | 100 // 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). | 101 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). |
| 105 return 2 * (1 << 20); // 2Mb | 102 return 2 * (1 << 20); // 2Mb |
| 106 #endif | 103 #endif |
| 107 } | 104 } |
| 108 | 105 |
| 109 bool RegisterThreadUtils(JNIEnv* env) { | 106 bool RegisterThreadUtils(JNIEnv* env) { |
| 110 return RegisterNativesImpl(env); | 107 return RegisterNativesImpl(env); |
| 111 } | 108 } |
| 112 | 109 |
| 113 } // namespace base | 110 } // namespace base |
| OLD | NEW |