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

Unified Diff: include/core/SkRefCnt.h

Issue 25432003: Add run-time reference adoption checks to SkRefCnt (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Comment punctuation fix. Created 7 years, 2 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 | « 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 d6120d654a30062e51a5be17b324b47d0d8c6f07..eb48276f038d05f686ccfee80820871f4b925aff 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -14,6 +14,22 @@
#include "SkInstCnt.h"
#include "SkTemplates.h"
+#ifdef SK_REF_CNT_BASE_INCLUDE
+#include SK_REF_CNT_BASE_INCLUDE
+#else
+/** \class SkRefCntBase
+
+ Default implementation of SkRefCntBase. The base class' contract is to
+ provide an implementation of aboutToRef. Embedders of skia can specify
+ an alternate implementation by setting SK_REF_CNT_BASE_INCLUDE. This is
+ useful for adding debug run-time checks to enforce certain usage patterns.
+*/
+class SK_API SkRefCntBase {
+public:
+ void aboutToRef() const {}
+};
+#endif
+
/** \class SkRefCnt
SkRefCnt is the base class for objects that may be shared by multiple
@@ -24,7 +40,7 @@
destructor to be called explicitly (or via the object going out of scope on
the stack or calling delete) if getRefCnt() > 1.
*/
-class SK_API SkRefCnt : SkNoncopyable {
+class SK_API SkRefCnt : public SkRefCntBase {
public:
SK_DECLARE_INST_COUNT_ROOT(SkRefCnt)
@@ -61,6 +77,7 @@ public:
*/
void ref() const {
SkASSERT(fRefCnt > 0);
+ this->INHERITED::aboutToRef();
sk_atomic_inc(&fRefCnt); // No barrier required.
}
@@ -106,6 +123,12 @@ protected:
private:
/**
+ * Make SkRefCnt non-copyable.
+ */
+ SkRefCnt(const SkRefCnt&);
+ SkRefCnt& operator=(const SkRefCnt&);
+
+ /**
* Called when the ref count goes to 0.
*/
virtual void internal_dispose() const {
@@ -120,7 +143,7 @@ private:
mutable int32_t fRefCnt;
- typedef SkNoncopyable INHERITED;
+ typedef SkRefCntBase INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
« 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