cds
2.3.2
|
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) | |
Guard & | operator= (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. | |
Guard & | operator= (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 > | |
T | protect (atomics::atomic< T > const &toGuard) |
Protects a pointer of type atomic<T*> More... | |
template<typename T , class Func > | |
T | 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. | |
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:
link()
and move assignment is supported.Due to performance reason the implementation does not check state of the guard in runtime.
|
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.
|
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.
Move assignment: the internal guards are swapped between src
and this
.
src
will become in unlinked state if this
was unlinked on entry.
|
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
|
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:
Really, the result of f( toGuard.load())
is assigned to the hazard pointer.