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

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

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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 <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 20 matching lines...) Expand all
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 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { 40 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
41 {kThreadPriority_RealtimeAudio, -16}, 41 {ThreadPriority::BACKGROUND, 10},
42 {kThreadPriority_Background, 10}, 42 {ThreadPriority::NORMAL, 0},
43 {kThreadPriority_Normal, 0}, 43 {ThreadPriority::DISPLAY, -6},
44 {kThreadPriority_Display, -6}, 44 {ThreadPriority::REALTIME_AUDIO, -16},
45 }; 45 };
46 46
47 bool HandleSetThreadPriorityForPlatform(PlatformThreadHandle handle, 47 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle,
48 ThreadPriority priority) { 48 ThreadPriority priority) {
49 // On Android, we set the Audio priority through JNI as Audio priority 49 // On Android, we set the Audio priority through JNI as Audio priority
50 // will also allow the process to run while it is backgrounded. 50 // will also allow the process to run while it is backgrounded.
51 if (priority == kThreadPriority_RealtimeAudio) { 51 if (priority == ThreadPriority::REALTIME_AUDIO) {
52 JNIEnv* env = base::android::AttachCurrentThread(); 52 JNIEnv* env = base::android::AttachCurrentThread();
53 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId()); 53 Java_ThreadUtils_setThreadPriorityAudio(env, PlatformThread::CurrentId());
54 return true; 54 return true;
55 } 55 }
56 return false; 56 return false;
57 } 57 }
58 58
59 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle,
60 ThreadPriority* priority) {
61 NOTIMPLEMENTED();
62 return false;
63 }
64
59 } // namespace internal 65 } // namespace internal
60 66
61 void PlatformThread::SetName(const char* name) { 67 void PlatformThread::SetName(const char* name) {
62 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); 68 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
63 tracked_objects::ThreadData::InitializeThreadContext(name); 69 tracked_objects::ThreadData::InitializeThreadContext(name);
64 70
65 // Like linux, on android we can get the thread names to show up in the 71 // Like linux, on android we can get the thread names to show up in the
66 // debugger by setting the process name for the LWP. 72 // debugger by setting the process name for the LWP.
67 // We don't want to do this for the main thread because that would rename 73 // We don't want to do this for the main thread because that would rename
68 // the process, causing tools like killall to stop working. 74 // the process, causing tools like killall to stop working.
69 if (PlatformThread::CurrentId() == getpid()) 75 if (PlatformThread::CurrentId() == getpid())
70 return; 76 return;
71 77
72 // Set the name for the LWP (which gets truncated to 15 characters). 78 // Set the name for the LWP (which gets truncated to 15 characters).
73 int err = prctl(PR_SET_NAME, name); 79 int err = prctl(PR_SET_NAME, name);
74 if (err < 0 && errno != EPERM) 80 if (err < 0 && errno != EPERM)
75 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; 81 DPLOG(ERROR) << "prctl(PR_SET_NAME)";
76 } 82 }
77 83
78 84
79 void InitThreading() { 85 void InitThreading() {
80 } 86 }
81 87
82 void InitOnThread() { 88 void InitOnThread() {
83 // Threads on linux/android may inherit their priority from the thread 89 // Threads on linux/android may inherit their priority from the thread
84 // where they were created. This sets all new threads to the default. 90 // where they were created. This sets all new threads to the default.
85 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), 91 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(),
86 kThreadPriority_Normal); 92 ThreadPriority::NORMAL);
87 } 93 }
88 94
89 void TerminateOnThread() { 95 void TerminateOnThread() {
90 base::android::DetachFromVM(); 96 base::android::DetachFromVM();
91 } 97 }
92 98
93 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { 99 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
94 #if !defined(ADDRESS_SANITIZER) 100 #if !defined(ADDRESS_SANITIZER)
95 return 0; 101 return 0;
96 #else 102 #else
97 // AddressSanitizer bloats the stack approximately 2x. Default stack size of 103 // AddressSanitizer bloats the stack approximately 2x. Default stack size of
98 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). 104 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example).
99 return 2 * (1 << 20); // 2Mb 105 return 2 * (1 << 20); // 2Mb
100 #endif 106 #endif
101 } 107 }
102 108
103 bool RegisterThreadUtils(JNIEnv* env) { 109 bool RegisterThreadUtils(JNIEnv* env) {
104 return RegisterNativesImpl(env); 110 return RegisterNativesImpl(env);
105 } 111 }
106 112
107 } // namespace base 113 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698