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

Implements a memory fenced ref count. More...

#include <rc.hpp>

Public Member Functions

 thread_safe_refcount () noexcept
 Construct a new thread safe refcount object.
 
void operator++ () noexcept
 Atomically increment the refcount by 1.
 
olong operator-- () noexcept
 Atomically decrement the internal counter by 1.
 
bool inc_if_nonzero () noexcept
 Atomically 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 true for this class.
 

Private Member Functions

 thread_safe_refcount (const thread_safe_refcount &)=delete
 
thread_safe_refcountoperator= (const thread_safe_refcount &)=delete
 

Private Attributes

std::atomic< olongrc
 

Detailed Description

Implements a memory fenced ref count.

Definition at line 761 of file rc.hpp.

Constructor & Destructor Documentation

◆ thread_safe_refcount() [1/2]

openvpn::thread_safe_refcount::thread_safe_refcount ( )
inlinenoexcept

Construct a new thread safe refcount object.

Definition at line 790 of file rc.hpp.

◆ thread_safe_refcount() [2/2]

openvpn::thread_safe_refcount::thread_safe_refcount ( const thread_safe_refcount )
privatedelete

Member Function Documentation

◆ inc_if_nonzero()

bool openvpn::thread_safe_refcount::inc_if_nonzero ( )
inlinenoexcept

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

Returns
true if refcount was incremented
false if refcount was not incremented

If refcount is 0, do nothing and return false. If refcount != 0, increment it and return true.

Definition at line 820 of file rc.hpp.

◆ is_thread_safe()

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

Returns true for this class.

Returns
true

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 thread safe.

Definition at line 847 of file rc.hpp.

◆ operator++()

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

Atomically increment the refcount by 1.

Definition at line 797 of file rc.hpp.

◆ operator--()

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

Atomically decrement the internal counter by 1.

Returns
olong decremented ref count

Definition at line 805 of file rc.hpp.

◆ operator=()

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

◆ use_count()

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

Returns the internal use count.

Returns
olong ref count

Definition at line 836 of file rc.hpp.

Member Data Documentation

◆ rc

std::atomic<olong> openvpn::thread_safe_refcount::rc
private

Definition at line 785 of file rc.hpp.


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