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

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

Issue 1739993004: content: Implement dynamic priorities for raster threads. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: preparing for checkin. Created 4 years, 9 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
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 <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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { 50 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) {
51 DCHECK(priority); 51 DCHECK(priority);
52 *priority = ThreadPriority::NORMAL; 52 *priority = ThreadPriority::NORMAL;
53 JNIEnv* env = base::android::AttachCurrentThread(); 53 JNIEnv* env = base::android::AttachCurrentThread();
54 if (Java_ThreadUtils_isThreadPriorityAudio( 54 if (Java_ThreadUtils_isThreadPriorityBackground(
55 env, PlatformThread::CurrentId())) { 55 env, PlatformThread::CurrentId())) {
56 *priority = ThreadPriority::BACKGROUND;
57 return true;
58 } else if (Java_ThreadUtils_isThreadPriorityNormal(
59 env, PlatformThread::CurrentId())) {
60 *priority = ThreadPriority::NORMAL;
61 return true;
62 } else if (Java_ThreadUtils_isThreadPriorityAudio(
63 env, PlatformThread::CurrentId())) {
56 *priority = ThreadPriority::REALTIME_AUDIO; 64 *priority = ThreadPriority::REALTIME_AUDIO;
57 return true; 65 return true;
58 } 66 }
59 return false; 67 return false;
60 } 68 }
61 69
70 bool SetChildThreadPriorityInCurrentProcess(PlatformThreadId tid,
71 ThreadPriority priority) {
72 // On Android, we set the Normal or Background priority through JNI.
73 // Other priorities are not yet supported by current function.
74 JNIEnv* env = base::android::AttachCurrentThread();
75 if (priority == ThreadPriority::BACKGROUND) {
76 Java_ThreadUtils_setThreadPriorityBackground(env, tid);
77 return true;
78 } else if (priority == ThreadPriority::NORMAL) {
79 Java_ThreadUtils_setThreadPriorityNormal(env, tid);
80 return true;
81 }
82 return false;
83 }
84
62 } // namespace internal 85 } // namespace internal
63 86
64 void PlatformThread::SetName(const std::string& name) { 87 void PlatformThread::SetName(const std::string& name) {
65 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); 88 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
66 tracked_objects::ThreadData::InitializeThreadContext(name); 89 tracked_objects::ThreadData::InitializeThreadContext(name);
67 90
68 // Like linux, on android we can get the thread names to show up in the 91 // Like linux, on android we can get the thread names to show up in the
69 // debugger by setting the process name for the LWP. 92 // debugger by setting the process name for the LWP.
70 // We don't want to do this for the main thread because that would rename 93 // We don't want to do this for the main thread because that would rename
71 // the process, causing tools like killall to stop working. 94 // the process, causing tools like killall to stop working.
(...skipping 22 matching lines...) Expand all
94 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). 117 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example).
95 return 2 * (1 << 20); // 2Mb 118 return 2 * (1 << 20); // 2Mb
96 #endif 119 #endif
97 } 120 }
98 121
99 bool RegisterThreadUtils(JNIEnv* env) { 122 bool RegisterThreadUtils(JNIEnv* env) {
100 return RegisterNativesImpl(env); 123 return RegisterNativesImpl(env);
101 } 124 }
102 125
103 } // namespace base 126 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698