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 #include "base/threading/thread_collision_warner.h" | 7 #include "base/threading/thread_collision_warner.h" |
7 | 8 |
8 namespace base { | 9 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 |
9 | 17 |
10 namespace subtle { | 18 namespace subtle { |
11 | 19 |
12 bool RefCountedThreadSafeBase::HasOneRef() const { | 20 bool RefCountedThreadSafeBase::HasOneRef() const { |
13 return AtomicRefCountIsOne(&ref_count_); | 21 return AtomicRefCountIsOne(&ref_count_); |
14 } | 22 } |
15 | 23 |
16 RefCountedThreadSafeBase::RefCountedThreadSafeBase() = default; | 24 RefCountedThreadSafeBase::RefCountedThreadSafeBase() = default; |
17 | 25 |
18 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { | 26 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() { |
(...skipping 17 matching lines...) Expand all Loading... |
36 #endif | 44 #endif |
37 if (!AtomicRefCountDec(&ref_count_)) { | 45 if (!AtomicRefCountDec(&ref_count_)) { |
38 #if DCHECK_IS_ON() | 46 #if DCHECK_IS_ON() |
39 in_dtor_ = true; | 47 in_dtor_ = true; |
40 #endif | 48 #endif |
41 return true; | 49 return true; |
42 } | 50 } |
43 return false; | 51 return false; |
44 } | 52 } |
45 | 53 |
| 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 |
46 } // namespace subtle | 61 } // namespace subtle |
47 | 62 |
| 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 |
48 } // namespace base | 73 } // namespace base |
OLD | NEW |