Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: base/memory/ref_counted.cc

Issue 2666423002: Assert sequence validity on non-thread-safe RefCount manipulations (2) (Closed)
Patch Set: rebase on ImageStorage fix Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698