1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/ref_counted.h"
7 #include "base/logging.h"
8 #include "base/thread_collision_warner.h"
14 RefCountedBase::RefCountedBase()
22 RefCountedBase::~RefCountedBase() {
24 DCHECK(in_dtor_
) << "RefCounted object deleted without calling Release()";
28 void RefCountedBase::AddRef() {
29 // TODO(maruel): Add back once it doesn't assert 500 times/sec.
30 // Current thread books the critical section "AddRelease" without release it.
31 // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
38 bool RefCountedBase::Release() {
39 // TODO(maruel): Add back once it doesn't assert 500 times/sec.
40 // Current thread books the critical section "AddRelease" without release it.
41 // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
45 if (--ref_count_
== 0) {
54 RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
60 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
62 DCHECK(in_dtor_
) << "RefCountedThreadSafe object deleted without "
67 void RefCountedThreadSafeBase::AddRef() {
71 AtomicRefCountInc(&ref_count_
);
74 bool RefCountedThreadSafeBase::Release() {
77 DCHECK(!AtomicRefCountIsZero(&ref_count_
));
79 if (!AtomicRefCountDec(&ref_count_
)) {
88 bool RefCountedThreadSafeBase::HasOneRef() const {
89 return AtomicRefCountIsOne(
90 &const_cast<RefCountedThreadSafeBase
*>(this)->ref_count_
);