Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkNVRefCnt< Derived > Class Template Reference

#include <SkRefCnt.h>

Public Member Functions

 SkNVRefCnt ()
 
 ~SkNVRefCnt ()
 
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 
bool refCntGreaterThan (int32_t threadIsolatedTestCnt) const
 

Detailed Description

template<typename Derived>
class SkNVRefCnt< Derived >

Definition at line 160 of file SkRefCnt.h.

Constructor & Destructor Documentation

◆ SkNVRefCnt()

template<typename Derived >
SkNVRefCnt< Derived >::SkNVRefCnt ( )
inline

Definition at line 162 of file SkRefCnt.h.

162: fRefCnt(1) {}

◆ ~SkNVRefCnt()

template<typename Derived >
SkNVRefCnt< Derived >::~SkNVRefCnt ( )
inline

Definition at line 163 of file SkRefCnt.h.

163 {
164 #ifdef SK_DEBUG
165 int rc = fRefCnt.load(std::memory_order_relaxed);
166 SkASSERTF(rc == 1, "NVRefCnt was %d", rc);
167 #endif
168 }
#define SkASSERTF(cond, fmt,...)
Definition: SkAssert.h:117

Member Function Documentation

◆ deref()

template<typename Derived >
void SkNVRefCnt< Derived >::deref ( ) const
inline

Definition at line 184 of file SkRefCnt.h.

184{ this->unref(); }
void unref() const
Definition: SkRefCnt.h:177

◆ ref()

template<typename Derived >
void SkNVRefCnt< Derived >::ref ( ) const
inline

Definition at line 176 of file SkRefCnt.h.

176{ (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed); }

◆ refCntGreaterThan()

template<typename Derived >
bool SkNVRefCnt< Derived >::refCntGreaterThan ( int32_t  threadIsolatedTestCnt) const
inline

Definition at line 191 of file SkRefCnt.h.

191 {
192 int cnt = fRefCnt.load(std::memory_order_acquire);
193 // If this fails then the above contract has been violated.
194 SkASSERT(cnt >= threadIsolatedTestCnt);
195 return cnt > threadIsolatedTestCnt;
196 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ unique()

template<typename Derived >
bool SkNVRefCnt< Derived >::unique ( ) const
inline

Definition at line 175 of file SkRefCnt.h.

175{ return 1 == fRefCnt.load(std::memory_order_acquire); }

◆ unref()

template<typename Derived >
void SkNVRefCnt< Derived >::unref ( ) const
inline

Definition at line 177 of file SkRefCnt.h.

177 {
178 if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
179 // restore the 1 for our destructor's assert
180 SkDEBUGCODE(fRefCnt.store(1, std::memory_order_relaxed));
181 delete (const Derived*)this;
182 }
183 }
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()

The documentation for this class was generated from the following file: