Chromium Code Reviews| Index: base/memory/singleton.h |
| diff --git a/base/memory/singleton.h b/base/memory/singleton.h |
| index e50bdc05f34eeecefc293529e7eeab0e9da0bbde..31470e8bda184f430fc40f589b17d4d2caf80c2d 100644 |
| --- a/base/memory/singleton.h |
| +++ b/base/memory/singleton.h |
| @@ -37,7 +37,6 @@ static const subtle::AtomicWord kBeingCreatedMarker = 1; |
| BASE_EXPORT subtle::AtomicWord WaitForInstance(subtle::AtomicWord* instance); |
| } // namespace internal |
| -} // namespace base |
| // TODO(joth): Move more of this file into namespace base |
|
halliwell
2015/08/28 14:52:17
remove TODO?
|
| @@ -110,7 +109,7 @@ struct StaticMemorySingletonTraits { |
| // this is traits for returning NULL. |
| static Type* New() { |
| // Only constructs once and returns pointer; otherwise returns NULL. |
| - if (base::subtle::NoBarrier_AtomicExchange(&dead_, 1)) |
| + if (subtle::NoBarrier_AtomicExchange(&dead_, 1)) |
| return NULL; |
| return new(buffer_.void_data()) Type(); |
| @@ -125,20 +124,19 @@ struct StaticMemorySingletonTraits { |
| static const bool kAllowedToAccessOnNonjoinableThread = true; |
| // Exposed for unittesting. |
| - static void Resurrect() { |
| - base::subtle::NoBarrier_Store(&dead_, 0); |
| - } |
| + static void Resurrect() { subtle::NoBarrier_Store(&dead_, 0); } |
| private: |
| - static base::AlignedMemory<sizeof(Type), ALIGNOF(Type)> buffer_; |
| + static AlignedMemory<sizeof(Type), ALIGNOF(Type)> buffer_; |
| // Signal the object was already deleted, so it is not revived. |
| - static base::subtle::Atomic32 dead_; |
| + static subtle::Atomic32 dead_; |
| }; |
| -template <typename Type> base::AlignedMemory<sizeof(Type), ALIGNOF(Type)> |
| +template <typename Type> |
| +AlignedMemory<sizeof(Type), ALIGNOF(Type)> |
| StaticMemorySingletonTraits<Type>::buffer_; |
| -template <typename Type> base::subtle::Atomic32 |
| - StaticMemorySingletonTraits<Type>::dead_ = 0; |
| +template <typename Type> |
| +subtle::Atomic32 StaticMemorySingletonTraits<Type>::dead_ = 0; |
| // The Singleton<Type, Traits, DifferentiatingType> class manages a single |
| // instance of Type which will be created on first use and will be destroyed at |
| @@ -190,7 +188,7 @@ template <typename Type> base::subtle::Atomic32 |
| // RAE = kRegisterAtExit |
| // |
| // On every platform, if Traits::RAE is true, the singleton will be destroyed at |
| -// process exit. More precisely it uses base::AtExitManager which requires an |
| +// process exit. More precisely it uses AtExitManager which requires an |
| // object of this type to be instantiated. AtExitManager mimics the semantics |
| // of atexit() such as LIFO order but under Windows is safer to call. For more |
| // information see at_exit.h. |
| @@ -229,36 +227,36 @@ class Singleton { |
| #ifndef NDEBUG |
| // Avoid making TLS lookup on release builds. |
| if (!Traits::kAllowedToAccessOnNonjoinableThread) |
| - base::ThreadRestrictions::AssertSingletonAllowed(); |
| + ThreadRestrictions::AssertSingletonAllowed(); |
| #endif |
| // The load has acquire memory ordering as the thread which reads the |
| // instance_ pointer must acquire visibility over the singleton data. |
| - base::subtle::AtomicWord value = base::subtle::Acquire_Load(&instance_); |
| - if (value != 0 && value != base::internal::kBeingCreatedMarker) { |
| + subtle::AtomicWord value = subtle::Acquire_Load(&instance_); |
| + if (value != 0 && value != internal::kBeingCreatedMarker) { |
| return reinterpret_cast<Type*>(value); |
| } |
| // Object isn't created yet, maybe we will get to create it, let's try... |
| - if (base::subtle::Acquire_CompareAndSwap( |
| - &instance_, 0, base::internal::kBeingCreatedMarker) == 0) { |
| + if (subtle::Acquire_CompareAndSwap(&instance_, 0, |
| + internal::kBeingCreatedMarker) == 0) { |
| // instance_ was NULL and is now kBeingCreatedMarker. Only one thread |
| // will ever get here. Threads might be spinning on us, and they will |
| // stop right after we do this store. |
| Type* newval = Traits::New(); |
| // Releases the visibility over instance_ to the readers. |
| - base::subtle::Release_Store( |
| - &instance_, reinterpret_cast<base::subtle::AtomicWord>(newval)); |
| + subtle::Release_Store(&instance_, |
| + reinterpret_cast<subtle::AtomicWord>(newval)); |
| if (newval != NULL && Traits::kRegisterAtExit) |
| - base::AtExitManager::RegisterCallback(OnExit, NULL); |
| + AtExitManager::RegisterCallback(OnExit, NULL); |
| return newval; |
| } |
| // We hit a race. Wait for the other thread to complete it. |
| - value = base::internal::WaitForInstance(&instance_); |
| + value = internal::WaitForInstance(&instance_); |
| return reinterpret_cast<Type*>(value); |
| } |
| @@ -269,15 +267,14 @@ class Singleton { |
| static void OnExit(void* /*unused*/) { |
| // AtExit should only ever be register after the singleton instance was |
| // created. We should only ever get here with a valid instance_ pointer. |
| - Traits::Delete( |
| - reinterpret_cast<Type*>(base::subtle::NoBarrier_Load(&instance_))); |
| + Traits::Delete(reinterpret_cast<Type*>(subtle::NoBarrier_Load(&instance_))); |
| instance_ = 0; |
| } |
| - static base::subtle::AtomicWord instance_; |
| + static subtle::AtomicWord instance_; |
| }; |
| template <typename Type, typename Traits, typename DifferentiatingType> |
| -base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: |
| - instance_ = 0; |
| +subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>::instance_ = 0; |
| +} // namespace base |
| #endif // BASE_MEMORY_SINGLETON_H_ |