Index: base/memory/singleton.h |
=================================================================== |
--- base/memory/singleton.h (revision 89645) |
+++ base/memory/singleton.h (working copy) |
@@ -109,6 +109,30 @@ |
static base::subtle::Atomic32 dead_; |
}; |
+// Alternate traits for use with the Singleton<Type>. Identical to |
+// DefaultSingletonTraits except that AddRef() will be called on the singleton |
+// upon construction and Release() will be called instead of delete when |
+// the singleton is destructed. |
+template<typename Type> |
+struct RefCountedSingletonTraits { |
+ // Allocates the reference counted object. |
+ static Type* New() { |
+ DCHECK(Type::ImplementsThreadSafeReferenceCounting()); |
+ Type* ptr = new Type(); |
+ ptr->AddRef(); |
+ return ptr; |
+ } |
+ |
+ // Destroys the reference counted object. |
+ static void Delete(Type* x) { |
+ DCHECK(Type::ImplementsThreadSafeReferenceCounting()); |
+ x->Release(); |
+ } |
+ |
+ static const bool kRegisterAtExit = true; |
+ static const bool kAllowedToAccessOnNonjoinableThread = false; |
+}; |
+ |
template <typename Type> intptr_t |
StaticMemorySingletonTraits<Type>::buffer_[kBufferSize]; |
template <typename Type> base::subtle::Atomic32 |