Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkRefCntBase Class Reference

SkRefCntBase is the base class for objects that may be shared by multiple objects. More...

#include <SkRefCnt.h>

Inheritance diagram for SkRefCntBase:
SkRefCnt GrCaps GrContext GrContextThreadSafeProxy GrShaderCaps SkBitmap::Allocator SkColorSpace SkColorTable SkDataTable SkDocument SkDrawFilter SkFlattenable SkFont SkICC SkImage SkLights SkPicture SkPixelRef SkPixelSerializer SkPngChunkReader SkROBuffer SkSurface

Public Member Functions

 SkRefCntBase ()
 Default construct, initializing the reference count to 1.
 
virtual ~SkRefCntBase ()
 Destruct, asserting that the reference count is 1.
 
int32_t getRefCnt () const
 Return the reference count. More...
 
void validate () const
 
bool unique () const
 May return true if the caller is the only owner. More...
 
void ref () const
 Increment the reference count. More...
 
void unref () const
 Decrement the reference count. More...
 

Protected Member Functions

void internal_dispose_restore_refcnt_to_1 () const
 Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More...
 

Private Types

typedef SkNoncopyable INHERITED
 

Private Member Functions

virtual void internal_dispose () const
 Called when the ref count goes to 0.
 

Private Attributes

std::atomic< int32_t > fRefCnt
 

Friends

class SkWeakRefCnt
 

Detailed Description

SkRefCntBase is the base class for objects that may be shared by multiple objects.

When an existing owner wants to share a reference, it calls ref(). When an owner wants to release its reference, it calls unref(). When the shared object's reference count goes to zero as the result of an unref() call, its (virtual) destructor is called. It is an error for the destructor to be called explicitly (or via the object going out of scope on the stack or calling delete) if getRefCnt() > 1.

Member Function Documentation

int32_t SkRefCntBase::getRefCnt ( ) const
inline

Return the reference count.

Use only for debugging.

void SkRefCntBase::internal_dispose_restore_refcnt_to_1 ( ) const
inlineprotected

Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g.

using a free list).

void SkRefCntBase::ref ( ) const
inline

Increment the reference count.

Must be balanced by a call to unref().

bool SkRefCntBase::unique ( ) const
inline

May return true if the caller is the only owner.

Ensures that all previous owner's actions are complete.

void SkRefCntBase::unref ( ) const
inline

Decrement the reference count.

If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.


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