#include <cds/gc/dhp/dhp_impl.h>
#include <cds/details/lib.h>
+//@cond
namespace cds { namespace gc {
typedef PTB DHP;
}} // namespace cds::gc
+//@endcond
#endif // #ifndef __CDS_GC_DHP_H
//@cond
namespace cds {
- namespace gc { namespace hzp {
+ namespace gc { namespace hp {
/// Hazard Pointer schema implementation details
namespace details {
//@endcond
};
- }}} // namespace gc::hzp::details
+ }}} // namespace gc::hp::details
} // namespace cds
//@endcond
#define __CDS_GC_HP_DETAILS_HP_FWD_H
namespace cds {
- namespace gc { namespace hzp {
+ namespace gc { namespace hp {
// forward declarations
class GarbageCollector;
#define __CDS_GC_HP_DETAILS_HP_INLINE_H
namespace cds {
- namespace gc{ namespace hzp { namespace details {
+ namespace gc{ namespace hp { namespace details {
/************************************************************************/
/* INLINES */
/************************************************************************/
- inline retired_vector::retired_vector( const cds::gc::hzp::GarbageCollector& HzpMgr )
+ inline retired_vector::retired_vector( const cds::gc::hp::GarbageCollector& HzpMgr )
: m_arr( HzpMgr.getMaxRetiredPtrCount() ),
m_nSize(0)
{}
- inline HPRec::HPRec( const cds::gc::hzp::GarbageCollector& HzpMgr )
+ inline HPRec::HPRec( const cds::gc::hp::GarbageCollector& HzpMgr )
: m_hzp( HzpMgr.getHazardPointerCount() ),
m_arrRetired( HzpMgr )
{}
- } } } // namespace gc::hzp::details
+ } } } // namespace gc::hp::details
} // namespace cds
#include <cds/details/bounded_array.h>
namespace cds {
- namespace gc{ namespace hzp { namespace details {
+ namespace gc{ namespace hp { namespace details {
/// Retired pointer
typedef cds::gc::details::retired_ptr retired_ptr;
typedef retired_vector_impl::iterator iterator;
/// Constructor
- retired_vector( const cds::gc::hzp::GarbageCollector& HzpMgr ) ; // inline
+ retired_vector( const cds::gc::hp::GarbageCollector& HzpMgr ); // inline
~retired_vector()
{}
/// Vector capacity.
/**
- The capacity is constant for any thread. It is defined by cds::gc::hzp::GarbageCollector.
+ The capacity is constant for any thread. It is defined by cds::gc::hp::GarbageCollector.
*/
size_t capacity() const { return m_arr.capacity(); }
}
};
- } } } // namespace gc::hzp::details
+ } } } // namespace gc::hp::details
} // namespace cds
#endif // #ifndef __CDS_GC_HP_DETAILS_HP_RETIRED_H
namespace cds {
namespace gc {
- namespace hzp {
+ namespace hp {
/// Hazard pointer
typedef void * hazard_pointer;
#if CDS_COMPILER == CDS_COMPILER_MSVC
# pragma warning(push)
- // warning C4251: 'cds::gc::hzp::GarbageCollector::m_pListHead' : class 'cds::cxx11_atomic::atomic<T>'
- // needs to have dll-interface to be used by clients of class 'cds::gc::hzp::GarbageCollector'
+ // warning C4251: 'cds::gc::hp::GarbageCollector::m_pListHead' : class 'cds::cxx11_atomic::atomic<T>'
+ // needs to have dll-interface to be used by clients of class 'cds::gc::hp::GarbageCollector'
# pragma warning(disable: 4251)
#endif
- [2004] Andrei Alexandrescy, Maged Michael "Lock-free Data Structures with Hazard Pointers"
- The cds::gc::hzp namespace and its members are internal representation of Hazard Pointer GC and should not be used directly.
+ The cds::gc::hp namespace and its members are internal representation of Hazard Pointer GC and should not be used directly.
Use cds::gc::HP class in your code.
Hazard Pointer garbage collector is a singleton. The main user-level part of Hazard Pointer schema is
by contructing cds::gc::HP object in beginning of your main().
See cds::gc::HP class for explanation.
*/
- namespace hzp {
+ namespace hp {
namespace details {
/// Hazard pointer record of the thread
retired_vector m_arrRetired ; ///< Retired pointer array
/// Ctor
- HPRec( const cds::gc::hzp::GarbageCollector& HzpMgr ) ; // inline
+ HPRec( const cds::gc::hp::GarbageCollector& HzpMgr ); // inline
~HPRec()
{}
event_counter m_DeferredNode ; ///< Count of objects that cannot be deleted in Scan phase because of a hazard_pointer guards it
};
- /// Internal list of cds::gc::hzp::details::HPRec
+ /// Internal list of cds::gc::hp::details::HPRec
struct hplist_node: public details::HPRec
{
hplist_node * m_pNextNode ; ///< next hazard ptr record in list
/// Auto-managed array of hazard pointers
/**
- This class is wrapper around cds::gc::hzp::details::HPArray class.
+ This class is wrapper around cds::gc::hp::details::HPArray class.
\p Count is the size of HP array
*/
template <size_t Count>
ThreadGC& getGC() const { return m_mgr; }
};
- } // namespace hzp
+ } // namespace hp
}} // namespace cds::gc
// Inlines
{
public:
/// Native guarded pointer type
- typedef gc::hzp::hazard_pointer guarded_pointer;
+ typedef gc::hp::hazard_pointer guarded_pointer;
/// Atomic reference
/**
template <typename T> using atomic_type = atomics::atomic<T>;
/// Thread GC implementation for internal usage
- typedef hzp::ThreadGC thread_gc_impl;
+ typedef hp::ThreadGC thread_gc_impl;
- /// Wrapper for hzp::ThreadGC class
+ /// Wrapper for hp::ThreadGC class
/**
@headerfile cds/gc/hp.h
This class performs automatically attaching/detaching Hazard Pointer GC
/// Hazard Pointer guard
/**
@headerfile cds/gc/hp.h
- This class is a wrapper for hzp::AutoHPGuard.
+ This class is a wrapper for hp::AutoHPGuard.
*/
- class Guard: public hzp::AutoHPGuard
+ class Guard : public hp::AutoHPGuard
{
//@cond
- typedef hzp::AutoHPGuard base_class;
+ typedef hp::AutoHPGuard base_class;
//@endcond
public:
/// Array of Hazard Pointer guards
/**
@headerfile cds/gc/hp.h
- This class is a wrapper for hzp::AutoHPArray template.
+ This class is a wrapper for hp::AutoHPArray template.
Template parameter \p Count defines the size of HP array.
*/
template <size_t Count>
- class GuardArray: public hzp::AutoHPArray<Count>
+ class GuardArray : public hp::AutoHPArray<Count>
{
//@cond
- typedef hzp::AutoHPArray<Count> base_class;
+ typedef hp::AutoHPArray<Count> base_class;
//@endcond
public:
/// Rebind array for other size \p Count2
};
public:
- /// Initializes hzp::GarbageCollector singleton
+ /// Initializes hp::GarbageCollector singleton
/**
The constructor initializes GC singleton with passed parameters.
If GC instance is not exist then the function creates the instance.
size_t nHazardPtrCount = 0, ///< Hazard pointer count per thread
size_t nMaxThreadCount = 0, ///< Max count of simultaneous working thread in your application
size_t nMaxRetiredPtrCount = 0, ///< Capacity of the array of retired objects for the thread
- hzp::scan_type nScanType = hzp::inplace ///< Scan type (see \ref hzp::scan_type enum)
+ hp::scan_type nScanType = hp::inplace ///< Scan type (see \ref hp::scan_type enum)
)
{
- hzp::GarbageCollector::Construct(
+ hp::GarbageCollector::Construct(
nHazardPtrCount,
nMaxThreadCount,
nMaxRetiredPtrCount,
/// Terminates GC singleton
/**
- The destructor calls \code hzp::GarbageCollector::Destruct( true ) \endcode
+ The destructor calls \code hp::GarbageCollector::Destruct( true ) \endcode
*/
~HP()
{
- hzp::GarbageCollector::Destruct( true );
+ hp::GarbageCollector::Destruct( true );
}
/// Checks if count of hazard pointer is no less than \p nCountNeeded
*/
static bool check_available_guards( size_t nCountNeeded, bool bRaiseException = true )
{
- if ( hzp::GarbageCollector::instance().getHazardPointerCount() < nCountNeeded ) {
+ if ( hp::GarbageCollector::instance().getHazardPointerCount() < nCountNeeded ) {
if ( bRaiseException )
throw std::overflow_error( "Too few hazard pointers" );
return false;
/// Returns max Hazard Pointer count
size_t max_hazard_count() const
{
- return hzp::GarbageCollector::instance().getHazardPointerCount();
+ return hp::GarbageCollector::instance().getHazardPointerCount();
}
/// Returns max count of thread
size_t max_thread_count() const
{
- return hzp::GarbageCollector::instance().getMaxThreadCount();
+ return hp::GarbageCollector::instance().getMaxThreadCount();
}
/// Returns capacity of retired pointer array
size_t retired_array_capacity() const
{
- return hzp::GarbageCollector::instance().getMaxRetiredPtrCount();
+ return hp::GarbageCollector::instance().getMaxRetiredPtrCount();
}
/// Retire pointer \p p with function \p pFunc
static void retire( T * p ) ; // inline in hp_impl.h
/// Get current scan strategy
- hzp::scan_type getScanType() const
+ hp::scan_type getScanType() const
{
- return hzp::GarbageCollector::instance().getScanType();
+ return hp::GarbageCollector::instance().getScanType();
}
/// Set current scan strategy
void setScanType(
- hzp::scan_type nScanType ///< new scan strategy
+ hp::scan_type nScanType ///< new scan strategy
)
{
- hzp::GarbageCollector::instance().setScanType( nScanType );
+ hp::GarbageCollector::instance().setScanType( nScanType );
}
/// Checks if Hazard Pointer GC is constructed and may be used
static bool isUsed()
{
- return hzp::GarbageCollector::isUsed();
+ return hp::GarbageCollector::isUsed();
}
//---------------------------------------------------------------
// Hazard Pointers reclamation schema constants
- namespace hzp {
+ namespace hp {
// Max number of threads expected
static const size_t c_nMaxThreadCount = 100;
// Number of Hazard Pointers per thread
static const size_t c_nHazardPointerPerThread = 8;
- } // namespace hzp
+ } // namespace hp
} /* namespace gc */ } /* namespace cds */
#define CDS_HAZARDPTR_STATISTIC( _x ) if ( m_bStatEnabled ) { _x; }
namespace cds { namespace gc {
- namespace hzp {
+ namespace hp {
/// Max array size of retired pointers
static const size_t c_nMaxRetireNodeCount = c_nHazardPointerPerThread * c_nMaxThreadCount * 2;
}
- } //namespace hzp
+ } //namespace hp
}} // namespace cds::gc
#endif
-std::ostream& operator << (std::ostream& s, const cds::gc::hzp::GarbageCollector::InternalState& stat)
+std::ostream& operator << (std::ostream& s, const cds::gc::hp::GarbageCollector::InternalState& stat)
{
s << "\nHZP GC internal state:"
<< "\n\t\tHP record allocated=" << stat.nHPRecAllocated
{
if ( m_bPrintGCState ) {
{
- cds::gc::hzp::GarbageCollector::InternalState stat;
- std::cout << cds::gc::hzp::GarbageCollector::instance().getInternalState( stat ) << std::endl;
+ cds::gc::hp::GarbageCollector::InternalState stat;
+ std::cout << cds::gc::hp::GarbageCollector::instance().getInternalState( stat ) << std::endl;
}
}
}
CppUnitMini::TestCfg& cfg = CppUnitMini::TestCase::m_Cfg.get( "General" );
std::string strHZPScanStrategy = cfg.get( "HZP_scan_strategy", std::string("classic") );
if ( strHZPScanStrategy == "inplace" )
- hzpGC.setScanType( cds::gc::hzp::inplace );
+ hzpGC.setScanType( cds::gc::hp::inplace );
else if ( strHZPScanStrategy == "classic" )
- hzpGC.setScanType( cds::gc::hzp::classic );
+ hzpGC.setScanType( cds::gc::hp::classic );
else {
std::cout << "Error value of HZP_scan_strategy in General section of test config\n";
}
switch (hzpGC.getScanType()) {
- case cds::gc::hzp::inplace:
+ case cds::gc::hp::inplace:
std::cout << "Use in-place scan strategy for Hazard Pointer memory reclamation algorithm\n";
break;
- case cds::gc::hzp::classic:
+ case cds::gc::hp::classic:
std::cout << "Use classic scan strategy for Hazard Pointer memory reclamation algorithm\n";
break;
default:
}
if ( CppUnitMini::TestCase::m_bPrintGCState ) {
- cds::gc::hzp::GarbageCollector::InternalState stat;
- cds::gc::hzp::GarbageCollector::instance().getInternalState( stat );
+ cds::gc::hp::GarbageCollector::InternalState stat;
+ cds::gc::hp::GarbageCollector::instance().getInternalState( stat );
std::cout << "HP constants:"
<< "\n\tHP count per thread=" << stat.nHPCount