| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // PLEASE READ: Do you really need a singleton? | 5 // PLEASE READ: Do you really need a singleton? |
| 6 // | 6 // |
| 7 // Singletons make it hard to determine the lifetime of an object, which can | 7 // Singletons make it hard to determine the lifetime of an object, which can |
| 8 // lead to buggy code and spurious crashes. | 8 // lead to buggy code and spurious crashes. |
| 9 // | 9 // |
| 10 // Instead of adding another singleton into the mix, try to identify either: | 10 // Instead of adding another singleton into the mix, try to identify either: |
| 11 // a) An existing singleton that can manage your object's lifetime | 11 // a) An existing singleton that can manage your object's lifetime |
| 12 // b) Locations where you can deterministically create the object and pass | 12 // b) Locations where you can deterministically create the object and pass |
| 13 // into other objects | 13 // into other objects |
| 14 // | 14 // |
| 15 // If you absolutely need a singleton, please keep them as trivial as possible | 15 // If you absolutely need a singleton, please keep them as trivial as possible |
| 16 // and ideally a leaf dependency. Singletons get problematic when they attempt | 16 // and ideally a leaf dependency. Singletons get problematic when they attempt |
| 17 // to do too much in their destructor or have circular dependencies. | 17 // to do too much in their destructor or have circular dependencies. |
| 18 | 18 |
| 19 #ifndef BASE_MEMORY_SINGLETON_H_ | 19 #ifndef BASE_MEMORY_SINGLETON_H_ |
| 20 #define BASE_MEMORY_SINGLETON_H_ | 20 #define BASE_MEMORY_SINGLETON_H_ |
| 21 #pragma once | |
| 22 | 21 |
| 23 #include "base/at_exit.h" | 22 #include "base/at_exit.h" |
| 24 #include "base/atomicops.h" | 23 #include "base/atomicops.h" |
| 25 #include "base/base_export.h" | 24 #include "base/base_export.h" |
| 26 #include "base/memory/aligned_memory.h" | 25 #include "base/memory/aligned_memory.h" |
| 27 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 26 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 28 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
| 29 | 28 |
| 30 namespace base { | 29 namespace base { |
| 31 namespace internal { | 30 namespace internal { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 instance_ = 0; | 275 instance_ = 0; |
| 277 } | 276 } |
| 278 static base::subtle::AtomicWord instance_; | 277 static base::subtle::AtomicWord instance_; |
| 279 }; | 278 }; |
| 280 | 279 |
| 281 template <typename Type, typename Traits, typename DifferentiatingType> | 280 template <typename Type, typename Traits, typename DifferentiatingType> |
| 282 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: | 281 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: |
| 283 instance_ = 0; | 282 instance_ = 0; |
| 284 | 283 |
| 285 #endif // BASE_MEMORY_SINGLETON_H_ | 284 #endif // BASE_MEMORY_SINGLETON_H_ |
| OLD | NEW |