diff options
author | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-03 16:47:37 +0000 |
---|---|---|
committer | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-03 16:47:37 +0000 |
commit | 83a05ddf63cc5920ad04b0a6936fb8f5625daa07 (patch) | |
tree | 117361a500928d197eb8e919e8356906e6276c43 /base/thread.cc | |
parent | acc0d96fda8b5389f30bf47ca297ca8755f9778c (diff) | |
download | chromium_src-83a05ddf63cc5920ad04b0a6936fb8f5625daa07.zip chromium_src-83a05ddf63cc5920ad04b0a6936fb8f5625daa07.tar.gz chromium_src-83a05ddf63cc5920ad04b0a6936fb8f5625daa07.tar.bz2 |
Add ThreadLocalPointer and ThreadLocalBoolean abstractions, that will deprecate the old ThreadLocalStorage / TLSSlot APIs.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/thread.cc')
-rw-r--r-- | base/thread.cc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/base/thread.cc b/base/thread.cc index 20612d4..4f68546 100644 --- a/base/thread.cc +++ b/base/thread.cc @@ -4,7 +4,9 @@ #include "base/thread.h" +#include "base/singleton.h" #include "base/string_util.h" +#include "base/thread_local.h" #include "base/waitable_event.h" namespace base { @@ -46,21 +48,25 @@ Thread::~Thread() { // because its Stop method was called. This allows us to catch cases where // MessageLoop::Quit() is called directly, which is unexpected when using a // Thread to setup and run a MessageLoop. -// Note that if we start doing complex stuff in other static initializers -// this could cause problems. -// TODO(evanm): this shouldn't rely on static initialization. -TLSSlot Thread::tls_index_; +namespace { + +// Use a differentiating type to make sure we don't share our boolean we any +// other Singleton<ThreadLocalBoolean>'s. +struct ThreadExitedDummyDiffType { }; +typedef Singleton<ThreadLocalBoolean, + DefaultSingletonTraits<ThreadLocalBoolean>, + ThreadExitedDummyDiffType> ThreadExitedSingleton; + +} // namespace void Thread::SetThreadWasQuitProperly(bool flag) { -#ifndef NDEBUG - tls_index_.Set(reinterpret_cast<void*>(flag)); -#endif + ThreadExitedSingleton::get()->Set(flag); } bool Thread::GetThreadWasQuitProperly() { bool quit_properly = true; #ifndef NDEBUG - quit_properly = (tls_index_.Get() != 0); + quit_properly = ThreadExitedSingleton::get()->Get(); #endif return quit_properly; } |