From: khizmax Date: Sat, 24 Dec 2016 08:51:34 +0000 (+0300) Subject: SkipList: improved dtor X-Git-Tag: v2.2.0~19 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=000eb6c43b36538b5128a3d05303de7b0a2032c1;p=libcds.git SkipList: improved dtor --- diff --git a/cds/intrusive/impl/skip_list.h b/cds/intrusive/impl/skip_list.h index fb29f20a..db291380 100644 --- a/cds/intrusive/impl/skip_list.h +++ b/cds/intrusive/impl/skip_list.h @@ -442,7 +442,7 @@ namespace cds { namespace intrusive { /// Clears and destructs the skip-list ~SkipListSet() { - clear(); + destroy(); } public: @@ -1682,8 +1682,19 @@ namespace cds { namespace intrusive { { unsigned int nCur = m_nHeight.load( memory_model::memory_order_relaxed ); if ( nCur < nHeight ) - m_nHeight.compare_exchange_strong( nCur, nHeight, memory_model::memory_order_release, atomics::memory_order_relaxed ); + m_nHeight.compare_exchange_strong( nCur, nHeight, memory_model::memory_order_relaxed, atomics::memory_order_relaxed ); } + + void destroy() + { + node_type* p = m_Head.head()->next( 0 ).load( atomics::memory_order_relaxed ).ptr(); + while ( p ) { + node_type* pNext = p->next( 0 ).load( atomics::memory_order_relaxed ).ptr(); + dispose_node( node_traits::to_value_ptr( p )); + p = pNext; + } + } + //@endcond private: diff --git a/cds/intrusive/skip_list_rcu.h b/cds/intrusive/skip_list_rcu.h index 79d9f5b2..52dccdd7 100644 --- a/cds/intrusive/skip_list_rcu.h +++ b/cds/intrusive/skip_list_rcu.h @@ -697,7 +697,7 @@ namespace cds { namespace intrusive { /// Clears and destructs the skip-list ~SkipListSet() { - clear(); + destroy(); } public: @@ -2002,6 +2002,17 @@ namespace cds { namespace intrusive { if ( nCur < nHeight ) m_nHeight.compare_exchange_strong( nCur, nHeight, memory_model::memory_order_release, atomics::memory_order_relaxed ); } + + void destroy() + { + node_type* p = m_Head.head()->next( 0 ).load( atomics::memory_order_relaxed ).ptr(); + while ( p ) { + node_type* pNext = p->next( 0 ).load( atomics::memory_order_relaxed ).ptr(); + dispose_node( node_traits::to_value_ptr( p ) ); + p = pNext; + } + } + //@endcond };