OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
wtc
2009/09/02 01:17:17
This should say 2006-2009.
| |
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 #ifndef BASE_SINGLETON_H_ | 5 #ifndef BASE_SINGLETON_H_ |
6 #define BASE_SINGLETON_H_ | 6 #define BASE_SINGLETON_H_ |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/dynamic_annotations.h" | 10 #include "base/dynamic_annotations.h" |
11 #include "base/platform_thread.h" | 11 #include "base/platform_thread.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // | 63 // |
64 // This class is itself thread-safe. The underlying Type must of course be | 64 // This class is itself thread-safe. The underlying Type must of course be |
65 // thread-safe if you want to use it concurrently. Two parameters may be tuned | 65 // thread-safe if you want to use it concurrently. Two parameters may be tuned |
66 // depending on the user's requirements. | 66 // depending on the user's requirements. |
67 // | 67 // |
68 // Glossary: | 68 // Glossary: |
69 // RAE = kRegisterAtExit | 69 // RAE = kRegisterAtExit |
70 // | 70 // |
71 // On every platform, if Traits::RAE is true, the singleton will be destroyed at | 71 // On every platform, if Traits::RAE is true, the singleton will be destroyed at |
72 // process exit. More precisely it uses base::AtExitManager which requires an | 72 // process exit. More precisely it uses base::AtExitManager which requires an |
73 // object of this type to be instanciated. AtExitManager mimics the semantics | 73 // object of this type to be instantiated. AtExitManager mimics the semantics |
74 // of atexit() such as LIFO order but under Windows is safer to call. For more | 74 // of atexit() such as LIFO order but under Windows is safer to call. For more |
75 // information see at_exit.h. | 75 // information see at_exit.h. |
76 // | 76 // |
77 // If Traits::RAE is false, the singleton will not be freed at process exit, | 77 // If Traits::RAE is false, the singleton will not be freed at process exit, |
78 // thus the singleton will be leaked if it is ever accessed. Traits::RAE | 78 // thus the singleton will be leaked if it is ever accessed. Traits::RAE |
79 // shouldn't be false unless absolutely necessary. Remember that the heap where | 79 // shouldn't be false unless absolutely necessary. Remember that the heap where |
80 // the object is allocated may be destroyed by the CRT anyway. | 80 // the object is allocated may be destroyed by the CRT anyway. |
81 // | 81 // |
82 // If you want to ensure that your class can only exist as a singleton, make | 82 // If you want to ensure that your class can only exist as a singleton, make |
83 // its constructors private, and make DefaultSingletonTraits<> a friend: | 83 // its constructors private, and make DefaultSingletonTraits<> a friend: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 base::subtle::NoBarrier_AtomicExchange(&instance_, 0))); | 183 base::subtle::NoBarrier_AtomicExchange(&instance_, 0))); |
184 } | 184 } |
185 static base::subtle::AtomicWord instance_; | 185 static base::subtle::AtomicWord instance_; |
186 }; | 186 }; |
187 | 187 |
188 template <typename Type, typename Traits, typename DifferentiatingType> | 188 template <typename Type, typename Traits, typename DifferentiatingType> |
189 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: | 189 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: |
190 instance_ = 0; | 190 instance_ = 0; |
191 | 191 |
192 #endif // BASE_SINGLETON_H_ | 192 #endif // BASE_SINGLETON_H_ |
OLD | NEW |