cds  1.4.0
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
cds::gc::hrc::GarbageCollector Class Reference

Gidenstam's Garbage Collector. More...

#include <cds/gc/hrc/hrc.h>

Data Structures

struct  internal_state
 GC internal statistics. More...
 
struct  statistics
 Internal statistics by events. More...
 
struct  thread_list_node
 HRC control structure of global thread list. More...
 

Public Types

typedef
cds::atomicity::event_counter 
event_counter
 event counter type
 

Public Member Functions

 CDS_DECLARE_EXCEPTION (HRCGarbageCollectorEmpty,"Global cds::gc::hrc::GarbageCollector is NULL")
 "Global GC object is NULL" exception
 
 CDS_DECLARE_EXCEPTION (HRCTooMany,"Not enough required Hazard Pointer count")
 Not enough required Hazard Pointer count.
 
size_t getHazardPointerCount () const
 Get max count of hazard pointers as defined in Construct call.
 
size_t getMaxThreadCount () const
 Get max thread count as defined in Construct call.
 
size_t getMaxRetiredPtrCount () const
 Get max retired pointers count. It is calculated by the parameters of Construct call.
 
internal_stategetInternalState (internal_state &stat) const
 Get internal statistics.
 
bool isStatisticsEnabled () const
 Check if statistics enabled.
 
bool enableStatistics (bool bEnable)
 Enable internal statistics.
 
details::thread_descriptor * allocateHRCThreadDesc (ThreadGC *pThreadGC)
 Allocates HRC thread descriptor (thread interface)
 
void retireHRCThreadDesc (details::thread_descriptor *pRec)
 Retires HRC thread descriptor (thread interface)
 
void Scan (ThreadGC *pThreadGC)
 The main method of GC. More...
 
void HelpScan (ThreadGC *pThreadGC)
 Manage free thread_descriptor records and move all retired pointers to pThreadGC.
 
void CleanUpAll (ThreadGC *pThreadGC)
 Global clean up. More...
 

Static Public Member Functions

static void CDS_STDCALL Construct (size_t nHazardPtrCount=0, size_t nMaxThreadCount=0, size_t nMaxNodeLinkCount=0, size_t nMaxTransientLinks=0)
 Create global instance of GarbageCollector. More...
 
static void CDS_STDCALL Destruct ()
 Destroy global instance of GarbageCollector.
 
static GarbageCollectorinstance ()
 Get global instance of GarbageCollector.
 
static bool isUsed ()
 Checks if global GC object is constructed and may be used.
 
static void checkHPCount (unsigned int nRequiredCount)
 Checks that required hazard pointer count nRequiredCount is less or equal then max hazard pointer count. More...
 

Private Member Functions

thread_list_nodenewHRCThreadDesc ()
 Allocates new HRC control structure from the heap (using operator new)
 
void deleteHRCThreadDesc (thread_list_node *pNode)
 Deletes pNode control structure.
 
void clearHRCThreadDesc (thread_list_node *pNode)
 Clears retired nodes of pNode control structure.
 
thread_list_nodegetHRCThreadDescForCurrentThread () const
 Finds HRC control structure for current thread.
 

Private Attributes

std::atomic< thread_list_node * > m_pListHead
 Head of thread list.
 
statistics m_Stat
 Internal statistics.
 
bool m_bStatEnabled
 true - accumulate internal statistics
 
const size_t m_nHazardPointerCount
 max count of thread's hazard pointer
 
const size_t m_nMaxThreadCount
 max count of thread
 
const size_t m_nMaxRetiredPtrCount
 max count of retired ptr per thread
 

Static Private Attributes

static GarbageCollectorm_pGC
 HRC garbage collector instance.
 

Detailed Description

Gidenstam's Garbage Collector.

This GC combines Hazard Pointers (HP) reclamation method by Michael's and the well-known reference counting reclamation schema. The HP method is light-weight algorithm guarding local references only. Reference counting schema is harder than HP with relation to the performance but can guard global references too. Using Gidenstam's GC it can be possible to safely introduce to the lock-free data structures very useful concepts like iterators.

GarbageCollector is the singleton.

Member Function Documentation

static void cds::gc::hrc::GarbageCollector::checkHPCount ( unsigned int  nRequiredCount)
inlinestatic

Checks that required hazard pointer count nRequiredCount is less or equal then max hazard pointer count.

If nRequiredCount > getHazardPointerCount() then the exception HZPTooMany is thrown

void cds::gc::hrc::GarbageCollector::CleanUpAll ( ThreadGC pThreadGC)

Global clean up.

The procedure try to remove redundant claimed references from links in deleted nodes that has been deleted by any thread. pThreadGC - ThreadGC of calling thread

static void CDS_STDCALL cds::gc::hrc::GarbageCollector::Construct ( size_t  nHazardPtrCount = 0,
size_t  nMaxThreadCount = 0,
size_t  nMaxNodeLinkCount = 0,
size_t  nMaxTransientLinks = 0 
)
static

Create global instance of GarbageCollector.

Parameters
nHazardPtrCountnumber of hazard pointers
nMaxThreadCountmax threads count
nMaxNodeLinkCountmax number of links a ContainerNode can contain
nMaxTransientLinksmax number of links in live nodes that may transiently point to a deleted node
void cds::gc::hrc::GarbageCollector::Scan ( ThreadGC pThreadGC)

The main method of GC.

The procedure searches through all not yet reclaimed nodes deleted by this thread and reclaim only those that does not have any matching hazard pointers and do not have any counted references from any links inside of nodes. Scan is called in context of thread owned pRec.


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

cds 1.4.0 Developed by Maxim Khiszinsky aka khizmax 2007 - 2012
Autogenerated Mon May 20 2013 00:37:58 by Doxygen 1.8.3.1