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

Unified Diff: src/gpu/GrNonAtomicRef.h

Issue 1664613002: Templatize GrNonAtomicRef (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | src/gpu/GrPipeline.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrNonAtomicRef.h
diff --git a/src/gpu/GrNonAtomicRef.h b/src/gpu/GrNonAtomicRef.h
index efa2881c5f49a34cd553ccb291b4c638277b7745..e1503bcf06e16936e463e79d243f3db7b1739203 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
« no previous file with comments | « no previous file | src/gpu/GrPipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698