From: khizmax Date: Sat, 29 Nov 2014 11:26:46 +0000 (+0300) Subject: Improving gc:HP and gc::DHP guards X-Git-Tag: v2.0.0~42 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=05a8e3ae98f1d73bdd8ba23f9d72ede428a36e34;p=libcds.git Improving gc:HP and gc::DHP guards --- diff --git a/cds/gc/details/dhp.h b/cds/gc/details/dhp.h index ee689bee..8f177c37 100644 --- a/cds/gc/details/dhp.h +++ b/cds/gc/details/dhp.h @@ -557,20 +557,12 @@ namespace cds { namespace gc { { typedef details::guard base_class; friend class ThreadGC; - - ThreadGC& m_gc ; ///< ThreadGC object of current thread public: /// Allocates a guard from \p gc GC. \p gc must be ThreadGC object of current thread - Guard( ThreadGC& gc ); + Guard(); // inline in dhp_impl.h /// Returns guard allocated back to pool of free guards - ~Guard(); // inline after GarbageCollector - - /// Returns DHP GC object - ThreadGC& getGC() CDS_NOEXCEPT - { - return m_gc; - } + ~Guard(); // inline in dhp_impl.h /// Guards pointer \p p template @@ -594,7 +586,6 @@ namespace cds { namespace gc { class GuardArray { details::guard m_arr[Count] ; ///< array of guard - ThreadGC& m_gc ; ///< ThreadGC object of current thread const static size_t c_nCapacity = Count ; ///< Array capacity (equal to \p Count template parameter) public: @@ -606,16 +597,16 @@ namespace cds { namespace gc { public: /// Allocates array of guards from \p gc which must be the ThreadGC object of current thread - GuardArray( ThreadGC& gc ); // inline below - - /// The object is not default-constructible - GuardArray() = delete; + GuardArray(); // inline in dhp_impl.h /// The object is not copy-constructible GuardArray( GuardArray const& ) = delete; + /// The object is not move-constructible + GuardArray( GuardArray&& ) = delete; + /// Returns guards allocated back to pool - ~GuardArray(); // inline below + ~GuardArray(); // inline in dh_impl.h /// Returns the capacity of array CDS_CONSTEXPR size_t capacity() const CDS_NOEXCEPT @@ -623,12 +614,6 @@ namespace cds { namespace gc { return c_nCapacity; } - /// Returns DHP ThreadGC object - ThreadGC& getGC() CDS_NOEXCEPT - { - return m_gc; - } - /// Returns reference to the guard of index \p nIndex (0 <= \p nIndex < \p Count) details::guard& operator []( size_t nIndex ) CDS_NOEXCEPT { @@ -983,32 +968,6 @@ namespace cds { namespace gc { m_gc.scan(); } }; - - ////////////////////////////////////////////////////////// - // Inlines - - inline Guard::Guard(ThreadGC& gc) - : m_gc( gc ) - { - getGC().allocGuard( *this ); - } - inline Guard::~Guard() - { - getGC().freeGuard( *this ); - } - - template - inline GuardArray::GuardArray( ThreadGC& gc ) - : m_gc( gc ) - { - getGC().allocGuard( *this ); - } - template - inline GuardArray::~GuardArray() - { - getGC().freeGuard( *this ); - } - } // namespace dhp }} // namespace cds::gc //@endcond diff --git a/cds/gc/details/hp.h b/cds/gc/details/hp.h index abc435ef..5685f0d0 100644 --- a/cds/gc/details/hp.h +++ b/cds/gc/details/hp.h @@ -608,38 +608,20 @@ namespace cds { class guard { details::hp_guard& m_hp ; ///< Hazard pointer guarded - ThreadGC& m_gc ; ///< Thread GC public: typedef details::hp_guard::hazard_ptr hazard_ptr ; ///< Hazard pointer type public: - /// Allocates HP guard from \p gc - guard( ThreadGC& gc ) - : m_hp( gc.allocGuard() ) - , m_gc( gc ) - {} + /// Allocates HP guard + guard(); // inline in hp_impl.h /// Allocates HP guard from \p gc and protects the pointer \p p of type \p T template - guard( ThreadGC& gc, T * p ) - : m_hp( gc.allocGuard() ) - , m_gc( gc ) - { - m_hp = p; - } + explicit guard( T * p ); // inline in hp_impl.h /// Frees HP guard. The pointer guarded may be deleted after this. - ~guard() - { - m_gc.freeGuard( m_hp ); - } - - /// Returns thread GC - ThreadGC& getGC() const - { - return m_gc; - } + ~guard(); // inline in hp_impl.h /// Protects the pointer \p p against reclamation (guards the pointer). template @@ -667,8 +649,6 @@ namespace cds { template class array : public details::hp_array { - ThreadGC& m_mgr ; ///< Thread GC - public: /// Rebind array for other size \p COUNT2 template @@ -677,21 +657,11 @@ namespace cds { }; public: - /// Allocates array of HP guard from \p mgr - array( ThreadGC& mgr ) - : m_mgr( mgr ) - { - mgr.allocGuard( *this ); - } + /// Allocates array of HP guard + array(); // inline in hp_impl.h /// Frees array of HP guard - ~array() - { - m_mgr.freeGuard( *this ); - } - - /// Returns thread GC - ThreadGC& getGC() const { return m_mgr; } + ~array(); //inline in hp_impl.h }; } // namespace hp diff --git a/cds/gc/impl/dhp_decl.h b/cds/gc/impl/dhp_decl.h index e07b196c..1cfb3f48 100644 --- a/cds/gc/impl/dhp_decl.h +++ b/cds/gc/impl/dhp_decl.h @@ -120,7 +120,8 @@ namespace cds { namespace gc { public: // Default ctor - Guard(); // inline in dhp_impl.h + Guard() + {} //@cond Guard( Guard const& ) = delete; @@ -259,7 +260,8 @@ namespace cds { namespace gc { public: // Default ctor - GuardArray(); // inline in dhp_impl.h + GuardArray() + {} //@cond GuardArray( GuardArray const& ) = delete; diff --git a/cds/gc/impl/dhp_impl.h b/cds/gc/impl/dhp_impl.h index 5028d93c..52fca6bf 100644 --- a/cds/gc/impl/dhp_impl.h +++ b/cds/gc/impl/dhp_impl.h @@ -8,6 +8,32 @@ //@cond namespace cds { namespace gc { + namespace dhp { + + inline Guard::Guard() + { + cds::threading::getGC().allocGuard( *this ); + } + + inline Guard::~Guard() + { + cds::threading::getGC().freeGuard( *this ); + } + + template + inline GuardArray::GuardArray() + { + cds::threading::getGC().allocGuard( *this ); + } + + template + inline GuardArray::~GuardArray() + { + cds::threading::getGC().freeGuard( *this ); + } + } // namespace dhp + + inline DHP::thread_gc::thread_gc( bool bPersistent ) @@ -32,15 +58,6 @@ namespace cds { namespace gc { cds::threading::getGC().freeGuard(g); } - inline DHP::Guard::Guard() - : Guard::base_class( cds::threading::getGC() ) - {} - - template - inline DHP::GuardArray::GuardArray() - : GuardArray::base_class( cds::threading::getGC() ) - {} - inline void DHP::scan() { cds::threading::getGC().scan(); diff --git a/cds/gc/impl/hp_decl.h b/cds/gc/impl/hp_decl.h index cd9b1c2b..e5790d7b 100644 --- a/cds/gc/impl/hp_decl.h +++ b/cds/gc/impl/hp_decl.h @@ -116,7 +116,8 @@ namespace cds { namespace gc { public: /// Default ctor - Guard(); // inline in hp_impl.h + Guard() + {} //@cond Guard( Guard const& ) = delete; @@ -253,7 +254,8 @@ namespace cds { namespace gc { public: /// Default ctor - GuardArray(); // inline in hp_impl.h + GuardArray() + {} //@cond GuardArray( GuardArray const& ) = delete; diff --git a/cds/gc/impl/hp_impl.h b/cds/gc/impl/hp_impl.h index ac395368..38c6c90c 100644 --- a/cds/gc/impl/hp_impl.h +++ b/cds/gc/impl/hp_impl.h @@ -9,6 +9,39 @@ //@cond namespace cds { namespace gc { + namespace hp { + inline guard::guard() + : m_hp( cds::threading::getGC().allocGuard() ) + {} + + template + inline guard::guard( T * p ) + : m_hp( cds::threading::getGC().allocGuard() ) + { + m_hp = p; + } + + inline guard::~guard() + { + cds::threading::getGC().freeGuard( m_hp ); + } + + template + inline array::array() + { + cds::threading::getGC().allocGuard( *this ); + } + + template + inline array::~array() + { + cds::threading::getGC().freeGuard( *this ); + } + + + + } // namespace hp + inline HP::thread_gc::thread_gc( bool bPersistent ) @@ -34,15 +67,6 @@ namespace cds { namespace gc { cds::threading::getGC().freeGuard( g ); } - inline HP::Guard::Guard() - : Guard::base_class( cds::threading::getGC() ) - {} - - template - inline HP::GuardArray::GuardArray() - : GuardArray::base_class( cds::threading::getGC() ) - {} - template inline void HP::retire( T * p, void (* pFunc)(T *) ) {