diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-19 04:13:30 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-19 04:13:30 +0000 |
commit | 09d8b96b586dc972f31b6e1c72643de6ffb5ad16 (patch) | |
tree | aae0e8d9212d4f4467c678c03c49bbef628c1303 /base/ref_counted.cc | |
parent | 492fbbb2e23f4323af17413419c7401dcbeea7ed (diff) | |
download | chromium_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/ref_counted.cc')
-rw-r--r-- | base/ref_counted.cc | 40 |
1 files changed, 40 insertions, 0 deletions
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_); |