aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrNonAtomicRef.h
diff options
context:
space:
mode:
authorGravatar cdalton <cdalton@nvidia.com>2016-02-02 22:46:16 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-02 22:46:16 -0800
commit4833f39a41e7689db4922fdbb5c1b47ae55f7c8d (patch)
treeb2cb8c45739d7937c0f9c8461cc2d70feb27ab55 /src/gpu/GrNonAtomicRef.h
parentafc7cce5d68663934128d76963cd501f771d71de (diff)
Templatize GrNonAtomicRef
Templatizes GrNonAtomicRef so it does not necessarily require a virtual destructor. This also gives us the flexibility to specialize how different types get deleted. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1664613002 Review URL: https://codereview.chromium.org/1664613002
Diffstat (limited to 'src/gpu/GrNonAtomicRef.h')
-rw-r--r--src/gpu/GrNonAtomicRef.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/gpu/GrNonAtomicRef.h b/src/gpu/GrNonAtomicRef.h
index efa2881c5f..e1503bcf06 100644
--- a/src/gpu/GrNonAtomicRef.h
+++ b/src/gpu/GrNonAtomicRef.h
@@ -15,15 +15,18 @@
* A simple non-atomic ref used in the GrBackend when we don't want to pay for the overhead of a
* threadsafe ref counted object
*/
-class GrNonAtomicRef : public SkNoncopyable {
+template<typename TSubclass> class GrNonAtomicRef : public SkNoncopyable {
public:
GrNonAtomicRef() : fRefCnt(1) {}
- virtual ~GrNonAtomicRef() {
+
+#ifdef SK_DEBUG
+ ~GrNonAtomicRef() {
// fRefCnt can be one when a subclass is created statically
SkASSERT((0 == fRefCnt || 1 == fRefCnt));
// Set to invalid values.
- SkDEBUGCODE(fRefCnt = -10;)
+ fRefCnt = -10;
}
+#endif
void ref() const {
// Once the ref cnt reaches zero it should never be ref'ed again.
@@ -35,7 +38,7 @@ public:
SkASSERT(fRefCnt > 0);
--fRefCnt;
if (0 == fRefCnt) {
- delete this;
+ GrTDeleteNonAtomicRef(static_cast<const TSubclass*>(this));
return;
}
}
@@ -46,4 +49,8 @@ private:
typedef SkNoncopyable INHERITED;
};
+template<typename T> inline void GrTDeleteNonAtomicRef(const T* ref) {
+ delete ref;
+}
+
#endif