| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkRefCnt_DEFINED | 8 #ifndef SkRefCnt_DEFINED |
| 9 #define SkRefCnt_DEFINED | 9 #define SkRefCnt_DEFINED |
| 10 | 10 |
| 11 #include "../private/SkAtomics.h" | 11 #include "../private/SkAtomics.h" |
| 12 #include "../private/SkUniquePtr.h" |
| 12 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 13 #include <memory> | |
| 14 | 14 |
| 15 /** \class SkRefCntBase | 15 /** \class SkRefCntBase |
| 16 | 16 |
| 17 SkRefCntBase is the base class for objects that may be shared by multiple | 17 SkRefCntBase is the base class for objects that may be shared by multiple |
| 18 objects. When an existing owner wants to share a reference, it calls ref(). | 18 objects. When an existing owner wants to share a reference, it calls ref(). |
| 19 When an owner wants to release its reference, it calls unref(). When the | 19 When an owner wants to release its reference, it calls unref(). When the |
| 20 shared object's reference count goes to zero as the result of an unref() | 20 shared object's reference count goes to zero as the result of an unref() |
| 21 call, its (virtual) destructor is called. It is an error for the | 21 call, its (virtual) destructor is called. It is an error for the |
| 22 destructor to be called explicitly (or via the object going out of scope on | 22 destructor to be called explicitly (or via the object going out of scope on |
| 23 the stack or calling delete) if getRefCnt() > 1. | 23 the stack or calling delete) if getRefCnt() > 1. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 /////////////////////////////////////////////////////////////////////////////// | 179 /////////////////////////////////////////////////////////////////////////////// |
| 180 | 180 |
| 181 template <typename T> struct SkTUnref { | 181 template <typename T> struct SkTUnref { |
| 182 void operator()(T* t) { t->unref(); } | 182 void operator()(T* t) { t->unref(); } |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 /** | 185 /** |
| 186 * Utility class that simply unref's its argument in the destructor. | 186 * Utility class that simply unref's its argument in the destructor. |
| 187 */ | 187 */ |
| 188 template <typename T> class SkAutoTUnref : public std::unique_ptr<T, SkTUnref<T>
> { | 188 template <typename T> class SkAutoTUnref : public skstd::unique_ptr<T, SkTUnref<
T>> { |
| 189 public: | 189 public: |
| 190 explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr<T, SkTUnref<T>>(ob
j) {} | 190 explicit SkAutoTUnref(T* obj = nullptr) : skstd::unique_ptr<T, SkTUnref<T>>(
obj) {} |
| 191 | 191 |
| 192 T* detach() { return this->release(); } | 192 T* detach() { return this->release(); } |
| 193 operator T*() const { return this->get(); } | 193 operator T*() const { return this->get(); } |
| 194 }; | 194 }; |
| 195 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( | 195 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
| 196 | 196 |
| 197 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 197 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
| 198 public: | 198 public: |
| 199 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 199 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
| 200 }; | 200 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 221 delete (const Derived*)this; | 221 delete (const Derived*)this; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 void deref() const { this->unref(); } | 224 void deref() const { this->unref(); } |
| 225 | 225 |
| 226 private: | 226 private: |
| 227 mutable int32_t fRefCnt; | 227 mutable int32_t fRefCnt; |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 #endif | 230 #endif |
| OLD | NEW |