cds  2.2.0
cds::gc::DHP Class Reference

Dynamic Hazard Pointer garbage collector. More...

#include <cds/gc/dhp.h>

Data Structures

class  Guard
 Dynamic Hazard Pointer guard. More...
 
class  GuardArray
 Array of Dynamic Hazard Pointer guards. More...
 
class  guarded_ptr
 Guarded pointer. More...
 
class  thread_gc
 Thread-level garbage collector. More...
 

Public Types

typedef void * guarded_pointer
 Native guarded pointer type.
 
template<typename T >
using atomic_ref = atomics::atomic< T * >
 Atomic reference.
 
template<typename T >
using atomic_type = atomics::atomic< T >
 Atomic type.
 
template<typename MarkedPtr >
using atomic_marked_ptr = atomics::atomic< MarkedPtr >
 Atomic marked pointer.
 
typedef dhp::ThreadGC thread_gc_impl
 Thread GC implementation for internal usage.
 

Public Member Functions

 DHP (size_t nLiberateThreshold=1024, size_t nInitialThreadGuardCount=8, size_t nEpochCount=16)
 Initializes DHP memory manager singleton. More...
 
 ~DHP ()
 Destroys DHP memory manager. More...
 

Static Public Member Functions

static constexpr bool check_available_guards (size_t nCountNeeded, bool=true)
 Checks if count of hazard pointer is no less than nCountNeeded. More...
 
template<typename T >
static void retire (T *p, void(*pFunc)(T *))
 Retire pointer p with function pFunc. More...
 
template<class Disposer , typename T >
static void retire (T *p)
 Retire pointer p with functor of type Disposer. More...
 
static bool isUsed ()
 Checks if Dynamic Hazard Pointer GC is constructed and may be used.
 
static void scan ()
 Forced GC cycle call for current thread. More...
 
static void force_dispose ()
 Synonym for scan()
 

Detailed Description

Dynamic Hazard Pointer garbage collector.

Implementation of Dynamic Hazard Pointer garbage collector.

Sources:

  • [2002] Maged M.Michael "Safe memory reclamation for dynamic lock-freeobjects using atomic reads and writes"
  • [2003] Maged M.Michael "Hazard Pointers: Safe memory reclamation for lock-free objects"
  • [2004] Andrei Alexandrescy, Maged Michael "Lock-free Data Structures with Hazard Pointers"

Dynamic Hazard Pointers SMR (safe memory reclamation) provides an unbounded number of hazard pointer per thread despite of classic Hazard Pointer SMR in which the count of the hazard pointef per thread is limited.

See How to use section for details how to apply garbage collector.

Constructor & Destructor Documentation

§ DHP()

cds::gc::DHP::DHP ( size_t  nLiberateThreshold = 1024,
size_t  nInitialThreadGuardCount = 8,
size_t  nEpochCount = 16 
)
inline

Initializes DHP memory manager singleton.

Constructor creates and initializes DHP global object. DHP object should be created before using CDS data structure based on cds::gc::DHP GC. Usually, it is created in the main() function. After creating of global object you may use CDS data structures based on cds::gc::DHP.

Parameters
  • nLiberateThreshold - scan() threshold. When count of retired pointers reaches this value, the scan() member function would be called for freeing retired pointers.
  • nInitialThreadGuardCount - initial count of guard allocated for each thread. When a thread is initialized the GC allocates local guard pool for the thread from common guard pool. By perforce the local thread's guard pool is grown automatically from common pool. When the thread terminated its guard pool is backed to common GC's pool.
  • nEpochCount: internally, DHP memory manager uses epoch-based schema to solve ABA problem for internal data. nEpochCount specifies the epoch count, i.e. the count of simultaneously working threads that remove the elements of DHP-based concurrent data structure. Default value is 16.

§ ~DHP()

cds::gc::DHP::~DHP ( )
inline

Destroys DHP memory manager.

The destructor destroys DHP global object. After calling of this function you may NOT use CDS data structures based on cds::gc::DHP. Usually, DHP object is destroyed at the end of your main().

Member Function Documentation

§ check_available_guards()

static constexpr bool cds::gc::DHP::check_available_guards ( size_t  nCountNeeded,
bool  = true 
)
inlinestatic

Checks if count of hazard pointer is no less than nCountNeeded.

The function always returns true since the guard count is unlimited for gc::DHP garbage collector.

§ retire() [1/2]

template<typename T >
static void cds::gc::DHP::retire ( T *  p,
void(*)(T *)  pFunc 
)
inlinestatic

Retire pointer p with function pFunc.

The function places pointer p to array of pointers ready for removing. (so called retired pointer array). The pointer can be safely removed when no guarded pointer points to it. Deleting the pointer is the function pFunc call.

§ retire() [2/2]

template<class Disposer , typename T >
static void cds::gc::DHP::retire ( T *  p)
inlinestatic

Retire pointer p with functor of type Disposer.

The function places pointer p to array of pointers ready for removing. (so called retired pointer array). The pointer can be safely removed when no guarded pointer points to it.

See gc::HP::retire for Disposer requirements.

§ scan()

static void cds::gc::DHP::scan ( )
static

Forced GC cycle call for current thread.

Usually, this function should not be called directly.


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

cds 2.2.0 Developed by Maxim Khizhinsky aka khizmax 2007 - 2017
Autogenerated Wed Jan 4 2017 08:49:48 by Doxygen 1.8.12