Chromium Code Reviews| Index: include/core/SkRefCnt.h |
| diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h |
| index 1e31d918cc973727fcdf6b99b5d27a823bba478c..9e2c980a6b77f0c2c4036972c69365d06d91846d 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 |
| + ~SkNVRefCnt() { |
|
mtklein
2014/11/24 17:34:05
Oh wait, I forgot, not lgtm. Make this protected?
|
| + SkASSERTF(0 == 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,13 @@ 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) { |
| + 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. |