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? |
| 6 // |
| 7 // Singletons make it hard to determine the lifetime of an object, which can |
| 8 // lead to buggy code and spurious crashes. |
| 9 // |
| 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 |
| 12 // b) Locations where you can deterministically create the object and pass |
| 13 // into other objects |
| 14 // |
| 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 |
| 17 // to do too much in their destructor or have circular dependencies. |
| 18 |
5 #ifndef BASE_MEMORY_SINGLETON_H_ | 19 #ifndef BASE_MEMORY_SINGLETON_H_ |
6 #define BASE_MEMORY_SINGLETON_H_ | 20 #define BASE_MEMORY_SINGLETON_H_ |
7 #pragma once | 21 #pragma once |
8 | 22 |
9 #include "base/at_exit.h" | 23 #include "base/at_exit.h" |
10 #include "base/atomicops.h" | 24 #include "base/atomicops.h" |
11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 25 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
12 #include "base/threading/platform_thread.h" | 26 #include "base/threading/platform_thread.h" |
13 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
14 | 28 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 instance_ = 0; | 276 instance_ = 0; |
263 } | 277 } |
264 static base::subtle::AtomicWord instance_; | 278 static base::subtle::AtomicWord instance_; |
265 }; | 279 }; |
266 | 280 |
267 template <typename Type, typename Traits, typename DifferentiatingType> | 281 template <typename Type, typename Traits, typename DifferentiatingType> |
268 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: | 282 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: |
269 instance_ = 0; | 283 instance_ = 0; |
270 | 284 |
271 #endif // BASE_MEMORY_SINGLETON_H_ | 285 #endif // BASE_MEMORY_SINGLETON_H_ |
OLD | NEW |