Index: base/memory/ref_counted.cc |
diff --git a/base/memory/ref_counted.cc b/base/memory/ref_counted.cc |
index 46bbd7ad858b152ec8a29d1b5060c24fb466be09..b6c888dcc0cbfb3ef829ffeb538b22cadc7ff72d 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 { |
@@ -43,6 +51,23 @@ bool RefCountedThreadSafeBase::Release() const { |
return false; |
} |
+#if DCHECK_IS_ON() |
+bool RefCountedBase::CalledOnValidSequence() const { |
+ return sequence_checker_.CalledOnValidSequence() || |
+ !AtomicRefCountIsZero(&g_cross_thread_ref_count_access_allow_count); |
+} |
+#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 |