Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: base/threading/platform_thread_android.cc

Issue 1193303002: base/threading: restrict to set only current thread priority (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review #48 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/threading/platform_thread.h ('k') | base/threading/platform_thread_freebsd.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
30 // - DISPLAY is -6 due to being midway between Android's DISPLAY (-4) and 30 // - DISPLAY is -6 due to being midway between Android's DISPLAY (-4) and
31 // URGENT_DISPLAY (-8). 31 // URGENT_DISPLAY (-8).
32 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value. 32 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value.
33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { 33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
34 {ThreadPriority::BACKGROUND, 9}, 34 {ThreadPriority::BACKGROUND, 9},
35 {ThreadPriority::NORMAL, 0}, 35 {ThreadPriority::NORMAL, 0},
36 {ThreadPriority::DISPLAY, -6}, 36 {ThreadPriority::DISPLAY, -6},
37 {ThreadPriority::REALTIME_AUDIO, -16}, 37 {ThreadPriority::REALTIME_AUDIO, -16},
38 }; 38 };
39 39
40 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, 40 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) {
41 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;
48 } 47 }
49 return false; 48 return false;
50 } 49 }
51 50
52 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, 51 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) {
53 ThreadPriority* priority) { 52 // See http://crbug.com/505474.
54 NOTIMPLEMENTED(); 53 NOTIMPLEMENTED();
55 return false; 54 return false;
56 } 55 }
57 56
58 } // namespace internal 57 } // namespace internal
59 58
60 void PlatformThread::SetName(const std::string& name) { 59 void PlatformThread::SetName(const std::string& name) {
61 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); 60 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
62 tracked_objects::ThreadData::InitializeThreadContext(name); 61 tracked_objects::ThreadData::InitializeThreadContext(name);
63 62
(...skipping 10 matching lines...) Expand all
74 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; 73 DPLOG(ERROR) << "prctl(PR_SET_NAME)";
75 } 74 }
76 75
77 76
78 void InitThreading() { 77 void InitThreading() {
79 } 78 }
80 79
81 void InitOnThread() { 80 void InitOnThread() {
82 // Threads on linux/android may inherit their priority from the thread 81 // Threads on linux/android may inherit their priority from the thread
83 // where they were created. This sets all new threads to the default. 82 // where they were created. This sets all new threads to the default.
84 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), 83 PlatformThread::SetCurrentThreadPriority(ThreadPriority::NORMAL);
85 ThreadPriority::NORMAL);
86 } 84 }
87 85
88 void TerminateOnThread() { 86 void TerminateOnThread() {
89 base::android::DetachFromVM(); 87 base::android::DetachFromVM();
90 } 88 }
91 89
92 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { 90 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
93 #if !defined(ADDRESS_SANITIZER) 91 #if !defined(ADDRESS_SANITIZER)
94 return 0; 92 return 0;
95 #else 93 #else
96 // AddressSanitizer bloats the stack approximately 2x. Default stack size of 94 // AddressSanitizer bloats the stack approximately 2x. Default stack size of
97 // 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).
98 return 2 * (1 << 20); // 2Mb 96 return 2 * (1 << 20); // 2Mb
99 #endif 97 #endif
100 } 98 }
101 99
102 bool RegisterThreadUtils(JNIEnv* env) { 100 bool RegisterThreadUtils(JNIEnv* env) {
103 return RegisterNativesImpl(env); 101 return RegisterNativesImpl(env);
104 } 102 }
105 103
106 } // namespace base 104 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread.h ('k') | base/threading/platform_thread_freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698