Base module

RefCounted

Base class for intrusive reference counting.

RefCounted

#include <icy/memory.h>

Subclassed by: PacketTransaction< Message >, Context< uv_pipe_t >, Context< uv_tcp_t >, Context< uv_udp_t >, Context< uv_idle_t >, Context< uv_process_t >, Context< uv_async_t >, Context< uv_timer_t >

Base class for intrusive reference counting.

Embeds the refcount in the object itself - no separate control block allocation, no atomic operations. Safe for single-threaded libuv loops.

Usage: inherit from RefCounted, then use IntrusivePtr instead of std::shared_ptr.

Public Methods

ReturnNameDescription
RefCountedDefaulted constructor.
RefCounted inline
voidaddRef const inlineIncrements the reference count. Called by IntrusivePtr on acquisition.
boolreleaseRef const inlineDecrements the reference count.
intrefCount const inlineReturns the current reference count.

RefCounted

RefCounted() = default

Defaulted constructor.


RefCounted

inline

inline RefCounted(const RefCounted &) noexcept

addRef

const inline

inline void addRef() const noexcept

Increments the reference count. Called by IntrusivePtr on acquisition.


releaseRef

const inline

inline bool releaseRef() const noexcept

Decrements the reference count.

Returns

true if the count reached zero (caller should delete the object).


refCount

const inline

inline int refCount() const noexcept

Returns the current reference count.

Returns

Current reference count.

Private Attributes

ReturnNameDescription
int_refCount

_refCount

int _refCount = 0