cycle_ptr
Public Types | Public Member Functions | Friends | List of all members
cycle_ptr::detail::hazard_ptr< T > Class Template Reference

Hazard pointer. More...

#include <hazard.h>

Public Types

using element_type = T
 Element type of the pointer.
 
using pointer = typename hazard_t::pointer
 Smart pointer equivalent.
 
using value_type = pointer
 Type held in this atomic.
 

Public Member Functions

auto is_lock_free () const noexcept -> bool
 Test if this instance is lock free.
 
auto is_lock_free () const volatile noexcept -> bool
 Test if this instance is lock free.
 
 hazard_ptr () noexcept=default
 Default constructor initializes to nullptr.
 
 hazard_ptr (const hazard_ptr &p) noexcept
 Copy construction.
 
 hazard_ptr (hazard_ptr &&p) noexcept
 Move construction.
 
 hazard_ptr (pointer &&p) noexcept
 Initializing constructor. More...
 
 hazard_ptr (const pointer &p) noexcept
 Initializing constructor. More...
 
 ~hazard_ptr () noexcept
 Destructor. More...
 
auto operator= (const hazard_ptr &p) noexcept -> pointer
 Copy assignment. More...
 
auto operator= (hazard_ptr &&p) noexcept -> pointer
 Move assignment. More...
 
auto operator= (const pointer &p) noexcept -> pointer
 Copy assignment. More...
 
auto operator= (pointer &&p) noexcept -> pointer
 Move assignment. More...
 
auto operator= ([[maybe_unused]] const std::nullptr_t nil) noexcept -> pointer
 nullptr assignment. More...
 
auto reset () noexcept -> void
 Reset this. More...
 
auto reset ([[maybe_unused]] std::nullptr_t nil) noexcept -> void
 Reset this. More...
 
auto reset (pointer &&p) noexcept -> void
 Assignment. More...
 
auto reset (const pointer &p) noexcept -> void
 Assignment. More...
 
 operator pointer () const noexcept
 Automatic conversion to pointer.
 
auto get () const noexcept -> pointer
 Read the value of this. More...
 
auto load () const noexcept -> pointer
 Read the value of this. More...
 
auto store (pointer &&p) noexcept -> void
 Assignment. More...
 
auto store (const pointer &p) noexcept -> void
 Assignment. More...
 
auto exchange (pointer &&p) noexcept -> pointer
 Exchange operation. More...
 
auto exchange (const pointer &p) noexcept -> pointer
 Exchange operation. More...
 
auto compare_exchange_weak (pointer &expected, pointer desired) noexcept -> bool
 Weak compare-exchange operation.
 
auto compare_exchange_strong (pointer &expected, pointer desired) noexcept -> bool
 Strong compare-exchange operation.
 

Friends

auto operator== (const hazard_ptr &x, std::nullptr_t y) noexcept -> bool
 Equality comparison.
 
auto operator== (const hazard_ptr &x, std::add_const_t< T > *y) noexcept -> bool
 Equality comparison.
 
template<typename U >
auto operator== (const hazard_ptr &x, const intrusive_ptr< U > &y) noexcept -> std::enable_if_t< std::is_convertible_v< U *, T * >, bool >
 Equality comparison.
 
auto operator== (std::nullptr_t x, const hazard_ptr &y) noexcept -> bool
 Equality comparison.
 
auto operator== (std::add_const_t< T > *x, const hazard_ptr &y) noexcept -> bool
 Equality comparison.
 
template<typename U >
auto operator== (const intrusive_ptr< U > &x, const hazard_ptr &y) noexcept -> std::enable_if_t< std::is_convertible_v< U *, T * >, bool >
 Equality comparison.
 
auto operator!= (const hazard_ptr &x, std::nullptr_t y) noexcept -> bool
 Inequality comparison.
 
auto operator!= (const hazard_ptr &x, std::add_const_t< T > *y) noexcept -> bool
 Inequality comparison.
 
template<typename U >
auto operator!= (const hazard_ptr &x, const intrusive_ptr< U > &y) noexcept -> std::enable_if_t< std::is_convertible_v< U *, T * >, bool >
 Inequality comparison.
 
auto operator!= (std::nullptr_t x, const hazard_ptr &y) noexcept -> bool
 Inequality comparison.
 
