diff options
-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; } |