libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
RefCount Class Reference

An atomic reference count object. More...

#include <sharedptr.h>

Public Member Functions

 RefCount ()
 Constructs a reference count initialized to 1.
 
 RefCount (const RefCount &o)
 Copy constructor resets the reference count to 1 for the new object.
 
RefCountoperator= (const RefCount &)
 Copy assignment resets the reference count to 1.
 
void inc ()
 Atomically increments the reference count.
 
bool dec ()
 Atomically decrements the reference count.
 
int value () const
 Returns the current reference count value.
 
bool isImmortal () const
 Returns true if this refcount is immortal (will never reach zero).
 
void setImmortal ()
 Marks this refcount as immortal. inc/dec become no-ops.
 

Static Public Attributes

static constexpr int Immortal = 0x40000000
 Threshold at or above which the refcount is considered immortal.
 

Detailed Description

An atomic reference count object.

Since it's atomic, operations are guaranteed to be consistent across threads. This also means there's going to be an increased cost over a simple reference count. However, this is generally still faster than any locking semantics that would be required to syncronize data between threads.

Member Function Documentation

◆ dec()

bool RefCount::dec ( )
inline

Atomically decrements the reference count.

Returns
True if the count has reached zero (caller should delete the object).

Returns false for immortal objects (never deleted).

◆ inc()

void RefCount::inc ( )
inline

Atomically increments the reference count.

No-op for immortal objects. Uses relaxed memory ordering since only the atomic increment itself needs to be consistent.


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