| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 | 6 |
| 7 #include "base/threading/thread_collision_warner.h" | 7 #include "base/threading/thread_collision_warner.h" |
| 8 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 namespace { | 10 namespace { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 return AtomicRefCountIsOne(&ref_count_); | 21 return AtomicRefCountIsOne(&ref_count_); |
| 22 } | 22 } |
| 23 | 23 |
| 24 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { | 24 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { |
| 25 #if DCHECK_IS_ON() | 25 #if DCHECK_IS_ON() |
| 26 DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without " | 26 DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without " |
| 27 "calling Release()"; | 27 "calling Release()"; |
| 28 #endif | 28 #endif |
| 29 } | 29 } |
| 30 | 30 |
| 31 void RefCountedThreadSafeBase::AddRef() const { | |
| 32 #if DCHECK_IS_ON() | |
| 33 DCHECK(!in_dtor_); | |
| 34 DCHECK(!needs_adopt_ref_) | |
| 35 << "This RefCounted object is created with non-zero reference count." | |
| 36 << " The first reference to such a object has to be made by AdoptRef or" | |
| 37 << " MakeRefCounted."; | |
| 38 #endif | |
| 39 AtomicRefCountInc(&ref_count_); | |
| 40 } | |
| 41 | |
| 42 bool RefCountedThreadSafeBase::Release() const { | |
| 43 #if DCHECK_IS_ON() | |
| 44 DCHECK(!in_dtor_); | |
| 45 DCHECK(!AtomicRefCountIsZero(&ref_count_)); | |
| 46 #endif | |
| 47 if (!AtomicRefCountDec(&ref_count_)) { | |
| 48 #if DCHECK_IS_ON() | |
| 49 in_dtor_ = true; | |
| 50 #endif | |
| 51 return true; | |
| 52 } | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 #if DCHECK_IS_ON() | 31 #if DCHECK_IS_ON() |
| 57 bool RefCountedBase::CalledOnValidSequence() const { | 32 bool RefCountedBase::CalledOnValidSequence() const { |
| 58 return sequence_checker_.CalledOnValidSequence() || | 33 return sequence_checker_.CalledOnValidSequence() || |
| 59 !AtomicRefCountIsZero(&g_cross_thread_ref_count_access_allow_count); | 34 !AtomicRefCountIsZero(&g_cross_thread_ref_count_access_allow_count); |
| 60 } | 35 } |
| 61 #endif | 36 #endif |
| 62 | 37 |
| 63 } // namespace subtle | 38 } // namespace subtle |
| 64 | 39 |
| 65 #if DCHECK_IS_ON() | 40 #if DCHECK_IS_ON() |
| 66 ScopedAllowCrossThreadRefCountAccess::ScopedAllowCrossThreadRefCountAccess() { | 41 ScopedAllowCrossThreadRefCountAccess::ScopedAllowCrossThreadRefCountAccess() { |
| 67 AtomicRefCountInc(&g_cross_thread_ref_count_access_allow_count); | 42 AtomicRefCountInc(&g_cross_thread_ref_count_access_allow_count); |
| 68 } | 43 } |
| 69 | 44 |
| 70 ScopedAllowCrossThreadRefCountAccess::~ScopedAllowCrossThreadRefCountAccess() { | 45 ScopedAllowCrossThreadRefCountAccess::~ScopedAllowCrossThreadRefCountAccess() { |
| 71 AtomicRefCountDec(&g_cross_thread_ref_count_access_allow_count); | 46 AtomicRefCountDec(&g_cross_thread_ref_count_access_allow_count); |
| 72 } | 47 } |
| 73 #endif | 48 #endif |
| 74 | 49 |
| 75 } // namespace base | 50 } // namespace base |
| OLD | NEW |