auto operator!= (std::add_const_t< T > *x, const hazard_ptr &y) noexcept -> bool
 Inequality comparison.
 
template<typename U >
auto operator!= (const intrusive_ptr< U > &x, const hazard_ptr &y) noexcept -> std::enable_if_t< std::is_convertible_v< U *, T * >, bool >
 Inequality comparison.
 

Detailed Description

template<typename T>
class cycle_ptr::detail::hazard_ptr< T >

Hazard pointer.

Implements an atomic, reference-counted pointer.

Uses the same rules as intrusive_ptr with regards to acquiring and releasing reference counter.

See also
intrusive_ptr
hazard

Constructor & Destructor Documentation

◆ hazard_ptr() [1/2]

template<typename T>
cycle_ptr::detail::hazard_ptr< T >::hazard_ptr ( pointer &&  p)
inlinenoexcept

Initializing constructor.

Postcondition
*this == original value of p.
p == nullptr

◆ hazard_ptr() [2/2]

template<typename T>
cycle_ptr::detail::hazard_ptr< T >::hazard_ptr ( const pointer p)
inlinenoexcept

Initializing constructor.

Postcondition
*this == p

◆ ~hazard_ptr()

template<typename T>
cycle_ptr::detail::hazard_ptr< T >::~hazard_ptr ( )
inlinenoexcept

Destructor.

Releases the held pointer.

Member Function Documentation

◆ exchange() [1/2]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::exchange ( pointer &&  p) -> pointer
inlinenoexcept

Exchange operation.

Parameters
pNew value of this.
Returns
Original value of this.
Postcondition
*this == original value of p
p == nullptr

◆ exchange() [2/2]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::exchange ( const pointer p) -> pointer
inlinenoexcept

Exchange operation.

Parameters
pNew value of this.
Returns
Original value of this.
Postcondition
*this == p

◆ get()

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::get ( ) const -> pointer
inlinenoexcept

Read the value of this.

Marked [[nodiscard]], as there's no point in reading the pointer if you're not going to evaluate it.

Returns
Pointer in this.

◆ load()

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::load ( ) const -> pointer
inlinenoexcept

Read the value of this.

Marked [[nodiscard]], as there's no point in reading the pointer if you're not going to evaluate it.

Returns
Pointer in this.

◆ operator=() [1/5]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::operator= ( const hazard_ptr< T > &  p) -> pointer
inlinenoexcept

Copy assignment.

Returns
p.get()
Postcondition
*this ==

◆ operator=() [2/5]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::operator= ( hazard_ptr< T > &&  p) -> pointer
inlinenoexcept

Move assignment.

Returns
p.get()
Postcondition
*this == original value of p
p == nullptr

◆ operator=() [3/5]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::operator= ( const pointer p) -> pointer
inlinenoexcept

Copy assignment.

Returns
p
Postcondition
*this == p

◆ operator=() [4/5]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::operator= ( pointer &&  p) -> pointer
inlinenoexcept

Move assignment.

Returns
p
Postcondition
*this == original value of p
p == nullptr

◆ operator=() [5/5]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::operator= ( [[maybe_unused] ] const std::nullptr_t  nil) -> pointer
inlinenoexcept

nullptr assignment.

Returns
pointer(nullptr)
Postcondition
*this == nullptr

◆ reset() [1/4]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::reset ( ) -> void
inlinenoexcept

Reset this.

Postcondition
*this == nullptr

◆ reset() [2/4]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::reset ( [[maybe_unused] ] std::nullptr_t  nil) -> void
inlinenoexcept

Reset this.

Postcondition
*this == nullptr

◆ reset() [3/4]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::reset ( pointer &&  p) -> void
inlinenoexcept

Assignment.

Postcondition
*this == original value of p
p == nullptr

◆ reset() [4/4]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::reset ( const pointer p) -> void
inlinenoexcept

Assignment.

Postcondition
*this == p

◆ store() [1/2]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::store ( pointer &&  p) -> void
inlinenoexcept

Assignment.

Postcondition
*this == original value of p
p == nullptr

◆ store() [2/2]

template<typename T>
auto cycle_ptr::detail::hazard_ptr< T >::store ( const pointer p) -> void
inlinenoexcept

Assignment.

Postcondition
*this == p

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