Fixed HP/DHP thread data initialization
authorkhizmax <libcds.dev@gmail.com>
Tue, 17 Jan 2017 19:05:07 +0000 (22:05 +0300)
committerkhizmax <libcds.dev@gmail.com>
Tue, 17 Jan 2017 19:05:07 +0000 (22:05 +0300)
cds/gc/dhp_smr.h
cds/gc/hp_smr.h
src/hp.cpp

index d8c3e9f..7d0b5d7 100644 (file)
@@ -73,8 +73,8 @@ namespace cds { namespace gc {
         public:
             static hp_allocator& instance();
 
-            CDS_EXPORT_API guard_block*    alloc();
-            void            free( guard_block* block )
+            CDS_EXPORT_API guard_block* alloc();
+            void free( guard_block* block )
             {
                 free_list_.put( block );
             }
@@ -98,7 +98,10 @@ namespace cds { namespace gc {
                 , extended_list_( nullptr )
                 , array_( arr )
                 , initial_capacity_( nSize )
-            {}
+            {
+                // Initialize guards
+                new( arr ) guard[nSize];
+            }
 
             thread_hp_storage() = delete;
             thread_hp_storage( thread_hp_storage const& ) = delete;
index 2fb7c30..5511178 100644 (file)
@@ -74,6 +74,9 @@ namespace cds { namespace gc {
                 , free_guard_count_(0)
 #       endif
             {
+                // Initialize guards
+                new( arr ) guard[nSize];
+
                 for ( guard* pEnd = arr + nSize - 1; arr < pEnd; ++arr )
                     arr->next_ = arr + 1;
                 arr->next_ = nullptr;
index 897e119..b678cfc 100644 (file)
@@ -341,7 +341,7 @@ namespace cds { namespace gc { namespace hp {
         {
             retired_ptr dummy_retired;
             while ( pNode ) {
-                if ( !pNode->m_bFree.load( atomics::memory_order_relaxed )) {
+                if ( pNode->m_idOwner.load( atomics::memory_order_relaxed ) != cds::OS::c_NullThreadId ) {
                     thread_hp_storage& hpstg = pNode->hazards_;
                     for ( size_t i = 0; i < hazard_ptr_count_; ++i ) {
                         pRec->sync();
@@ -397,11 +397,13 @@ namespace cds { namespace gc { namespace hp {
         thread_record* pNode = thread_list_.load( atomics::memory_order_acquire );
 
         while ( pNode ) {
-            for ( size_t i = 0; i < get_hazard_ptr_count(); ++i ) {
-                pRec->sync();
-                void * hptr = pNode->hazards_[i].get();
-                if ( hptr )
-                    plist.push_back( hptr );
+            if ( pNode->m_idOwner.load( std::memory_order_relaxed ) != cds::OS::c_NullThreadId ) {
+                for ( size_t i = 0; i < get_hazard_ptr_count(); ++i ) {
+                    pRec->sync();
+                    void * hptr = pNode->hazards_[i].get();
+                    if ( hptr )
+                        plist.push_back( hptr );
+                }
             }
             pNode = pNode->m_pNextNode.load( atomics::memory_order_relaxed );
         }