cds
2.3.2
|
Dynamic (adaptie) Hazard Pointer SMR. 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... | |
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::stat | stat |
Internal statistics. | |
Public Member Functions | |
DHP (size_t nInitialHazardPtrCount=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,) |
Checks if count of hazard pointer is no less than nCountNeeded . More... | |
static void | set_memory_allocator (void *(*alloc_func)(size_t size), void(*free_func)(void *p)) |
Set memory management functions. More... | |
template<typename T > | |
static void | retire (T *p, void(*func)(void *)) |
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() | |
static void | statistics (stat &st) |
Returns internal statistics. More... | |
static CDS_EXPORT_API stat const & | postmortem_statistics () |
Returns post-mortem statistics. More... | |
Dynamic (adaptie) Hazard Pointer SMR.
Implementation of Dynamic (adaptive) Hazard Pointer SMR
Sources:
DHP is an adaptive variant of classic cds::gc::HP
, see Compare HP implementation
cds::intrusive::TaggedFreeList
and more complicated CAS-based free-list cds::intrusive::FreeList
. For x86 architecture and GCC/clang, libcds selects appropriate free-list based on -mcx16
compiler flag. You may manually disable DCAS support specifying -DCDS_DISABLE_128BIT_ATOMIC
for 64bit build or -DCDS_DISABLE_64BIT_ATOMIC
for 32bit build in compiler command line. All your projects and libcds MUST be compiled with the same flags - either with DCAS support or without it. For MS VC++ compiler DCAS is not supported.See How to use section for details how to apply SMR.
|
inlineexplicit |
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
. Usually, it is created in the beginning of main()
function. After creating of global object you may use CDS data structures based on cds::gc::DHP
.
nInitialThreadGuardCount
- initial count of guard allocated for each thread. When a thread is initialized the GC allocates local guard pool for the thread from a 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.
nInitialHazardPtrCount | Initial number of hazard pointer per thread |
|
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()
.
|
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.
|
static |
Returns post-mortem statistics.
Post-mortem statistics is gathered in the DHP
object destructor and can be accessible after destructing the global DHP
object.
libcds
and your program with -DCDS_ENABLE_HPSTAT
.Usage:
|
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 hazard pointer points to it. func
is a disposer: when p
can be safely removed, func
is called.
|
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 hazard pointer points to it.
Deleting the pointer is an invocation of some object of type Disposer
; the interface of Disposer
is:
Since the functor call can happen at any time after retire()
call, additional restrictions are imposed to Disposer
type:
p
should not depend on where the functor will be called.delete
functor: Functor based on std::allocator
:
|
inlinestatic |
Forced GC cycle call for current thread.
Usually, this function should not be called directly.
|
inlinestatic |
Set memory management functions.
SMR object allocates some memory for thread-specific data and for creating SMR object. By default, a standard new
and delete
operators are used for this.
alloc_func | malloc() function |
free_func | free() function |
|
inlinestatic |
Returns internal statistics.
The function clears st
before gathering statistics.
libcds
and your program with -DCDS_ENABLE_HPSTAT
.