Improving gc:HP and gc::DHP guards
authorkhizmax <libcds.dev@gmail.com>
Sat, 29 Nov 2014 11:26:46 +0000 (14:26 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 29 Nov 2014 11:26:46 +0000 (14:26 +0300)
cds/gc/details/dhp.h
cds/gc/details/hp.h
cds/gc/impl/dhp_decl.h
cds/gc/impl/dhp_impl.h
cds/gc/impl/hp_decl.h
cds/gc/impl/hp_impl.h

index ee689bee79c289dc7bc2601c1968abaeb3730abb..8f177c37e448f403965bb6cdba86b8581582b6cf 100644 (file)
@@ -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 <typename T>
@@ -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 <size_t Count>
-        inline GuardArray<Count>::GuardArray( ThreadGC& gc )
-            : m_gc( gc )
-        {
-            getGC().allocGuard( *this );
-        }
-        template <size_t Count>
-        inline GuardArray<Count>::~GuardArray()
-        {
-            getGC().freeGuard( *this );
-        }
-
     }   // namespace dhp
 }}  // namespace cds::gc
 //@endcond
index abc435ef0b76befbbcedde050490bf71025abe9f..5685f0d098ef8e0086d31d6382746c4e5df3ad31 100644 (file)
@@ -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 <typename T>
-            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 <typename T>
@@ -667,8 +649,6 @@ namespace cds {
         template <size_t Count>
         class array : public details::hp_array<Count>
         {
-            ThreadGC&    m_mgr    ;    ///< Thread GC
-
         public:
             /// Rebind array for other size \p COUNT2
             template <size_t Count2>
@@ -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
index e07b196c3c62b3121dee47849a2af76cb25e7951..1cfb3f4891c617eb1a59d6f1fec2e125fc8cddb0 100644 (file)
@@ -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;
index 5028d93caa922167c2d91476e53ea5b2240bfb14..52fca6bf0908d8b9a4c26198c3bda5c98b7a9503 100644 (file)
@@ -8,6 +8,32 @@
 //@cond
 namespace cds { namespace gc {
 
+    namespace dhp {
+
+        inline Guard::Guard()
+        {
+            cds::threading::getGC<DHP>().allocGuard( *this );
+        }
+
+        inline Guard::~Guard()
+        {
+            cds::threading::getGC<DHP>().freeGuard( *this );
+        }
+
+        template <size_t Count>
+        inline GuardArray<Count>::GuardArray()
+        {
+            cds::threading::getGC<DHP>().allocGuard( *this );
+        }
+
+        template <size_t Count>
+        inline GuardArray<Count>::~GuardArray()
+        {
+            cds::threading::getGC<DHP>().freeGuard( *this );
+        }
+    } // namespace dhp
+
+
     inline DHP::thread_gc::thread_gc(
         bool    bPersistent
         )
@@ -32,15 +58,6 @@ namespace cds { namespace gc {
         cds::threading::getGC<DHP>().freeGuard(g);
     }
 
-    inline DHP::Guard::Guard()
-        : Guard::base_class( cds::threading::getGC<DHP>() )
-    {}
-
-    template <size_t Count>
-    inline DHP::GuardArray<Count>::GuardArray()
-        : GuardArray::base_class( cds::threading::getGC<DHP>() )
-    {}
-
     inline void DHP::scan()
     {
         cds::threading::getGC<DHP>().scan();
index cd9b1c2b406352028432e1d3b179e66f936873bf..e5790d7b4f39819603de312466b904b7ed88cf80 100644 (file)
@@ -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;
index ac3953685616e3bf1c186cbda9ed021c8db44604..38c6c90cb8699616291d91880a9a6235ee125daa 100644 (file)
@@ -9,6 +9,39 @@
 //@cond
 namespace cds { namespace gc {
 
+    namespace hp {
+        inline guard::guard()
+            : m_hp( cds::threading::getGC<HP>().allocGuard() )
+        {}
+
+        template <typename T>
+        inline guard::guard( T * p )
+            : m_hp( cds::threading::getGC<HP>().allocGuard() )
+        {
+            m_hp = p;
+        }
+
+        inline guard::~guard()
+        {
+            cds::threading::getGC<HP>().freeGuard( m_hp );
+        }
+
+        template <size_t Count>
+        inline array<Count>::array()
+        {
+            cds::threading::getGC<HP>().allocGuard( *this );
+        }
+
+        template <size_t Count>
+        inline array<Count>::~array()
+        {
+            cds::threading::getGC<HP>().freeGuard( *this );
+        }
+
+
+
+    } // namespace hp
+
     inline HP::thread_gc::thread_gc(
         bool    bPersistent
         )
@@ -34,15 +67,6 @@ namespace cds { namespace gc {
         cds::threading::getGC<HP>().freeGuard( g );
     }
 
-    inline HP::Guard::Guard()
-        : Guard::base_class( cds::threading::getGC<HP>() )
-    {}
-
-    template <size_t COUNT>
-    inline HP::GuardArray<COUNT>::GuardArray()
-        : GuardArray::base_class( cds::threading::getGC<HP>() )
-    {}
-
     template <typename T>
     inline void HP::retire( T * p, void (* pFunc)(T *) )
     {