| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef BASE_SINGLETON_H_ | 5 #ifndef BASE_SINGLETON_H_ |
| 6 #define BASE_SINGLETON_H_ | 6 #define BASE_SINGLETON_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| 11 #include "base/platform_thread.h" |
| 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 12 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 12 | 13 |
| 13 // Default traits for Singleton<Type>. Calls operator new and operator delete on | 14 // Default traits for Singleton<Type>. Calls operator new and operator delete on |
| 14 // the object. Registers automatic deletion at process exit. | 15 // the object. Registers automatic deletion at process exit. |
| 15 // Overload if you need arguments or another memory allocation function. | 16 // Overload if you need arguments or another memory allocation function. |
| 16 template<typename Type> | 17 template<typename Type> |
| 17 struct DefaultSingletonTraits { | 18 struct DefaultSingletonTraits { |
| 18 // Allocates the object. | 19 // Allocates the object. |
| 19 static Type* New() { | 20 static Type* New() { |
| 20 // The parenthesis is very important here; it forces POD type | 21 // The parenthesis is very important here; it forces POD type |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 instance_ = 0; | 250 instance_ = 0; |
| 250 } | 251 } |
| 251 static base::subtle::AtomicWord instance_; | 252 static base::subtle::AtomicWord instance_; |
| 252 }; | 253 }; |
| 253 | 254 |
| 254 template <typename Type, typename Traits, typename DifferentiatingType> | 255 template <typename Type, typename Traits, typename DifferentiatingType> |
| 255 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: | 256 base::subtle::AtomicWord Singleton<Type, Traits, DifferentiatingType>:: |
| 256 instance_ = 0; | 257 instance_ = 0; |
| 257 | 258 |
| 258 #endif // BASE_SINGLETON_H_ | 259 #endif // BASE_SINGLETON_H_ |
| OLD | NEW |