Skip to content

Commit

Permalink
rename smr to basic_smr
Browse files Browse the repository at this point in the history
  • Loading branch information
Krock21 committed Jul 13, 2020
1 parent 1325754 commit 155586f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions cds/gc/dhp.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace cds { namespace gc {
}

// no free block
// smr::scan() extend retired_array if needed
// basic_smr::scan() extend retired_array if needed
return false;
}

Expand All @@ -325,7 +325,7 @@ namespace cds { namespace gc {
return ret;
}

private: // called by smr
private: // called by basic_smr
void init()
{
if ( list_head_ == nullptr ) {
Expand Down Expand Up @@ -479,7 +479,7 @@ namespace cds { namespace gc {
struct thread_record;

public:
/// Returns the instance of Hazard Pointer \ref smr
/// Returns the instance of Hazard Pointer \ref basic_smr
static smr& instance()
{
# ifdef CDS_DISABLE_SMR_EXCEPTION
Expand Down Expand Up @@ -517,7 +517,7 @@ namespace cds { namespace gc {
construct( nInitialHazardPtrCount );
}

/// Destroys global instance of \ref smr
/// Destroys global instance of \ref basic_smr
/**
The parameter \p bDetachAll should be used carefully: if its value is \p true,
then the object destroyed automatically detaches all attached threads. This feature
Expand Down
26 changes: 13 additions & 13 deletions cds/gc/hp.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,20 @@ namespace cds { namespace gc {
};
//@endcond

/// \p smr::scan() strategy
/// \p basic_smr::scan() strategy
enum scan_type {
classic, ///< classic scan as described in Michael's works (see smr::classic_scan())
inplace ///< inplace scan without allocation (see smr::inplace_scan())
classic, ///< classic scan as described in Michael's works (see basic_smr::classic_scan())
inplace ///< inplace scan without allocation (see basic_smr::inplace_scan())
};

//@cond
/// Hazard Pointer SMR (Safe Memory Reclamation)
class smr {
class basic_smr {
struct thread_record;

public:
/// Returns the instance of Hazard Pointer \ref smr
static smr &instance() {
/// Returns the instance of Hazard Pointer \ref basic_smr
static basic_smr &instance() {
# ifdef CDS_DISABLE_SMR_EXCEPTION
assert( instance_ != nullptr );
# else
Expand Down Expand Up @@ -401,7 +401,7 @@ namespace cds { namespace gc {
construct(nHazardPtrCount, nMaxThreadCount, nMaxRetiredPtrCount, nScanType);
}

/// Destroys global instance of \ref smr
/// Destroys global instance of \ref basic_smr
/**
The parameter \p bDetachAll should be used carefully: if its value is \p true,
then the object destroyed automatically detaches all attached threads. This feature
Expand Down Expand Up @@ -511,14 +511,14 @@ namespace cds { namespace gc {
CDS_EXPORT_API void help_scan(thread_data *pThis);

private:
CDS_EXPORT_API smr(
CDS_EXPORT_API basic_smr(
size_t nHazardPtrCount, ///< Hazard pointer count per thread
size_t nMaxThreadCount, ///< Max count of simultaneous working thread in your application
size_t nMaxRetiredPtrCount, ///< Capacity of the array of retired objects for the thread
scan_type nScanType ///< Scan type (see \ref scan_type enum)
);

CDS_EXPORT_API ~smr();
CDS_EXPORT_API ~basic_smr();

CDS_EXPORT_API void detach_all_thread();

Expand Down Expand Up @@ -567,23 +567,23 @@ namespace cds { namespace gc {
CDS_EXPORT_API void free_thread_data(thread_record *pRec, bool callHelpScan);

private:
static CDS_EXPORT_API smr *instance_;
static CDS_EXPORT_API basic_smr *instance_;

atomics::atomic<thread_record *> thread_list_; ///< Head of thread list

size_t const hazard_ptr_count_; ///< max count of thread's hazard pointer
size_t const max_thread_count_; ///< max count of thread
size_t const max_retired_ptr_count_; ///< max count of retired ptr per thread
scan_type const scan_type_; ///< scan type (see \ref scan_type enum)
void ( smr::*scan_func_ )(thread_data *pRec);
void ( basic_smr::*scan_func_ )(thread_data *pRec);
};
//@endcond

} // namespace details

//@cond
// for backward compatibility
typedef details::smr smr;
typedef details::basic_smr smr;
typedef smr GarbageCollector;
//@endcond
} // namespace hp
Expand Down Expand Up @@ -1467,7 +1467,7 @@ namespace cds { namespace gc {
} // namespace cds::gc::details

typedef details::HP HP;
typedef hp::details::smr smr;
typedef hp::details::basic_smr smr;
}} // namespace cds::gc

#endif // #ifndef CDSLIB_GC_HP_SMR_H
Expand Down
44 changes: 22 additions & 22 deletions src/hp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ namespace cds { namespace gc { namespace hp { namespace details {
stat s_postmortem_stat;
} // namespace

/*static*/ CDS_EXPORT_API smr* smr::instance_ = nullptr;
/*static*/ CDS_EXPORT_API basic_smr* basic_smr::instance_ = nullptr;
thread_local thread_data* tls_ = nullptr;

/*static*/ CDS_EXPORT_API thread_data* smr::tls()
/*static*/ CDS_EXPORT_API thread_data* basic_smr::tls()
{
assert( tls_ != nullptr );
return tls_;
}

struct smr::thread_record: thread_data
struct basic_smr::thread_record: thread_data
{
// next hazard ptr record in list
thread_record* next_ = nullptr;
Expand All @@ -140,7 +140,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
{}
};

/*static*/ CDS_EXPORT_API void smr::set_memory_allocator(
/*static*/ CDS_EXPORT_API void basic_smr::set_memory_allocator(
void* ( *alloc_func )( size_t size ),
void( *free_func )( void * p )
)
Expand All @@ -153,36 +153,36 @@ namespace cds { namespace gc { namespace hp { namespace details {
}


/*static*/ CDS_EXPORT_API void smr::construct( size_t nHazardPtrCount, size_t nMaxThreadCount, size_t nMaxRetiredPtrCount, scan_type nScanType )
/*static*/ CDS_EXPORT_API void basic_smr::construct(size_t nHazardPtrCount, size_t nMaxThreadCount, size_t nMaxRetiredPtrCount, scan_type nScanType )
{
if ( !instance_ ) {
instance_ = new( s_alloc_memory(sizeof(smr))) smr( nHazardPtrCount, nMaxThreadCount, nMaxRetiredPtrCount, nScanType );
instance_ = new( s_alloc_memory(sizeof(basic_smr))) basic_smr(nHazardPtrCount, nMaxThreadCount, nMaxRetiredPtrCount, nScanType );
}
}

/*static*/ CDS_EXPORT_API void smr::destruct( bool bDetachAll )
/*static*/ CDS_EXPORT_API void basic_smr::destruct(bool bDetachAll )
{
if ( instance_ ) {
if ( bDetachAll )
instance_->detach_all_thread();

instance_->~smr();
instance_->~basic_smr();
s_free_memory( instance_ );
instance_ = nullptr;
}
}

CDS_EXPORT_API smr::smr( size_t nHazardPtrCount, size_t nMaxThreadCount, size_t nMaxRetiredPtrCount, scan_type nScanType )
CDS_EXPORT_API basic_smr::basic_smr(size_t nHazardPtrCount, size_t nMaxThreadCount, size_t nMaxRetiredPtrCount, scan_type nScanType )
: hazard_ptr_count_( nHazardPtrCount == 0 ? defaults::c_nHazardPointerPerThread : nHazardPtrCount )
, max_thread_count_( nMaxThreadCount == 0 ? defaults::c_nMaxThreadCount : nMaxThreadCount )
, max_retired_ptr_count_( calc_retired_size( nMaxRetiredPtrCount, hazard_ptr_count_, max_thread_count_ ))
, scan_type_( nScanType )
, scan_func_( nScanType == classic ? &smr::classic_scan : &smr::inplace_scan )
, scan_func_( nScanType == classic ? &basic_smr::classic_scan : &basic_smr::inplace_scan )
{
thread_list_.store( nullptr, atomics::memory_order_release );
}

CDS_EXPORT_API smr::~smr()
CDS_EXPORT_API basic_smr::~basic_smr()
{
CDS_DEBUG_ONLY( const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; )
CDS_DEBUG_ONLY( const cds::OS::ThreadId mainThreadId = cds::OS::get_current_thread_id();)
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
}


CDS_EXPORT_API smr::thread_record* smr::create_thread_data()
CDS_EXPORT_API basic_smr::thread_record* basic_smr::create_thread_data()
{
size_t const guard_array_size = thread_hp_storage::calc_array_size( get_hazard_ptr_count());
size_t const retired_array_size = retired_array::calc_array_size( get_max_retired_ptr_count());
Expand Down Expand Up @@ -248,7 +248,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
);
}

/*static*/ CDS_EXPORT_API void smr::destroy_thread_data( thread_record* pRec )
/*static*/ CDS_EXPORT_API void basic_smr::destroy_thread_data(thread_record* pRec )
{
// all retired pointers must be freed
assert( pRec->retired_.size() == 0 );
Expand All @@ -258,7 +258,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
}


CDS_EXPORT_API smr::thread_record* smr::alloc_thread_data()
CDS_EXPORT_API basic_smr::thread_record* basic_smr::alloc_thread_data()
{
thread_record * hprec;
const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId;
Expand Down Expand Up @@ -286,7 +286,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
return hprec;
}

CDS_EXPORT_API void smr::free_thread_data( smr::thread_record* pRec, bool callHelpScan )
CDS_EXPORT_API void basic_smr::free_thread_data(basic_smr::thread_record* pRec, bool callHelpScan )
{
assert( pRec != nullptr );

Expand All @@ -297,7 +297,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
pRec->thread_id_.store( cds::OS::c_NullThreadId, atomics::memory_order_release );
}

CDS_EXPORT_API void smr::detach_all_thread()
CDS_EXPORT_API void basic_smr::detach_all_thread()
{
thread_record * pNext = nullptr;
const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId;
Expand All @@ -310,13 +310,13 @@ namespace cds { namespace gc { namespace hp { namespace details {
}
}

/*static*/ CDS_EXPORT_API void smr::attach_thread()
/*static*/ CDS_EXPORT_API void basic_smr::attach_thread()
{
if ( !tls_ )
tls_ = instance().alloc_thread_data();
}

/*static*/ CDS_EXPORT_API void smr::detach_thread()
/*static*/ CDS_EXPORT_API void basic_smr::detach_thread()
{
thread_data* rec = tls_;
if ( rec ) {
Expand All @@ -326,7 +326,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
}


CDS_EXPORT_API void smr::inplace_scan( thread_data* pThreadRec )
CDS_EXPORT_API void basic_smr::inplace_scan(thread_data* pThreadRec )
{
thread_record* pRec = static_cast<thread_record*>( pThreadRec );

Expand Down Expand Up @@ -415,7 +415,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
}

// cppcheck-suppress functionConst
CDS_EXPORT_API void smr::classic_scan( thread_data* pThreadRec )
CDS_EXPORT_API void basic_smr::classic_scan(thread_data* pThreadRec )
{
thread_record* pRec = static_cast<thread_record*>( pThreadRec );

Expand Down Expand Up @@ -469,7 +469,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
}
}

CDS_EXPORT_API void smr::help_scan( thread_data* pThis )
CDS_EXPORT_API void basic_smr::help_scan(thread_data* pThis )
{
assert( static_cast<thread_record*>( pThis )->thread_id_.load( atomics::memory_order_relaxed ) == cds::OS::get_current_thread_id());

Expand Down Expand Up @@ -520,7 +520,7 @@ namespace cds { namespace gc { namespace hp { namespace details {
}
}

CDS_EXPORT_API void smr::statistics( stat& st )
CDS_EXPORT_API void basic_smr::statistics(stat& st )
{
st.clear();
# ifdef CDS_ENABLE_HPSTAT
Expand Down

0 comments on commit 155586f

Please sign in to comment.