cds  2.3.2
cds::gc::DHP::Guard Class Reference

Dynamic Hazard Pointer guard. More...

#include <cds/gc/dhp.h>

Public Member Functions

 Guard () noexcept
 Default ctor allocates a guard (hazard pointer) from thread-private storage.
 
 Guard (std::nullptr_t) noexcept
 Initilalizes an unlinked guard i.e. the guard contains no hazard pointer. Used for move semantics support.
 
 Guard (Guard &&src) noexcept
 Move ctor - src guard becomes unlinked (transfer internal guard ownership)
 
Guardoperator= (Guard &&src) noexcept
 Move assignment: the internal guards are swapped between src and this. More...
 
 Guard (Guard const &)=delete
 Copy ctor is prohibited - the guard is not copyable.
 
Guardoperator= (Guard const &)=delete
 Copy assignment is prohibited.
 
 ~Guard ()
 Frees the internal hazard pointer if the guard is in linked state.
 
bool is_linked () const
 Checks if the guard object linked with any internal hazard pointer.
 
void link ()
 Links the guard with internal hazard pointer if the guard is in unlinked state.
 
void unlink ()
 Unlinks the guard from internal hazard pointer; the guard becomes in unlinked state.
 
template<typename T >
protect (atomics::atomic< T > const &toGuard)
 Protects a pointer of type atomic<T*> More...
 
template<typename T , class Func >
protect (atomics::atomic< T > const &toGuard, Func f)
 Protects a converted pointer of type atomic<T*> More...
 
template<typename T >
T * assign (T *p)
 Store p to the guard. More...
 
template<typename T , int BITMASK>
T * assign (cds::details::marked_ptr< T, BITMASK > p)
 Store marked pointer p to the guard. More...
 
void copy (Guard const &src)
 Copy from src guard to this guard.
 
void clear ()
 Clears value of the guard.
 
template<typename T >
T * get () const
 Gets the value currently protected (relaxed read)
 
void * get_native () const
 Gets native guarded pointer stored.
 

Detailed Description

Dynamic Hazard Pointer guard.

A guard is a hazard pointer. Additionally, the Guard class manages allocation and deallocation of the hazard pointer

Guard object is movable but not copyable.

The guard object can be in two states:

  • unlinked - the guard is not linked with any internal hazard pointer. In this state no operation except link() and move assignment is supported.
  • linked (default) - the guard allocates an internal hazard pointer and fully operable.

Due to performance reason the implementation does not check state of the guard in runtime.

Warning
Move assignment can transfer the guard in unlinked state, use with care.

Member Function Documentation

◆ assign() [1/2]

template<typename T >
T* cds::gc::DHP::Guard::assign ( T *  p)
inline

Store p to the guard.

The function is just an assignment, no loop is performed. Can be used for a pointer that cannot be changed concurrently or for already guarded pointer.

◆ assign() [2/2]

template<typename T , int BITMASK>
T* cds::gc::DHP::Guard::assign ( cds::details::marked_ptr< T, BITMASK >  p)
inline

Store marked pointer p to the guard.

The function is just an assignment of p.ptr(), no loop is performed. Can be used for a marked pointer that cannot be changed concurrently or for already guarded pointer.

◆ operator=()

Guard& cds::gc::DHP::Guard::operator= ( Guard &&  src)
inlinenoexcept

Move assignment: the internal guards are swapped between src and this.

Warning
src will become in unlinked state if this was unlinked on entry.

◆ protect() [1/2]

template<typename T >
T cds::gc::DHP::Guard::protect ( atomics::atomic< T > const &  toGuard)
inline

Protects a pointer of type atomic<T*>

Return the value of toGuard

The function tries to load toGuard and to store it to the HP slot repeatedly until the guard's value equals toGuard

◆ protect() [2/2]

template<typename T , class Func >
T cds::gc::DHP::Guard::protect ( atomics::atomic< T > const &  toGuard,
Func  f 
)
inline

Protects a converted pointer of type atomic<T*>

Return the value of toGuard

The function tries to load toGuard and to store result of f functor to the HP slot repeatedly until the guard's value equals toGuard.

The function is useful for intrusive containers when toGuard is a node pointer that should be converted to a pointer to the value type before guarding. The parameter f of type Func is a functor that makes this conversion:

struct functor {
value_type * operator()( T * p );
};

Really, the result of f( toGuard.load()) is assigned to the hazard pointer.


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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:35 by Doxygen 1.8.13