From: khizmax Date: Sun, 7 Aug 2016 08:21:09 +0000 (+0300) Subject: Simplified IterableList iterator X-Git-Tag: v2.2.0~143 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1a0dceb97d9ea662108b2400f7deb731da787960;p=libcds.git Simplified IterableList iterator --- diff --git a/cds/intrusive/impl/iterable_list.h b/cds/intrusive/impl/iterable_list.h index ccc50be6..603d3015 100644 --- a/cds/intrusive/impl/iterable_list.h +++ b/cds/intrusive/impl/iterable_list.h @@ -190,35 +190,32 @@ namespace cds { namespace intrusive { protected: node_type* m_pNode; - value_type* m_pVal; - typename gc::Guard m_Guard; // for m_pVal + typename gc::Guard m_Guard; // data guard void next() { while ( m_pNode ) { - m_pNode = m_pNode->next.load( memory_model::memory_order_relaxed ); - if ( !m_pNode ) + m_pNode = m_pNode->next.load( memory_model::memory_order_acquire ); + if ( !m_pNode ) { + m_Guard.clear(); break; - m_pVal = m_Guard.protect( m_pNode->data ); - if ( m_pVal ) + } + if ( m_Guard.protect( m_pNode->data )) break; } } explicit iterator_type( atomic_node_ptr const& pNode ) - : m_pNode( pNode.load( memory_model::memory_order_relaxed )) - , m_pVal( nullptr ) + : m_pNode( pNode.load( memory_model::memory_order_acquire )) { if ( m_pNode ) { - m_pVal = m_Guard.protect( m_pNode->data ); - if ( !m_pVal ) + if ( !m_Guard.protect( m_pNode->data )) next(); } } iterator_type( node_type* pNode, value_type* pVal ) : m_pNode( pNode ) - , m_pVal( pVal ) { if ( m_pNode ) { assert( pVal != nullptr ); @@ -232,25 +229,23 @@ namespace cds { namespace intrusive { iterator_type() : m_pNode( nullptr ) - , m_pVal( nullptr ) {} iterator_type( iterator_type const& src ) : m_pNode( src.m_pNode ) - , m_pVal( src.m_pVal ) { - m_Guard.assign( m_pVal ); + m_Guard.copy( src.m_Guard ); } value_ptr operator ->() const { - return m_pVal; + return m_Guard.get(); } value_ref operator *() const { - assert( m_pVal != nullptr ); - return *m_pVal; + assert( m_Guard.get_native() != nullptr ); + return *m_Guard.get(); } /// Pre-increment @@ -263,8 +258,7 @@ namespace cds { namespace intrusive { iterator_type& operator = (iterator_type const& src) { m_pNode = src.m_pNode; - m_pVal = src.m_pVal; - m_Guard.assign( m_pVal ); + m_Guard.copy( src.m_Guard ); return *this; } @@ -276,7 +270,7 @@ namespace cds { namespace intrusive { template bool operator !=(iterator_type const& i ) const { - return m_pNode != i.m_pNode; + return !( *this == i ); } }; //@endcond