| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/safe_strerror_posix.h" | 13 #include "base/safe_strerror_posix.h" |
| 14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/tracked_objects.h" |
| 16 | 17 |
| 17 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
| 18 #include <mach/mach.h> | 19 #include <mach/mach.h> |
| 19 #include <sys/resource.h> | 20 #include <sys/resource.h> |
| 20 #include <algorithm> | 21 #include <algorithm> |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
| 24 #include <dlfcn.h> | 25 #include <dlfcn.h> |
| 25 #include <sys/prctl.h> | 26 #include <sys/prctl.h> |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // Linux SetName is currently disabled, as we need to distinguish between | 169 // Linux SetName is currently disabled, as we need to distinguish between |
| 169 // helper threads (where it's ok to make this call) and the main thread | 170 // helper threads (where it's ok to make this call) and the main thread |
| 170 // (where making this call renames our process, causing tools like killall | 171 // (where making this call renames our process, causing tools like killall |
| 171 // to stop working). | 172 // to stop working). |
| 172 #if 0 && defined(OS_LINUX) | 173 #if 0 && defined(OS_LINUX) |
| 173 // static | 174 // static |
| 174 void PlatformThread::SetName(const char* name) { | 175 void PlatformThread::SetName(const char* name) { |
| 175 // have to cast away const because ThreadLocalPointer does not support const | 176 // have to cast away const because ThreadLocalPointer does not support const |
| 176 // void* | 177 // void* |
| 177 current_thread_name.Pointer()->Set(const_cast<char*>(name)); | 178 current_thread_name.Pointer()->Set(const_cast<char*>(name)); |
| 179 tracked_objects::ThreadData::InitializeThreadContext(name); |
| 178 | 180 |
| 179 // http://0pointer.de/blog/projects/name-your-threads.html | 181 // http://0pointer.de/blog/projects/name-your-threads.html |
| 180 | 182 |
| 181 // glibc recently added support for pthread_setname_np, but it's not | 183 // glibc recently added support for pthread_setname_np, but it's not |
| 182 // commonly available yet. So test for it at runtime. | 184 // commonly available yet. So test for it at runtime. |
| 183 int (*dynamic_pthread_setname_np)(pthread_t, const char*); | 185 int (*dynamic_pthread_setname_np)(pthread_t, const char*); |
| 184 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = | 186 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) = |
| 185 dlsym(RTLD_DEFAULT, "pthread_setname_np"); | 187 dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
| 186 | 188 |
| 187 if (dynamic_pthread_setname_np) { | 189 if (dynamic_pthread_setname_np) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 203 } | 205 } |
| 204 } | 206 } |
| 205 #elif defined(OS_MACOSX) | 207 #elif defined(OS_MACOSX) |
| 206 // Mac is implemented in platform_thread_mac.mm. | 208 // Mac is implemented in platform_thread_mac.mm. |
| 207 #else | 209 #else |
| 208 // static | 210 // static |
| 209 void PlatformThread::SetName(const char* name) { | 211 void PlatformThread::SetName(const char* name) { |
| 210 // have to cast away const because ThreadLocalPointer does not support const | 212 // have to cast away const because ThreadLocalPointer does not support const |
| 211 // void* | 213 // void* |
| 212 current_thread_name.Pointer()->Set(const_cast<char*>(name)); | 214 current_thread_name.Pointer()->Set(const_cast<char*>(name)); |
| 215 tracked_objects::ThreadData::InitializeThreadContext(name); |
| 213 | 216 |
| 214 // (This should be relatively simple to implement for the BSDs; I | 217 // (This should be relatively simple to implement for the BSDs; I |
| 215 // just don't have one handy to test the code on.) | 218 // just don't have one handy to test the code on.) |
| 216 } | 219 } |
| 217 #endif // defined(OS_LINUX) | 220 #endif // defined(OS_LINUX) |
| 218 | 221 |
| 219 | 222 |
| 220 #if !defined(OS_MACOSX) | 223 #if !defined(OS_MACOSX) |
| 221 // Mac is implemented in platform_thread_mac.mm. | 224 // Mac is implemented in platform_thread_mac.mm. |
| 222 // static | 225 // static |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // Mac OS X uses lower-level mach APIs | 257 // Mac OS X uses lower-level mach APIs |
| 255 | 258 |
| 256 // static | 259 // static |
| 257 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { | 260 void PlatformThread::SetThreadPriority(PlatformThreadHandle, ThreadPriority) { |
| 258 // TODO(crogers): implement | 261 // TODO(crogers): implement |
| 259 NOTIMPLEMENTED(); | 262 NOTIMPLEMENTED(); |
| 260 } | 263 } |
| 261 #endif | 264 #endif |
| 262 | 265 |
| 263 } // namespace base | 266 } // namespace base |
| OLD | NEW |