From: khizmax Date: Mon, 17 Nov 2014 10:46:19 +0000 (+0300) Subject: Remove ugly reinterpret_cast from HP GC X-Git-Tag: v2.0.0~77 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7e76f730857417d3413a4b0d1fcb77378a57ed02;p=libcds.git Remove ugly reinterpret_cast from HP GC --- diff --git a/cds/gc/details/retired_ptr.h b/cds/gc/details/retired_ptr.h index 850451e1..1df4422a 100644 --- a/cds/gc/details/retired_ptr.h +++ b/cds/gc/details/retired_ptr.h @@ -5,6 +5,7 @@ #include +//@cond namespace cds { namespace gc { /// Common implementation details for any GC namespace details { @@ -20,7 +21,10 @@ namespace cds { namespace gc { /// Pointer type typedef void * pointer; - pointer m_p; ///< retired pointer + union { + pointer m_p; ///< retired pointer + uintptr_t m_n; + }; free_retired_ptr_func m_funcFree; ///< pointer to the destructor function /// Comparison of two retired pointers @@ -37,14 +41,14 @@ namespace cds { namespace gc { /// Ctor retired_ptr( pointer p, free_retired_ptr_func func ) CDS_NOEXCEPT - : m_p( p ), - m_funcFree( func ) + : m_p( p ) + , m_funcFree( func ) {} /// Typecasting ctor template retired_ptr( T * p, void (* pFreeFunc)(T *)) CDS_NOEXCEPT - : m_p( reinterpret_cast( p ) ) + : m_p( reinterpret_cast(p)) , m_funcFree( reinterpret_cast< free_retired_ptr_func >( pFreeFunc )) {} @@ -68,7 +72,6 @@ namespace cds { namespace gc { } }; - //@cond static inline bool operator <( const retired_ptr& p1, const retired_ptr& p2 ) CDS_NOEXCEPT { return retired_ptr::less( p1, p2 ); @@ -83,8 +86,8 @@ namespace cds { namespace gc { { return !(p1 == p2); } - //@endcond } // namespace details }} // namespace cds::gc +//@endcond #endif // #ifndef __CDS_GC_DETAILS_RETIRED_PTR_H diff --git a/src/hp_gc.cpp b/src/hp_gc.cpp index f256dee7..05b5f748 100644 --- a/src/hp_gc.cpp +++ b/src/hp_gc.cpp @@ -218,7 +218,7 @@ namespace cds { namespace gc { details::retired_vector::iterator itRetired = pRec->m_arrRetired.begin(); details::retired_vector::iterator itRetiredEnd = pRec->m_arrRetired.end(); for ( auto it = itRetired; it != itRetiredEnd; ++it ) { - if ( reinterpret_cast(it->m_p) & 1 ) { + if ( it->m_n & 1 ) { // found a pointer with LSB bit set - use classic_scan classic_scan( pRec ); return; @@ -241,7 +241,7 @@ namespace cds { namespace gc { details::retired_vector::iterator it = std::lower_bound( itRetired, itRetiredEnd, dummyRetired, cds::gc::details::retired_ptr::less ); if ( it != itRetiredEnd && it->m_p == hptr ) { // Mark retired pointer as guarded - it->m_p = reinterpret_cast(reinterpret_cast(it->m_p) | 1); + it->m_n |= 1; } } } @@ -251,11 +251,12 @@ namespace cds { namespace gc { // Move all marked pointers to head of array { - details::retired_vector::iterator itInsert = itRetired; + auto itInsert = itRetired; for ( auto it = itRetired; it != itRetiredEnd; ++it ) { - if ( reinterpret_cast(it->m_p) & 1 ) { - it->m_p = reinterpret_cast(reinterpret_cast(it->m_p) & ~1); - *itInsert = *it; + if ( it->m_n & 1 ) { + it->m_n &= ~1; + if ( itInsert != it ) + *itInsert = *it; ++itInsert; CDS_HAZARDPTR_STATISTIC( ++m_Stat.m_DeferredNode ); }