OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <sched.h> | 8 #include <sched.h> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // On linux we can get the thread names to show up in the debugger by setting | 183 // On linux we can get the thread names to show up in the debugger by setting |
184 // the process name for the LWP. We don't want to do this for the main | 184 // the process name for the LWP. We don't want to do this for the main |
185 // thread because that would rename the process, causing tools like killall | 185 // thread because that would rename the process, causing tools like killall |
186 // to stop working. | 186 // to stop working. |
187 if (PlatformThread::CurrentId() == getpid()) | 187 if (PlatformThread::CurrentId() == getpid()) |
188 return; | 188 return; |
189 | 189 |
190 // http://0pointer.de/blog/projects/name-your-threads.html | 190 // http://0pointer.de/blog/projects/name-your-threads.html |
191 // Set the name for the LWP (which gets truncated to 15 characters). | 191 // Set the name for the LWP (which gets truncated to 15 characters). |
192 // Note that glibc also has a 'pthread_setname_np' api, but it may not be | 192 // Note that glibc also has a 'pthread_setname_np' api, but it may not be |
193 // available everywhere and doesn't seem to have any advantage over using | 193 // available everywhere and it's only benefit over using prctl directly is |
194 // prctl. | 194 // that it can set the name of threads other than the current thread. |
195 int err = prctl(PR_SET_NAME, name); | 195 int err = prctl(PR_SET_NAME, name); |
196 if (err < 0) | 196 // We expect EPERM failures in sandboxed processes, just ignore those. |
| 197 if (err < 0 && errno != EPERM) |
197 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; | 198 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
198 } | 199 } |
199 #elif defined(OS_MACOSX) | 200 #elif defined(OS_MACOSX) |
200 // Mac is implemented in platform_thread_mac.mm. | 201 // Mac is implemented in platform_thread_mac.mm. |
201 #else | 202 #else |
202 // static | 203 // static |
203 void PlatformThread::SetName(const char* name) { | 204 void PlatformThread::SetName(const char* name) { |
204 // have to cast away const because ThreadLocalPointer does not support const | 205 // have to cast away const because ThreadLocalPointer does not support const |
205 // void* | 206 // void* |
206 current_thread_name.Pointer()->Set(const_cast<char*>(name)); | 207 current_thread_name.Pointer()->Set(const_cast<char*>(name)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // Mac OS X uses lower-level mach APIs | 250 // Mac OS X uses lower-level mach APIs |
250 | 251 |
251 // static | 252 // static |
252 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 253 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
253 // TODO(crogers): implement | 254 // TODO(crogers): implement |
254 NOTIMPLEMENTED(); | 255 NOTIMPLEMENTED(); |
255 } | 256 } |
256 #endif | 257 #endif |
257 | 258 |
258 } // namespace base | 259 } // namespace base |
OLD | NEW |