Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::atomic_ref< T > Class Template Reference

Thread safe reference handle. More...

#include <asyncpp/ref.h>

Public Member Functions

constexpr atomic_ref () noexcept
 Construct an empty atomic_ref.
 
 atomic_ref (ref< T > ptr)
 Construct a new atomic_ref object.
 
atomic_refoperator= (const ref< T > &other)
 Assignment operator.
 
atomic_refoperator= (ref< T > &&other)
 Move assignment operator.
 
atomic_refoperator= (const atomic_ref< T > &other) noexcept(noexcept(refcounted_add_ref(std::declval< T * >())) &&noexcept(refcounted_remove_ref(std::declval< T * >())))
 Assignment operator.
 
atomic_refoperator= (atomic_ref< T > &&other) noexcept(noexcept(refcounted_remove_ref(std::declval< T * >())))
 Move assignment operator.
 
 ~atomic_ref () noexcept(noexcept(refcounted_remove_ref(std::declval< T * >())))
 Destructor.
 
ref< T > load () const noexcept(noexcept(refcounted_add_ref(std::declval< T * >())))
 Get the contained value.
 
void store (ref< T > hdl)
 Store a new value and destroy the old one.
 
void store (const atomic_ref< T > &hdl)
 Store a new value and destroy the old one.
 
ref< T > exchange (ref< T > hdl)
 Reset the handle with a new value.
 
ref< T > exchange (const atomic_ref< T > &hdl)
 Reset the handle with a new value.
 
T * release () noexcept
 Release the contained pointer.
 
void reset () noexcept(noexcept(refcounted_remove_ref(std::declval< T * >())))
 Reset the pointer to nullptr.
 
 operator bool () const noexcept
 Check if the handle contains a pointer.
 
bool operator! () const noexcept
 Check if the handle contains no pointer.
 
ref< T > operator-> () const noexcept(noexcept(refcounted_add_ref(std::declval< T * >())))
 Dereference this handle.
 

Friends

template<RefCountable T2>
constexpr auto operator<=> (const atomic_ref< T2 > &lhs, const atomic_ref< T2 > &rhs) noexcept
 
template<RefCountable T2>
constexpr auto operator<=> (const atomic_ref< T2 > &lhs, const T2 *rhs) noexcept
 
template<RefCountable T2>
constexpr auto operator<=> (const T2 *lhs, const atomic_ref< T2 > &rhs) noexcept
 

Detailed Description

template<RefCountable T>
class asyncpp::atomic_ref< T >

Thread safe reference handle.

atomic_ref is similar to ref but allows for thread safe assignment and read. It is similar to std::atomic<std::shared_ptr<>>. Note that atomic_ref is not lock free, it uses the upmost bit of the pointer as a locking flag. This allows for a small size (identical to raw pointer) and does not need direct access to the reference count. The downside is that it effectively serializes all access regardless of reading/writing.

Template Parameters
TType of the reference counted class

Constructor & Destructor Documentation

◆ atomic_ref()

template<RefCountable T>
asyncpp::atomic_ref< T >::atomic_ref ( ref< T > ptr)
inline

Construct a new atomic_ref object.

Parameters
ptrThe pointer to store
Exceptions
std::logic_errorif the pointer value collides with the lock_mask

Member Function Documentation

◆ exchange() [1/2]

template<RefCountable T>
ref< T > asyncpp::atomic_ref< T >::exchange ( const atomic_ref< T > & hdl)
inline

Reset the handle with a new value.

Parameters
hdlThe new pointer

◆ exchange() [2/2]

template<RefCountable T>
ref< T > asyncpp::atomic_ref< T >::exchange ( ref< T > hdl)
inline

Reset the handle with a new value.

Parameters
hdlThe new pointer
Returns
The old value of this handle
Exceptions
std::logic_errorif the pointer value collides with the lock_mask

◆ store() [1/2]

template<RefCountable T>
void asyncpp::atomic_ref< T >::store ( const atomic_ref< T > & hdl)
inline

Store a new value and destroy the old one.

Parameters
hdlThe new pointer

◆ store() [2/2]

template<RefCountable T>
void asyncpp::atomic_ref< T >::store ( ref< T > hdl)
inline

Store a new value and destroy the old one.

Parameters
hdlThe new pointer
Exceptions
std::logic_errorif the pointer value collides with the lock_mask

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