Chromium Code Reviews| Index: base/threading/platform_thread_posix.cc |
| diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc |
| index baa3ab1e7e42d7843265123fb3685088f5b6a333..29c7e5a4065aa597dada44f379ef15c445bd6510 100644 |
| --- a/base/threading/platform_thread_posix.cc |
| +++ b/base/threading/platform_thread_posix.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/safe_strerror_posix.h" |
| +#include "base/threading/thread_local.h" |
| #include "base/threading/thread_restrictions.h" |
| #if defined(OS_MACOSX) |
| @@ -41,6 +42,8 @@ void InitThreading(); |
| namespace { |
| +static ThreadLocalPointer<char> current_thread_name; |
| + |
| struct ThreadParams { |
| PlatformThread::Delegate* delegate; |
| bool joinable; |
| @@ -59,6 +62,8 @@ void* ThreadFunc(void* params) { |
| return NULL; |
| } |
| + |
|
Sigurður Ásgeirsson
2011/08/04 12:31:39
nit: spurious space?
nduca
2011/08/04 18:17:38
Done.
|
| + |
| bool CreateThread(size_t stack_size, bool joinable, |
| PlatformThread::Delegate* delegate, |
| PlatformThreadHandle* thread_handle) { |
| @@ -168,6 +173,10 @@ void PlatformThread::Sleep(int duration_ms) { |
| #if 0 && defined(OS_LINUX) |
| // static |
| void PlatformThread::SetName(const char* name) { |
| + // have to cast away const because ThreadLocalPointer does not support const |
| + // void* |
| + current_thread_name.Set(const_cast<char*>(name)); |
| + |
| // http://0pointer.de/blog/projects/name-your-threads.html |
| // glibc recently added support for pthread_setname_np, but it's not |
| @@ -198,8 +207,10 @@ void PlatformThread::SetName(const char* name) { |
| // Mac is implemented in platform_thread_mac.mm. |
| #else |
| // static |
| -void PlatformThread::SetName(const char* /*name*/) { |
| - // Leave it unimplemented. |
| +void PlatformThread::SetName(const char* name) { |
| + // have to cast away const because ThreadLocalPointer does not support const |
| + // void* |
| + current_thread_name.Set(const_cast<char*>(name)); |
| // (This should be relatively simple to implement for the BSDs; I |
| // just don't have one handy to test the code on.) |
| @@ -207,6 +218,11 @@ void PlatformThread::SetName(const char* /*name*/) { |
| #endif // defined(OS_LINUX) |
| // static |
| +const char* PlatformThread::GetName() { |
| + return current_thread_name.Get(); |
| +} |
| + |
| +// static |
| bool PlatformThread::Create(size_t stack_size, Delegate* delegate, |
| PlatformThreadHandle* thread_handle) { |
| return CreateThread(stack_size, true /* joinable thread */, |