| 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 | |
| 7 #include "base/threading/thread_collision_warner.h" | 6 #include "base/threading/thread_collision_warner.h" |
| 8 | 7 |
| 9 namespace base { | 8 namespace base { |
| 10 namespace { | |
| 11 | |
| 12 #if DCHECK_IS_ON() | |
| 13 AtomicRefCount g_cross_thread_ref_count_access_allow_count = 0; | |
| 14 #endif | |
| 15 | |
| 16 } // namespace | |
| 17 | 9 |
| 18 namespace subtle { | 10 namespace subtle { |
| 19 | 11 |
| 20 bool RefCountedThreadSafeBase::HasOneRef() const { | 12 bool RefCountedThreadSafeBase::HasOneRef() const { |
| 21 return AtomicRefCountIsOne(&ref_count_); | 13 return AtomicRefCountIsOne(&ref_count_); |
| 22 } | 14 } |
| 23 | 15 |
| 24 RefCountedThreadSafeBase::RefCountedThreadSafeBase() = default; | 16 RefCountedThreadSafeBase::RefCountedThreadSafeBase() = default; |
| 25 | 17 |
| 26 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { | 18 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 #endif | 36 #endif |
| 45 if (!AtomicRefCountDec(&ref_count_)) { | 37 if (!AtomicRefCountDec(&ref_count_)) { |
| 46 #if DCHECK_IS_ON() | 38 #if DCHECK_IS_ON() |
| 47 in_dtor_ = true; | 39 in_dtor_ = true; |
| 48 #endif | 40 #endif |
| 49 return true; | 41 return true; |
| 50 } | 42 } |
| 51 return false; | 43 return false; |
| 52 } | 44 } |
| 53 | 45 |
| 54 #if DCHECK_IS_ON() | |
| 55 bool RefCountedBase::CalledOnValidSequence() const { | |
| 56 return sequence_checker_.CalledOnValidSequence() || | |
| 57 !AtomicRefCountIsZero(&g_cross_thread_ref_count_access_allow_count); | |
| 58 } | |
| 59 #endif | |
| 60 | |
| 61 } // namespace subtle | 46 } // namespace subtle |
| 62 | 47 |
| 63 #if DCHECK_IS_ON() | |
| 64 ScopedAllowCrossThreadRefCountAccess::ScopedAllowCrossThreadRefCountAccess() { | |
| 65 AtomicRefCountInc(&g_cross_thread_ref_count_access_allow_count); | |
| 66 } | |
| 67 | |
| 68 ScopedAllowCrossThreadRefCountAccess::~ScopedAllowCrossThreadRefCountAccess() { | |
| 69 AtomicRefCountDec(&g_cross_thread_ref_count_access_allow_count); | |
| 70 } | |
| 71 #endif | |
| 72 | |
| 73 } // namespace base | 48 } // namespace base |
| OLD | NEW |