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

Unified Diff: include/core/SkRefCnt.h

Issue 741793002: Add SkNVRefCnt, prune down SkPicture's size (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: notes 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
Index: include/core/SkRefCnt.h
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 4da2fbbc936266662a4510b64a8ce3a9de921972..fd49cbea30b85e8b66d6607589e2eac7de325d9e 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -247,4 +247,21 @@ public:
};
#define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref)
tomhudson 2014/11/19 18:59:06 Can we put something like a short version of the C
mtklein 2014/11/19 19:19:14 Done.
+template <typename Derived>
+class SkNVRefCnt : SkNoncopyable {
+public:
+ SkNVRefCnt() : fRefCnt(1) {}
+
+ // 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;
+ // - ref() doesn't need any barrier;
+ // - unref() needs a release barrier, and an acquire if it's going to call delete.
+
+ 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); } }
+private:
+ mutable int32_t fRefCnt;
+};
+
#endif
« include/core/SkPicture.h ('K') | « include/core/SkPicture.h ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698