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/resource.h> | 9 #include <sys/resource.h> |
9 | 10 |
10 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
11 #include "base/android/thread_utils.h" | 12 #include "base/android/thread_utils.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/threading/thread_id_name_manager.h" | 15 #include "base/threading/thread_id_name_manager.h" |
15 #include "base/tracked_objects.h" | 16 #include "base/tracked_objects.h" |
16 #include "jni/ThreadUtils_jni.h" | 17 #include "jni/ThreadUtils_jni.h" |
17 | 18 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // granted permission to adjust nice values on the system. | 71 // granted permission to adjust nice values on the system. |
71 DCHECK_NE(handle.id_, kInvalidThreadId); | 72 DCHECK_NE(handle.id_, kInvalidThreadId); |
72 int kNiceSetting = ThreadNiceValue(priority); | 73 int kNiceSetting = ThreadNiceValue(priority); |
73 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) | 74 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) |
74 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; | 75 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; |
75 } | 76 } |
76 | 77 |
77 void PlatformThread::SetName(const char* name) { | 78 void PlatformThread::SetName(const char* name) { |
78 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 79 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
79 tracked_objects::ThreadData::InitializeThreadContext(name); | 80 tracked_objects::ThreadData::InitializeThreadContext(name); |
| 81 |
| 82 // Like linux, on android we can get the thread names to show up in the |
| 83 // debugger by setting the process name for the LWP. |
| 84 // We don't want to do this for the main thread because that would rename |
| 85 // the process, causing tools like killall to stop working. |
| 86 if (PlatformThread::CurrentId() == getpid()) |
| 87 return; |
| 88 |
| 89 // Set the name for the LWP (which gets truncated to 15 characters). |
| 90 int err = prctl(PR_SET_NAME, name); |
| 91 if (err < 0 && errno != EPERM) |
| 92 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
80 } | 93 } |
81 | 94 |
82 | 95 |
83 void InitThreading() { | 96 void InitThreading() { |
84 } | 97 } |
85 | 98 |
86 void InitOnThread() { | 99 void InitOnThread() { |
87 // Threads on linux/android may inherit their priority from the thread | 100 // Threads on linux/android may inherit their priority from the thread |
88 // where they were created. This sets all new threads to the default. | 101 // where they were created. This sets all new threads to the default. |
89 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), | 102 PlatformThread::SetThreadPriority(PlatformThread::CurrentHandle(), |
(...skipping 12 matching lines...) Expand all Loading... |
102 // 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). |
103 return 2 * (1 << 20); // 2Mb | 116 return 2 * (1 << 20); // 2Mb |
104 #endif | 117 #endif |
105 } | 118 } |
106 | 119 |
107 bool RegisterThreadUtils(JNIEnv* env) { | 120 bool RegisterThreadUtils(JNIEnv* env) { |
108 return RegisterNativesImpl(env); | 121 return RegisterNativesImpl(env); |
109 } | 122 } |
110 | 123 |
111 } // namespace base | 124 } // namespace base |
OLD | NEW |