summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/ref_counted.cc20
-rw-r--r--base/ref_counted.h17
-rw-r--r--tools/heapcheck/suppressions.txt14
3 files changed, 11 insertions, 40 deletions
diff --git a/base/ref_counted.cc b/base/ref_counted.cc
index 54c1071..2d459ae 100644
--- a/base/ref_counted.cc
+++ b/base/ref_counted.cc
@@ -12,7 +12,7 @@ namespace base {
namespace subtle {
RefCountedBase::RefCountedBase()
- : counter_holder_(new CounterHolder)
+ : ref_count_(0)
#ifndef NDEBUG
, in_dtor_(false)
#endif
@@ -20,7 +20,6 @@ RefCountedBase::RefCountedBase()
}
RefCountedBase::~RefCountedBase() {
- delete counter_holder_;
#ifndef NDEBUG
DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
#endif
@@ -33,7 +32,7 @@ void RefCountedBase::AddRef() const {
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
- ++(counter_holder_->ref_count);
+ ++ref_count_;
}
bool RefCountedBase::Release() const {
@@ -43,7 +42,7 @@ bool RefCountedBase::Release() const {
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
- if (--(counter_holder_->ref_count) == 0) {
+ if (--ref_count_ == 0) {
#ifndef NDEBUG
in_dtor_ = true;
#endif
@@ -54,19 +53,16 @@ bool RefCountedBase::Release() const {
bool RefCountedThreadSafeBase::HasOneRef() const {
return AtomicRefCountIsOne(
- &const_cast<RefCountedThreadSafeBase*>(this)->
- counter_holder_->ref_count);
+ &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
}
-RefCountedThreadSafeBase::RefCountedThreadSafeBase()
- : counter_holder_(new CounterHolder) {
+RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
#ifndef NDEBUG
in_dtor_ = false;
#endif
}
RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
- delete counter_holder_;
#ifndef NDEBUG
DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
"calling Release()";
@@ -77,15 +73,15 @@ void RefCountedThreadSafeBase::AddRef() const {
#ifndef NDEBUG
DCHECK(!in_dtor_);
#endif
- AtomicRefCountInc(&counter_holder_->ref_count);
+ AtomicRefCountInc(&ref_count_);
}
bool RefCountedThreadSafeBase::Release() const {
#ifndef NDEBUG
DCHECK(!in_dtor_);
- DCHECK(!AtomicRefCountIsZero(&counter_holder_->ref_count));
+ DCHECK(!AtomicRefCountIsZero(&ref_count_));
#endif
- if (!AtomicRefCountDec(&counter_holder_->ref_count)) {
+ if (!AtomicRefCountDec(&ref_count_)) {
#ifndef NDEBUG
in_dtor_ = true;
#endif
diff --git a/base/ref_counted.h b/base/ref_counted.h
index 6a2b996..4c3aeb8 100644
--- a/base/ref_counted.h
+++ b/base/ref_counted.h
@@ -17,25 +17,19 @@ class RefCountedBase {
public:
static bool ImplementsThreadSafeReferenceCounting() { return false; }
- bool HasOneRef() const { return counter_holder_->ref_count == 1; }
+ bool HasOneRef() const { return ref_count_ == 1; }
protected:
RefCountedBase();
~RefCountedBase();
- struct CounterHolder {
- CounterHolder() : ref_count(0), weak_count(0) {}
- int ref_count;
- int weak_count; // Simulates weak pointer.
- };
-
void AddRef() const;
// Returns true if the object should self-delete.
bool Release() const;
private:
- mutable CounterHolder* counter_holder_;
+ mutable int ref_count_;
#ifndef NDEBUG
mutable bool in_dtor_;
#endif
@@ -61,12 +55,7 @@ class RefCountedThreadSafeBase {
bool Release() const;
private:
- struct CounterHolder {
- CounterHolder() : ref_count(0), weak_count(0) {}
- AtomicRefCount ref_count;
- AtomicRefCount weak_count; // Simulates weak pointer.
- };
- mutable CounterHolder* counter_holder_;
+ mutable AtomicRefCount ref_count_;
#ifndef NDEBUG
mutable bool in_dtor_;
#endif
diff --git a/tools/heapcheck/suppressions.txt b/tools/heapcheck/suppressions.txt
index 5c3a66d..5a3e879 100644
--- a/tools/heapcheck/suppressions.txt
+++ b/tools/heapcheck/suppressions.txt
@@ -135,20 +135,6 @@
fun:testing::HandleExceptionsInMethodIfSupported
fun:testing::Test::Run
}
-{
- Intentional leak in BrowserThreadTest.NotReleasedIfTargetThreadNonExistent
- Heapcheck:Leak
- fun:RefCountedThreadSafeBase
- fun:RefCountedThreadSafe
- fun:NeverDeleted
- fun:BrowserThreadTest_NotReleasedIfTargetThreadNonExistent_Test::TestBody
- fun:testing::HandleExceptionsInMethodIfSupported
- fun:testing::Test::Run
- fun:testing::TestInfo::Run
- fun:testing::TestCase::Run
- fun:testing::internal::UnitTestImpl::RunAllTests
- fun:testing::HandleExceptionsInMethodIfSupported
-}
#-----------------------------------------------------------------------
# 3. Suppressions for real chromium bugs that are not yet fixed.
# These should all be in chromium's bug tracking system (but a few aren't yet).