diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-02 00:15:02 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-02 00:15:02 +0000 |
commit | 41ba55133f26e55968f0ca2ad197da983f83664b (patch) | |
tree | 7136734cbf2de003af8d5509f4933332f191f549 | |
parent | f388292e2415c365d474472198c62db5178ff234 (diff) | |
download | chromium_src-41ba55133f26e55968f0ca2ad197da983f83664b.zip chromium_src-41ba55133f26e55968f0ca2ad197da983f83664b.tar.gz chromium_src-41ba55133f26e55968f0ca2ad197da983f83664b.tar.bz2 |
Make the ref counts mutable, so we can ref count const objects.
Review URL: http://codereview.chromium.org/1575024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61263 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/ref_counted.cc | 8 | ||||
-rw-r--r-- | base/ref_counted.h | 22 | ||||
-rw-r--r-- | base/weak_ptr.cc | 4 | ||||
-rw-r--r-- | base/weak_ptr.h | 4 |
4 files changed, 19 insertions, 19 deletions
diff --git a/base/ref_counted.cc b/base/ref_counted.cc index ae04281..f1dffa4 100644 --- a/base/ref_counted.cc +++ b/base/ref_counted.cc @@ -25,7 +25,7 @@ RefCountedBase::~RefCountedBase() { #endif } -void RefCountedBase::AddRef() { +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_); @@ -35,7 +35,7 @@ void RefCountedBase::AddRef() { ++ref_count_; } -bool RefCountedBase::Release() { +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_); @@ -64,14 +64,14 @@ RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { #endif } -void RefCountedThreadSafeBase::AddRef() { +void RefCountedThreadSafeBase::AddRef() const { #ifndef NDEBUG DCHECK(!in_dtor_); #endif AtomicRefCountInc(&ref_count_); } -bool RefCountedThreadSafeBase::Release() { +bool RefCountedThreadSafeBase::Release() const { #ifndef NDEBUG DCHECK(!in_dtor_); DCHECK(!AtomicRefCountIsZero(&ref_count_)); diff --git a/base/ref_counted.h b/base/ref_counted.h index e2b2ed2..2cc4029 100644 --- a/base/ref_counted.h +++ b/base/ref_counted.h @@ -23,15 +23,15 @@ class RefCountedBase { RefCountedBase(); ~RefCountedBase(); - void AddRef(); + void AddRef() const; // Returns true if the object should self-delete. - bool Release(); + bool Release() const; private: - int ref_count_; + mutable int ref_count_; #ifndef NDEBUG - bool in_dtor_; + mutable bool in_dtor_; #endif DFAKE_MUTEX(add_release_); @@ -49,15 +49,15 @@ class RefCountedThreadSafeBase { RefCountedThreadSafeBase(); ~RefCountedThreadSafeBase(); - void AddRef(); + void AddRef() const; // Returns true if the object should self-delete. - bool Release(); + bool Release() const; private: - AtomicRefCount ref_count_; + mutable AtomicRefCount ref_count_; #ifndef NDEBUG - bool in_dtor_; + mutable bool in_dtor_; #endif DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafeBase); @@ -85,13 +85,13 @@ class RefCounted : public subtle::RefCountedBase { RefCounted() { } ~RefCounted() { } - void AddRef() { + void AddRef() const { subtle::RefCountedBase::AddRef(); } - void Release() { + void Release() const { if (subtle::RefCountedBase::Release()) { - delete static_cast<T*>(this); + delete static_cast<const T*>(this); } } diff --git a/base/weak_ptr.cc b/base/weak_ptr.cc index dec6a65..6473b4a 100644 --- a/base/weak_ptr.cc +++ b/base/weak_ptr.cc @@ -15,12 +15,12 @@ WeakReference::Flag::~Flag() { *handle_ = NULL; } -void WeakReference::Flag::AddRef() { +void WeakReference::Flag::AddRef() const { DCHECK(CalledOnValidThread()); RefCounted<Flag>::AddRef(); } -void WeakReference::Flag::Release() { +void WeakReference::Flag::Release() const { DCHECK(CalledOnValidThread()); RefCounted<Flag>::Release(); } diff --git a/base/weak_ptr.h b/base/weak_ptr.h index a4222f3..4ae7972 100644 --- a/base/weak_ptr.h +++ b/base/weak_ptr.h @@ -69,8 +69,8 @@ class WeakReference { Flag(Flag** handle); ~Flag(); - void AddRef(); - void Release(); + void AddRef() const; + void Release() const; void Invalidate() { handle_ = NULL; } bool is_valid() const { return handle_ != NULL; } |