8#ifndef SkRefCnt_DEFINED
9#define SkRefCnt_DEFINED
41 SkASSERTF(this->getRefCnt() == 1,
"fRefCnt was %d", this->getRefCnt());
43 fRefCnt.store(0, std::memory_order_relaxed);
51 if (1 == fRefCnt.load(std::memory_order_acquire)) {
65 (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed);
75 if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
78 this->internal_dispose();
86 int32_t getRefCnt()
const {
87 return fRefCnt.load(std::memory_order_relaxed);
97 fRefCnt.store(1, std::memory_order_relaxed);
106 mutable std::atomic<int32_t> fRefCnt;
114#ifdef SK_REF_CNT_MIXIN_INCLUDE
117#include SK_REF_CNT_MIXIN_INCLUDE
121 #if defined(SK_BUILD_FOR_GOOGLE3)
123 void deref()
const { this->unref(); }
132template <
typename T>
static inline T*
SkRef(
T* obj) {
159template <
typename Derived>
165 int rc = fRefCnt.load(std::memory_order_relaxed);
175 bool unique()
const {
return 1 == fRefCnt.load(std::memory_order_acquire); }
176 void ref()
const { (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); }
178 if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
180 SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed));
181 delete (
const Derived*)
this;
192 int cnt = fRefCnt.load(std::memory_order_acquire);
194 SkASSERT(cnt >= threadIsolatedTestCnt);
195 return cnt > threadIsolatedTestCnt;
199 mutable std::atomic<int32_t> fRefCnt;
224 constexpr sk_sp() : fPtr(nullptr) {}
225 constexpr sk_sp(std::nullptr_t) : fPtr(nullptr) {}
232 template <
typename U,
242 template <
typename U,
273 template <
typename U,
286 this->
reset(that.release());
289 template <
typename U,
292 this->
reset(that.release());
301 explicit operator bool()
const {
return this->
get() !=
nullptr; }
303 T*
get()
const {
return fPtr; }
332 swap(fPtr, that.fPtr);
346 return a.get() ==
b.get();
356 return a.get() !=
b.get();
359 return static_cast<bool>(
a);
362 return static_cast<bool>(
b);
365template <
typename C,
typename CT,
typename T>
367 return os << sp.get();
370template <
typename T,
typename... Args>
#define SkASSERTF(cond, fmt,...)
sk_sp< T > sk_make_sp(Args &&... args)
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
static void SkSafeUnref(T *obj)
static T * SkSafeRef(T *obj)
sk_sp< T > sk_ref_sp(T *obj)
auto operator<<(std::basic_ostream< C, CT > &os, const sk_sp< T > &sp) -> decltype(os<< sp.get())
bool operator==(const sk_sp< T > &a, const sk_sp< U > &b)
void swap(sk_sp< T > &a, sk_sp< T > &b)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
bool refCntGreaterThan(int32_t threadIsolatedTestCnt) const
virtual void internal_dispose() const
void swap(sk_sp< T > &that)
sk_sp< T > & operator=(sk_sp< T > &&that)
std::true_type sk_is_trivially_relocatable
sk_sp< T > & operator=(sk_sp< U > &&that)
sk_sp< T > & operator=(const sk_sp< U > &that)
sk_sp(const sk_sp< U > &that)
sk_sp< T > & operator=(const sk_sp< T > &that)
sk_sp< T > & operator=(std::nullptr_t)
constexpr sk_sp(std::nullptr_t)
void reset(T *ptr=nullptr)
sk_sp(const sk_sp< T > &that)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const myers::Point & get(const myers::Segment &)