cds
2.3.2
|
Guarded pointer. More...
#include <cds/gc/dhp.h>
Public Types | |
typedef GuardedType | guarded_type |
Guarded type. | |
typedef ValueType | value_type |
Value type. | |
typedef std::conditional< std::is_same< Cast, void >::value, trivial_cast, Cast >::type | value_cast |
Functor for casting guarded_type to value_type . | |
Public Member Functions | |
guarded_ptr () noexcept | |
Creates empty guarded pointer. | |
guarded_ptr (guarded_ptr &&gp) noexcept | |
Move ctor. | |
template<typename GT , typename VT , typename C > | |
guarded_ptr (guarded_ptr< GT, VT, C > &&gp) noexcept | |
Move ctor. | |
guarded_ptr (Guard &&g) noexcept | |
Ctor from Guard . | |
guarded_ptr (guarded_ptr const &gp)=delete | |
The guarded pointer is not copy-constructible. | |
~guarded_ptr () noexcept | |
Clears the guarded pointer. More... | |
guarded_ptr & | operator= (guarded_ptr &&gp) noexcept |
Move-assignment operator. | |
guarded_ptr & | operator= (Guard &&g) noexcept |
Move-assignment from Guard . | |
guarded_ptr & | operator= (guarded_ptr const &gp)=delete |
The guarded pointer is not copy-assignable. | |
value_type * | operator-> () const noexcept |
Returns a pointer to guarded value. | |
value_type & | operator* () noexcept |
Returns a reference to guarded value. | |
value_type const & | operator* () const noexcept |
Returns const reference to guarded value. | |
bool | empty () const noexcept |
Checks if the guarded pointer is nullptr . | |
operator bool () const noexcept | |
bool operator returns !empty() | |
void | release () noexcept |
Clears guarded pointer. More... | |
Guarded pointer.
A guarded pointer is a pair of a pointer and GC's guard. Usually, it is used for returning a pointer to the item from an lock-free container. The guard prevents the pointer to be early disposed (freed) by GC. After destructing guarded_ptr
object the pointer can be disposed (freed) automatically at any time.
Template arguments:
GuardedType
- a type which the guard storesValueType
- a value typeCast
- a functor for converting GuardedType*
to ValueType*
. Default is void
(no casting).For intrusive containers, GuardedType
is the same as ValueType
and no casting is needed. In such case the guarded_ptr
is:
For standard (non-intrusive) containers GuardedType
is not the same as ValueType
and casting is needed. For example:
You don't need use this class directly. All set/map container classes from libcds
declare the typedef for guarded_ptr
with appropriate casting functor.
|
inlinenoexcept |
|
inlinenoexcept |
Clears guarded pointer.
If the guarded pointer has been released, the pointer can be disposed (freed) at any time. Dereferncing the guarded pointer after release()
is dangerous.