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 d8c3e9f6ab946903d7d87dcea68b71718444d7c6..7d0b5d7d7a31da59fa077f80082d768bd6c79193 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 2fb7c307d782aaade59acecd6ec3805c15c50c4c..5511178097a71856f98d0b4880b3a78339a548b8 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 897e119a867f5b6139205b16967c0cacc527c958..b678cfc82b54b2462c695d18cca034c8cfa81b60 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 );
         }