diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/raw_scoped_refptr_mismatch_checker.h | 3 | ||||
-rw-r--r-- | base/ref_counted.cc | 40 | ||||
-rw-r--r-- | base/ref_counted.h | 34 |
3 files changed, 5 insertions, 72 deletions
diff --git a/base/raw_scoped_refptr_mismatch_checker.h b/base/raw_scoped_refptr_mismatch_checker.h index b79cfb5..522751a 100644 --- a/base/raw_scoped_refptr_mismatch_checker.h +++ b/base/raw_scoped_refptr_mismatch_checker.h @@ -36,8 +36,7 @@ struct NeedsScopedRefptrButGetsRawPtr { // raw pointer type and are convertible to a RefCounted(Base|ThreadSafeBase) // type. value = (is_pointer<T>::value && - (is_convertible<T, subtle::RefCountedBase*>::value || - is_convertible<T, subtle::RefCountedThreadSafeBase*>::value)) + (is_convertible<T, subtle::RefCountedThreadSafeBase*>::value)) }; #endif }; diff --git a/base/ref_counted.cc b/base/ref_counted.cc index 2d459ae..8d2c5fd 100644 --- a/base/ref_counted.cc +++ b/base/ref_counted.cc @@ -11,46 +11,6 @@ namespace base { namespace subtle { -RefCountedBase::RefCountedBase() - : ref_count_(0) -#ifndef NDEBUG - , in_dtor_(false) -#endif - { -} - -RefCountedBase::~RefCountedBase() { -#ifndef NDEBUG - DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; -#endif -} - -void RefCountedBase::AddRef() const { - // TODO(maruel): Add back once it doesn't assert 500 times/sec. - // Current thread books the critical section "AddRelease" without release it. - // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_); -#ifndef NDEBUG - DCHECK(!in_dtor_); -#endif - ++ref_count_; -} - -bool RefCountedBase::Release() const { - // TODO(maruel): Add back once it doesn't assert 500 times/sec. - // Current thread books the critical section "AddRelease" without release it. - // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_); -#ifndef NDEBUG - DCHECK(!in_dtor_); -#endif - if (--ref_count_ == 0) { -#ifndef NDEBUG - in_dtor_ = true; -#endif - return true; - } - return false; -} - bool RefCountedThreadSafeBase::HasOneRef() const { return AtomicRefCountIsOne( &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_); diff --git a/base/ref_counted.h b/base/ref_counted.h index 4c3aeb8..47ea654 100644 --- a/base/ref_counted.h +++ b/base/ref_counted.h @@ -13,32 +13,6 @@ namespace base { namespace subtle { -class RefCountedBase { - public: - static bool ImplementsThreadSafeReferenceCounting() { return false; } - - bool HasOneRef() const { return ref_count_ == 1; } - - protected: - RefCountedBase(); - ~RefCountedBase(); - - void AddRef() const; - - // Returns true if the object should self-delete. - bool Release() const; - - private: - mutable int ref_count_; -#ifndef NDEBUG - mutable bool in_dtor_; -#endif - - DFAKE_MUTEX(add_release_); - - DISALLOW_COPY_AND_ASSIGN(RefCountedBase); -}; - class RefCountedThreadSafeBase { public: static bool ImplementsThreadSafeReferenceCounting() { return true; } @@ -80,23 +54,23 @@ class RefCountedThreadSafeBase { // You should always make your destructor private, to avoid any code deleting // the object accidently while there are references to it. template <class T> -class RefCounted : public subtle::RefCountedBase { +class RefCounted : public subtle::RefCountedThreadSafeBase { public: RefCounted() { } ~RefCounted() { } void AddRef() const { - subtle::RefCountedBase::AddRef(); + subtle::RefCountedThreadSafeBase::AddRef(); } void Release() const { - if (subtle::RefCountedBase::Release()) { + if (subtle::RefCountedThreadSafeBase::Release()) { delete static_cast<const T*>(this); } } private: - DISALLOW_COPY_AND_ASSIGN(RefCounted<T>); + DISALLOW_COPY_AND_ASSIGN(RefCounted); }; // Forward declaration. |