|
constexpr | atomic_ref () noexcept |
| Construct an empty atomic_ref.
|
|
| atomic_ref (ref< T > ptr) |
| Construct a new atomic_ref object.
|
|
atomic_ref & | operator= (const ref< T > &other) |
| Assignment operator.
|
|
atomic_ref & | operator= (ref< T > &&other) |
| Move assignment operator.
|
|
atomic_ref & | operator= (const atomic_ref< T > &other) noexcept(noexcept(refcounted_add_ref(std::declval< T * >())) &&noexcept(refcounted_remove_ref(std::declval< T * >()))) |
| Assignment operator.
|
|
atomic_ref & | operator= (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.
|
|
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
-
T | Type of the reference counted class |