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

Unified Diff: include/core/SkRefCnt.h

Issue 247813005: teach TSAN about SkSpinlock, SkRefCnt, and SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused Created 6 years, 8 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
« no previous file with comments | « include/core/SkOnce.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkRefCnt.h
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 41c78293fa7f2824d9ecc755c085d7242b845ab2..2ac68ddbcdff6c33c4c131fc18a35202af31d2a5 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -37,7 +37,7 @@ public:
*/
virtual ~SkRefCntBase() {
#ifdef SK_DEBUG
- SkASSERT(fRefCnt == 1);
+ SkASSERT(this->unique());
fRefCnt = 0; // illegal value, to catch us if we reuse after delete
#endif
}
@@ -53,6 +53,7 @@ public:
// an unproctected read. Generally, don't read fRefCnt, and don't stifle this warning.
bool const unique = (1 == SK_ANNOTATE_UNPROTECTED_READ(fRefCnt));
if (unique) {
+ SK_ANNOTATE_HAPPENS_AFTER(this);
// Acquire barrier (L/SL), if not provided by load of fRefCnt.
// Prevents user's 'unique' code from happening before decrements.
//TODO: issue the barrier.
bungeman-skia 2014/04/23 22:37:54 We do need to actually issue a barrier here on ARM
mtklein 2014/04/23 23:41:47 Ooh, yes, or as you noted, provide a way to load f
bungeman-skia 2014/04/24 14:06:56 Eh, there's no real reason to provide any barrier
@@ -63,7 +64,7 @@ public:
/** Increment the reference count. Must be balanced by a call to unref().
*/
void ref() const {
- SkASSERT(fRefCnt > 0);
+ SkASSERT(this->unsafeGetRefCnt() > 0);
sk_atomic_inc(&fRefCnt); // No barrier required.
}
@@ -72,9 +73,11 @@ public:
the object needs to have been allocated via new, and not on the stack.
*/
void unref() const {
- SkASSERT(fRefCnt > 0);
+ SkASSERT(this->unsafeGetRefCnt() > 0);
+ SK_ANNOTATE_HAPPENS_BEFORE(this);
// Release barrier (SL/S), if not provided below.
if (sk_atomic_dec(&fRefCnt) == 1) {
+ SK_ANNOTATE_HAPPENS_AFTER(this);
// Acquire barrier (L/SL), if not provided above.
// Prevents code in dispose from happening before the decrement.
sk_membar_acquire__after_atomic_dec();
@@ -84,7 +87,7 @@ public:
#ifdef SK_DEBUG
void validate() const {
- SkASSERT(fRefCnt > 0);
+ SkASSERT(this->unsafeGetRefCnt() > 0);
}
#endif
@@ -103,6 +106,9 @@ protected:
}
private:
+ // OK for use in asserts, but not much else.
+ int32_t unsafeGetRefCnt() { return SK_ANNOTATE_UNPROTECTED_READ(fRefCnt); }
+
/**
* Called when the ref count goes to 0.
*/
« no previous file with comments | « include/core/SkOnce.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698