Chromium Code Reviews| Index: base/memory/ref_counted.cc |
| diff --git a/base/memory/ref_counted.cc b/base/memory/ref_counted.cc |
| index cd6181b147349e46c4a86b7487e952d4725d1f91..5ca42c562dc7582cfcbfa44621a310932f838237 100644 |
| --- a/base/memory/ref_counted.cc |
| +++ b/base/memory/ref_counted.cc |
| @@ -3,9 +3,17 @@ |
| // found in the LICENSE file. |
| #include "base/memory/ref_counted.h" |
| + |
| #include "base/threading/thread_collision_warner.h" |
| namespace base { |
| +namespace { |
| + |
| +#if DCHECK_IS_ON() |
| +AtomicRefCount g_cross_thread_ref_count_access_allow_count = 0; |
| +#endif |
| + |
| +} // namespace |
| namespace subtle { |
| @@ -48,6 +56,23 @@ bool RefCountedThreadSafeBase::Release() const { |
| return false; |
| } |
| +#if DCHECK_IS_ON() |
| +bool RefCountedBase::CalledOnValidSequence() const { |
| + return !AtomicRefCountIsZero(&g_cross_thread_ref_count_access_allow_count) || |
| + 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.
|
| +} |
| +#endif |
| + |
| } // namespace subtle |
| +#if DCHECK_IS_ON() |
| +ScopedAllowCrossThreadRefCountAccess::ScopedAllowCrossThreadRefCountAccess() { |
| + AtomicRefCountInc(&g_cross_thread_ref_count_access_allow_count); |
| +} |
| + |
| +ScopedAllowCrossThreadRefCountAccess::~ScopedAllowCrossThreadRefCountAccess() { |
| + AtomicRefCountDec(&g_cross_thread_ref_count_access_allow_count); |
| +} |
| +#endif |
| + |
| } // namespace base |