diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-03 23:45:44 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-03 23:45:44 +0000 |
commit | a77f68d645f00b878cfe59a4883cc483016a0847 (patch) | |
tree | 9c6f47214b3258a3693b8c541e6b1f34fd855cf2 /base/threading | |
parent | ae56a1b0881793ffcf6e14710d41b35c0d57fbc3 (diff) | |
download | chromium_src-a77f68d645f00b878cfe59a4883cc483016a0847.zip chromium_src-a77f68d645f00b878cfe59a4883cc483016a0847.tar.gz chromium_src-a77f68d645f00b878cfe59a4883cc483016a0847.tar.bz2 |
Remove 1 exit time destructor and 1 static initializer from platform_thead_(posix|mac)
BUG=101600,94925
TEST=none
Review URL: http://codereview.chromium.org/8436007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading')
-rw-r--r-- | base/threading/platform_thread_mac.mm | 13 | ||||
-rw-r--r-- | base/threading/platform_thread_posix.cc | 14 |
2 files changed, 20 insertions, 7 deletions
diff --git a/base/threading/platform_thread_mac.mm b/base/threading/platform_thread_mac.mm index ef807eb..a530157 100644 --- a/base/threading/platform_thread_mac.mm +++ b/base/threading/platform_thread_mac.mm @@ -10,12 +10,19 @@ #include <mach/mach_time.h> #include <mach/thread_policy.h> +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/threading/thread_local.h" namespace base { -static ThreadLocalPointer<char> current_thread_name; +namespace { + +LazyInstance<ThreadLocalPointer<char>, + LeakyLazyInstanceTraits<ThreadLocalPointer<char> > > + current_thread_name(LINKER_INITIALIZED); + +} // namespace // If Cocoa is to be used on more than one thread, it must know that the // application is multithreaded. Since it's possible to enter Cocoa code @@ -40,7 +47,7 @@ void InitThreading() { // static void PlatformThread::SetName(const char* name) { - current_thread_name.Set(const_cast<char*>(name)); + current_thread_name.Pointer()->Set(const_cast<char*>(name)); // pthread_setname_np is only available in 10.6 or later, so test // for it at runtime. @@ -61,7 +68,7 @@ void PlatformThread::SetName(const char* name) { // static const char* PlatformThread::GetName() { - return current_thread_name.Get(); + return current_thread_name.Pointer()->Get(); } namespace { diff --git a/base/threading/platform_thread_posix.cc b/base/threading/platform_thread_posix.cc index e6b8e64..55b3f69 100644 --- a/base/threading/platform_thread_posix.cc +++ b/base/threading/platform_thread_posix.cc @@ -7,6 +7,7 @@ #include <errno.h> #include <sched.h> +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/safe_strerror_posix.h" @@ -38,7 +39,12 @@ void InitThreading(); namespace { -static ThreadLocalPointer<char> current_thread_name; +#if !defined(OS_MACOSX) +// Mac name code is in in platform_thread_mac.mm. +LazyInstance<ThreadLocalPointer<char>, + LeakyLazyInstanceTraits<ThreadLocalPointer<char> > > + current_thread_name(LINKER_INITIALIZED); +#endif struct ThreadParams { PlatformThread::Delegate* delegate; @@ -168,7 +174,7 @@ void PlatformThread::Sleep(int duration_ms) { 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)); + current_thread_name.Pointer()->Set(const_cast<char*>(name)); // http://0pointer.de/blog/projects/name-your-threads.html @@ -203,7 +209,7 @@ void PlatformThread::SetName(const char* name) { 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)); + current_thread_name.Pointer()->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.) @@ -215,7 +221,7 @@ void PlatformThread::SetName(const char* name) { // Mac is implemented in platform_thread_mac.mm. // static const char* PlatformThread::GetName() { - return current_thread_name.Get(); + return current_thread_name.Pointer()->Get(); } #endif |