From a1254acdb344174e761f5061c820559dab64a74c Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 9 Sep 2015 06:48:29 -0700 Subject: Port uses of SkLazyPtr to SkOncePtr. This gives SkOncePtr a non-trivial destructor that uses std::default_delete by default. This is overrideable, as seen in SkColorTable. SK_DECLARE_STATIC_ONCE_PTR still just leaves its pointers hanging at EOP. BUG=skia: No public API changes. TBR=reed@google.com Review URL: https://codereview.chromium.org/1322933005 --- include/private/SkOncePtr.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'include/private') diff --git a/include/private/SkOncePtr.h b/include/private/SkOncePtr.h index 9af204bcb2..40bea1a4c3 100644 --- a/include/private/SkOncePtr.h +++ b/include/private/SkOncePtr.h @@ -9,22 +9,23 @@ #define SkOncePtr_DEFINED #include "SkAtomics.h" +#include "SkUniquePtr.h" -template class SkStaticOnce; +template class SkBaseOncePtr; // Use this to create a global static pointer that's intialized exactly once when you call get(). -#define SK_DECLARE_STATIC_ONCE_PTR(type, name) namespace {} static SkStaticOnce name +#define SK_DECLARE_STATIC_ONCE_PTR(type, name) namespace {} static SkBaseOncePtr name // Use this for a local or member pointer that's initialized exactly once when you call get(). -template +template > class SkOncePtr : SkNoncopyable { public: SkOncePtr() { sk_bzero(this, sizeof(*this)); } - - // SkOncePtr does not have a destructor and does not clean up the pointer. But you may, e.g. - // delete (T*)fOncePtr; - // SkSafeUnref((T*)fOncePtr); - // etc. + ~SkOncePtr() { + if (T* ptr = (T*)*this) { + Delete()(ptr); + } + } template T* get(const F& f) const { @@ -36,11 +37,11 @@ public: } private: - SkStaticOnce fOnce; + SkBaseOncePtr fOnce; }; /* TODO(mtklein): in next CL -typedef SkStaticOnce SkOnceFlag; +typedef SkBaseOncePtr SkOnceFlag; #define SK_DECLARE_STATIC_ONCE(name) namespace {} static SkOnceFlag name template @@ -52,7 +53,7 @@ inline void SkOnce(SkOnceFlag* once, const F& f) { // Implementation details below here! No peeking! template -class SkStaticOnce { +class SkBaseOncePtr { public: template T* get(const F& f) const { -- cgit v1.2.3