OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::thread_unsafe_refcount Class Reference

implements a simple reference count for objects. More...

#include <rc.hpp>

Public Member Functions

 thread_unsafe_refcount () noexcept
 Construct a new thread unsafe refcount::thread unsafe refcount object.
 
void operator++ () noexcept
 Increment ref count by 1.
 
olong operator-- () noexcept
 Decrement ref count by 1.
 
bool inc_if_nonzero () noexcept
 Increments refcount by 1 if refcount is not 0, returns true if it incremented refcount.
 
olong use_count () const noexcept
 Returns the internal use count.
 

Static Public Member Functions

static constexpr bool is_thread_safe ()
 Returns false for this type.
 

Private Member Functions

 thread_unsafe_refcount (const thread_unsafe_refcount &)=delete
 
thread_unsafe_refcountoperator= (const thread_unsafe_refcount &)=delete
 

Private Attributes

olong rc
 The reference count, platform efficient integer type.
 

Detailed Description

implements a simple reference count for objects.

The purpose of thread_unsafe_refcount is to keep track of how many references exist to an object and automatically delete the object when the reference count reaches zero. It provides methods to increment, decrement, and read the current reference count.

thread_unsafe_refcount contains a member variable rc which holds the current reference count number as a type olong. Overall, thread_unsafe_refcount provides simple reference counting functionality to track object references in a single-threaded context. It could be used to implement basic automatic memory management based on scope and references for objects.

Definition at line 640 of file rc.hpp.

Constructor & Destructor Documentation

◆ thread_unsafe_refcount() [1/2]

openvpn::thread_unsafe_refcount::thread_unsafe_refcount ( )
inlinenoexcept

Construct a new thread unsafe refcount::thread unsafe refcount object.

initializes rc to 0 for a new object with no references.

Definition at line 671 of file rc.hpp.

◆ thread_unsafe_refcount() [2/2]

openvpn::thread_unsafe_refcount::thread_unsafe_refcount ( const thread_unsafe_refcount )
privatedelete

Member Function Documentation

◆ inc_if_nonzero()

bool openvpn::thread_unsafe_refcount::inc_if_nonzero ( )
inlinenoexcept

Increments refcount by 1 if refcount is not 0, returns true if it incremented refcount.

Returns
true if the ref count was incremented
false if the ref count was not incremented

Definition at line 693 of file rc.hpp.

◆ is_thread_safe()

constexpr bool openvpn::thread_unsafe_refcount::is_thread_safe ( )
inlinestaticconstexpr

Returns false for this type.

Returns
false

This allows a uniform way to check at compile time or runtime and determine if the refcount type is thread safe or not. This one is not.

Definition at line 718 of file rc.hpp.

◆ operator++()

void openvpn::thread_unsafe_refcount::operator++ ( )
inlinenoexcept

Increment ref count by 1.

Definition at line 676 of file rc.hpp.

◆ operator--()

olong openvpn::thread_unsafe_refcount::operator-- ( )
inlinenoexcept

Decrement ref count by 1.

Returns
olong

Definition at line 684 of file rc.hpp.

◆ operator=()

thread_unsafe_refcount & openvpn::thread_unsafe_refcount::operator= ( const thread_unsafe_refcount )
privatedelete

◆ use_count()

olong openvpn::thread_unsafe_refcount::use_count ( ) const
inlinenoexcept

Returns the internal use count.

Returns
olong ref count

Definition at line 707 of file rc.hpp.

Member Data Documentation

◆ rc

olong openvpn::thread_unsafe_refcount::rc
private

The reference count, platform efficient integer type.

Definition at line 664 of file rc.hpp.


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