summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-19 04:13:30 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-19 04:13:30 +0000
commit09d8b96b586dc972f31b6e1c72643de6ffb5ad16 (patch)
treeaae0e8d9212d4f4467c678c03c49bbef628c1303 /base
parent492fbbb2e23f4323af17413419c7401dcbeea7ed (diff)
downloadchromium_src-09d8b96b586dc972f31b6e1c72643de6ffb5ad16.zip
chromium_src-09d8b96b586dc972f31b6e1c72643de6ffb5ad16.tar.gz
chromium_src-09d8b96b586dc972f31b6e1c72643de6ffb5ad16.tar.bz2
Revert 78649 - Finished running the experiment.
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 TBR=willchan@chromium.org Review URL: http://codereview.chromium.org/6711057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78811 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, 72 insertions, 5 deletions
diff --git a/base/raw_scoped_refptr_mismatch_checker.h b/base/raw_scoped_refptr_mismatch_checker.h
index 522751a..b79cfb5 100644
--- a/base/raw_scoped_refptr_mismatch_checker.h
+++ b/base/raw_scoped_refptr_mismatch_checker.h
@@ -36,7 +36,8 @@ struct NeedsScopedRefptrButGetsRawPtr {
// raw pointer type and are convertible to a RefCounted(Base|ThreadSafeBase)
// type.
value = (is_pointer<T>::value &&
- (is_convertible<T, subtle::RefCountedThreadSafeBase*>::value))
+ (is_convertible<T, subtle::RefCountedBase*>::value ||
+ is_convertible<T, subtle::RefCountedThreadSafeBase*>::value))
};
#endif
};
diff --git a/base/ref_counted.cc b/base/ref_counted.cc
index 8d2c5fd..2d459ae 100644
--- a/base/ref_counted.cc
+++ b/base/ref_counted.cc
@@ -11,6 +11,46 @@ 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 47ea654..4c3aeb8 100644
--- a/base/ref_counted.h
+++ b/base/ref_counted.h
@@ -13,6 +13,32 @@ 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; }
@@ -54,23 +80,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::RefCountedThreadSafeBase {
+class RefCounted : public subtle::RefCountedBase {
public:
RefCounted() { }
~RefCounted() { }
void AddRef() const {
- subtle::RefCountedThreadSafeBase::AddRef();
+ subtle::RefCountedBase::AddRef();
}
void Release() const {
- if (subtle::RefCountedThreadSafeBase::Release()) {
+ if (subtle::RefCountedBase::Release()) {
delete static_cast<const T*>(this);
}
}
private:
- DISALLOW_COPY_AND_ASSIGN(RefCounted);
+ DISALLOW_COPY_AND_ASSIGN(RefCounted<T>);
};
// Forward declaration.