summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 02:08:17 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 02:08:17 +0000
commitce21d0fcc67de4f167cad948f767b01bb6862030 (patch)
tree5421554a1a8005f606aa3704d81b9c4d75629782 /base
parent9ca245e3b2d0e2271c7124d3aceb8179903718e2 (diff)
downloadchromium_src-ce21d0fcc67de4f167cad948f767b01bb6862030.zip
chromium_src-ce21d0fcc67de4f167cad948f767b01bb6862030.tar.gz
chromium_src-ce21d0fcc67de4f167cad948f767b01bb6862030.tar.bz2
Chrome is too fast, make it slower.
Test out using RefCountedThreadSafeBase for all refcounting. Will revert after I'm done testing performance implications. BUG= TEST= Review URL: http://codereview.chromium.org/6712009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/raw_scoped_refptr_mismatch_checker.h3
-rw-r--r--base/ref_counted.cc40
-rw-r--r--base/ref_counted.h34
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.