cds  2.3.2
cds::gc::DHP::guarded_ptr< GuardedType, ValueType, Cast > Class Template Reference

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_ptroperator= (guarded_ptr &&gp) noexcept
 Move-assignment operator.
 
guarded_ptroperator= (Guard &&g) noexcept
 Move-assignment from Guard.
 
guarded_ptroperator= (guarded_ptr const &gp)=delete
 The guarded pointer is not copy-assignable.
 
value_typeoperator-> () const noexcept
 Returns a pointer to guarded value.
 
value_typeoperator* () 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...
 

Detailed Description

template<typename GuardedType, typename ValueType = GuardedType, typename Cast = void>
class cds::gc::DHP::guarded_ptr< GuardedType, ValueType, Cast >

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 stores
  • ValueType - a value type
  • Cast - 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:

typedef cds::gc::DHP::guarded_ptr< foo > intrusive_guarded_ptr;

For standard (non-intrusive) containers GuardedType is not the same as ValueType and casting is needed. For example:

struct foo {
int const key;
std::string value;
};
struct value_accessor {
std::string* operator()( foo* pFoo ) const
{
return &(pFoo->value);
}
};
// Guarded ptr

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.

Constructor & Destructor Documentation

◆ ~guarded_ptr()

template<typename GuardedType , typename ValueType = GuardedType, typename Cast = void>
cds::gc::DHP::guarded_ptr< GuardedType, ValueType, Cast >::~guarded_ptr ( )
inlinenoexcept

Clears the guarded pointer.

release is called if guarded pointer is not empty

Member Function Documentation

◆ release()

template<typename GuardedType , typename ValueType = GuardedType, typename Cast = void>
void cds::gc::DHP::guarded_ptr< GuardedType, ValueType, Cast >::release ( )
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.


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