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