Chromium Code Reviews| 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( | 21 return AtomicRefCountIsOne( |
| 14 &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_); | 22 &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_); |
| 15 } | 23 } |
| 16 | 24 |
| 17 RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) { | 25 RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) { |
| 18 #if DCHECK_IS_ON() | 26 #if DCHECK_IS_ON() |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 41 #endif | 49 #endif |
| 42 if (!AtomicRefCountDec(&ref_count_)) { | 50 if (!AtomicRefCountDec(&ref_count_)) { |
| 43 #if DCHECK_IS_ON() | 51 #if DCHECK_IS_ON() |
| 44 in_dtor_ = true; | 52 in_dtor_ = true; |
| 45 #endif | 53 #endif |
| 46 return true; | 54 return true; |
| 47 } | 55 } |
| 48 return false; | 56 return false; |
| 49 } | 57 } |
| 50 | 58 |
| 59 #if DCHECK_IS_ON() | |
| 60 bool RefCountedBase::CalledOnValidSequence() const { | |
| 61 return !AtomicRefCountIsZero(&g_cross_thread_ref_count_access_allow_count) || | |
| 62 sequence_checker_.CalledOnValidSequence(); | |
|
gab
2017/02/17 21:10:40
Flip these (i.e. sequence check || exception).
tzik
2017/02/21 06:15:02
Done.
| |
| 63 } | |
| 64 #endif | |
| 65 | |
| 51 } // namespace subtle | 66 } // namespace subtle |
| 52 | 67 |
| 68 #if DCHECK_IS_ON() | |
| 69 ScopedAllowCrossThreadRefCountAccess::ScopedAllowCrossThreadRefCountAccess() { | |
| 70 AtomicRefCountInc(&g_cross_thread_ref_count_access_allow_count); | |
| 71 } | |
| 72 | |
| 73 ScopedAllowCrossThreadRefCountAccess::~ScopedAllowCrossThreadRefCountAccess() { | |
| 74 AtomicRefCountDec(&g_cross_thread_ref_count_access_allow_count); | |
| 75 } | |
| 76 #endif | |
| 77 | |
| 53 } // namespace base | 78 } // namespace base |
| OLD | NEW |