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

Unified Diff: include/core/SkRefCnt.h

Issue 745383003: add some debugging to SkNVRefCnt (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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 | « no previous file | 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 1e31d918cc973727fcdf6b99b5d27a823bba478c..ab716ddf58d83fa3e4f23195f15b818b6e93fa1e 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -253,6 +253,11 @@ template <typename Derived>
class SkNVRefCnt : SkNoncopyable {
public:
SkNVRefCnt() : fRefCnt(1) {}
+#ifdef SK_DEBUG
mtklein 2014/11/22 00:08:14 Double debug guards seem like overkill? Should be
+ ~SkNVRefCnt() {
+ SkASSERTF(1 == fRefCnt, "NVRefCnt was %d", fRefCnt);
+ }
+#endif
// Implementation is pretty much the same as SkRefCntBase. All required barriers are the same:
// - unique() needs acquire when it returns true, and no barrier if it returns false;
@@ -261,7 +266,14 @@ public:
bool unique() const { return 1 == sk_acquire_load(&fRefCnt); }
void ref() const { sk_atomic_inc(&fRefCnt); }
- void unref() const { if (1 == sk_atomic_dec(&fRefCnt)) { SkDELETE((const Derived*)this); } }
+ void unref() const {
+ int32_t prevValue = sk_atomic_dec(&fRefCnt);
+ SkASSERT(prevValue >= 1);
+ if (1 == prevValue) {
+ SkDEBUGCODE(fRefCnt = 1;) // for the assert in our destructor
bsalomon 2014/11/21 22:48:50 Why 1? For stack objects? Do we want to allow that
mtklein 2014/11/22 00:08:14 I'm game to try disallowing the stack and delete i
+ SkDELETE((const Derived*)this);
+ }
+ }
void deref() const { this->unref(); } // Chrome prefers to call deref().
int32_t getRefCnt() const { return fRefCnt; } // Used by Chrome unit tests.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698