From 479efa8521759b1deb1aecf408c86ee8012d31e5 Mon Sep 17 00:00:00 2001 From: "mikhail.pozdnyakov@intel.com" Date: Thu, 12 Dec 2013 16:26:59 +0000 Subject: [PATCH] Revert of https://codereview.chromium.org/88993002/ Reason for revert: http://code.google.com/p/chromium/issues/detail?id=326236 TBR=thakis@chromium.org,darin@chromium.org NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/114163002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240334 0039d316-1c4b-4281-b951-d872f2087c98 --- base/memory/ref_counted.cc | 42 +++++++++++++++++++++++++++++++++++++++++ base/memory/ref_counted.h | 47 ++++------------------------------------------ 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/base/memory/ref_counted.cc b/base/memory/ref_counted.cc index f5924d0fe76e..31ad5098cd0f 100644 --- a/base/memory/ref_counted.cc +++ b/base/memory/ref_counted.cc @@ -3,12 +3,54 @@ // found in the LICENSE file. #include "base/memory/ref_counted.h" + +#include "base/logging.h" #include "base/threading/thread_collision_warner.h" 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(this)->ref_count_); diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h index be5eda8e0839..aae36b17c2f1 100644 --- a/base/memory/ref_counted.h +++ b/base/memory/ref_counted.h @@ -10,9 +10,6 @@ #include "base/atomic_ref_count.h" #include "base/base_export.h" #include "base/compiler_specific.h" -#ifndef NDEBUG -#include "base/logging.h" -#endif #include "base/threading/thread_collision_warner.h" namespace base { @@ -24,49 +21,13 @@ class BASE_EXPORT RefCountedBase { bool HasOneRef() const { return ref_count_ == 1; } protected: - RefCountedBase() - : ref_count_(0) - #ifndef NDEBUG - , in_dtor_(false) - #endif - { - } - - ~RefCountedBase() { - #ifndef NDEBUG - DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; - #endif - } - + RefCountedBase(); + ~RefCountedBase(); - void 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_; - } + void AddRef() const; // Returns true if the object should self-delete. - bool 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 Release() const; private: mutable int ref_count_; -- 2.11.4.GIT