diff options
Diffstat (limited to 'base/threading')
-rw-r--r-- | base/threading/thread_local.h | 40 | ||||
-rw-r--r-- | base/threading/thread_local_posix.cc | 38 | ||||
-rw-r--r-- | base/threading/thread_local_storage.cc | 2 | ||||
-rw-r--r-- | base/threading/thread_local_win.cc | 40 |
4 files changed, 7 insertions, 113 deletions
diff --git a/base/threading/thread_local.h b/base/threading/thread_local.h index b13be1a..ec8ce49 100644 --- a/base/threading/thread_local.h +++ b/base/threading/thread_local.h @@ -50,55 +50,27 @@ #include "base/base_export.h" #include "base/basictypes.h" - -#if defined(OS_POSIX) -#include <pthread.h> -#endif +#include "base/threading/thread_local_storage.h" namespace base { -namespace internal { - -// Helper functions that abstract the cross-platform APIs. Do not use directly. -struct BASE_EXPORT ThreadLocalPlatform { -#if defined(OS_WIN) - typedef unsigned long SlotType; -#elif defined(OS_POSIX) - typedef pthread_key_t SlotType; -#endif - - static void AllocateSlot(SlotType* slot); - static void FreeSlot(SlotType slot); - static void* GetValueFromSlot(SlotType slot); - static void SetValueInSlot(SlotType slot, void* value); -}; - -} // namespace internal template <typename Type> class ThreadLocalPointer { public: - ThreadLocalPointer() : slot_() { - internal::ThreadLocalPlatform::AllocateSlot(&slot_); - } + ThreadLocalPointer() {} - ~ThreadLocalPointer() { - internal::ThreadLocalPlatform::FreeSlot(slot_); - } + ~ThreadLocalPointer() {} Type* Get() { - return static_cast<Type*>( - internal::ThreadLocalPlatform::GetValueFromSlot(slot_)); + return static_cast<Type*>(slot_.Get()); } void Set(Type* ptr) { - internal::ThreadLocalPlatform::SetValueInSlot( - slot_, const_cast<void*>(static_cast<const void*>(ptr))); + slot_.Set(const_cast<void*>(static_cast<const void*>(ptr))); } private: - typedef internal::ThreadLocalPlatform::SlotType SlotType; - - SlotType slot_; + ThreadLocalStorage::Slot slot_; DISALLOW_COPY_AND_ASSIGN(ThreadLocalPointer<Type>); }; diff --git a/base/threading/thread_local_posix.cc b/base/threading/thread_local_posix.cc deleted file mode 100644 index 526a66d..0000000 --- a/base/threading/thread_local_posix.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/threading/thread_local.h" - -#include <pthread.h> - -#include "base/logging.h" - -namespace base { -namespace internal { - -// static -void ThreadLocalPlatform::AllocateSlot(SlotType* slot) { - int error = pthread_key_create(slot, NULL); - CHECK_EQ(error, 0); -} - -// static -void ThreadLocalPlatform::FreeSlot(SlotType slot) { - int error = pthread_key_delete(slot); - DCHECK_EQ(0, error); -} - -// static -void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) { - return pthread_getspecific(slot); -} - -// static -void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) { - int error = pthread_setspecific(slot, value); - DCHECK_EQ(error, 0); -} - -} // namespace internal -} // namespace base diff --git a/base/threading/thread_local_storage.cc b/base/threading/thread_local_storage.cc index ad4ff68..e1749c4 100644 --- a/base/threading/thread_local_storage.cc +++ b/base/threading/thread_local_storage.cc @@ -31,7 +31,7 @@ base::subtle::AtomicWord g_native_tls_key = base::subtle::Atomic32 g_last_used_tls_key = 0; // The maximum number of 'slots' in our thread local storage stack. -const int kThreadLocalStorageSize = 64; +const int kThreadLocalStorageSize = 256; // The maximum number of times to try to clear slots by calling destructors. // Use pthread naming convention for clarity. diff --git a/base/threading/thread_local_win.cc b/base/threading/thread_local_win.cc deleted file mode 100644 index 1c74e42..0000000 --- a/base/threading/thread_local_win.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/threading/thread_local.h" - -#include <windows.h> - -#include "base/logging.h" - -namespace base { -namespace internal { - -// static -void ThreadLocalPlatform::AllocateSlot(SlotType* slot) { - *slot = TlsAlloc(); - CHECK_NE(*slot, TLS_OUT_OF_INDEXES); -} - -// static -void ThreadLocalPlatform::FreeSlot(SlotType slot) { - if (!TlsFree(slot)) { - NOTREACHED() << "Failed to deallocate tls slot with TlsFree()."; - } -} - -// static -void* ThreadLocalPlatform::GetValueFromSlot(SlotType slot) { - return TlsGetValue(slot); -} - -// static -void ThreadLocalPlatform::SetValueInSlot(SlotType slot, void* value) { - if (!TlsSetValue(slot, value)) { - LOG(FATAL) << "Failed to TlsSetValue()."; - } -} - -} // namespace internal -} // namespace base |