From 9ffe43a2b52bbbfb8b85040658598410492a3709 Mon Sep 17 00:00:00 2001 From: khizmax Date: Mon, 24 Nov 2014 09:59:51 +0300 Subject: [PATCH] fix a bugs in guarded_ptr and exempt_ptr --- cds/gc/impl/dhp_decl.h | 3 +- cds/gc/impl/hp_decl.h | 3 +- cds/urcu/exempt_ptr.h | 2 +- .../ordered_list/hdr_intrusive_michael.h | 36 +++++++++++-------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/cds/gc/impl/dhp_decl.h b/cds/gc/impl/dhp_decl.h index 6da2073a..e07b196c 100644 --- a/cds/gc/impl/dhp_decl.h +++ b/cds/gc/impl/dhp_decl.h @@ -529,8 +529,7 @@ namespace cds { namespace gc { */ void release() CDS_NOEXCEPT { - if ( m_guard.is_initialized() ) - m_guard.clear(); + free_guard(); } //@cond diff --git a/cds/gc/impl/hp_decl.h b/cds/gc/impl/hp_decl.h index bffc5268..cd9b1c2b 100644 --- a/cds/gc/impl/hp_decl.h +++ b/cds/gc/impl/hp_decl.h @@ -533,8 +533,7 @@ namespace cds { namespace gc { */ void release() CDS_NOEXCEPT { - if ( m_pGuard ) - m_pGuard->clear(); + free_guard(); } //@cond diff --git a/cds/urcu/exempt_ptr.h b/cds/urcu/exempt_ptr.h index e86103a1..0a7ba1f5 100644 --- a/cds/urcu/exempt_ptr.h +++ b/cds/urcu/exempt_ptr.h @@ -242,8 +242,8 @@ namespace cds { namespace urcu { /// Disposes the pointer. Should be called only outside of RCU critical section void release() { - assert( !rcu::is_locked() ); if ( !empty() ) { + assert( !rcu::is_locked() ); rcu::template retire_ptr( m_pNode ); m_pNode = nullptr; } diff --git a/tests/test-hdr/ordered_list/hdr_intrusive_michael.h b/tests/test-hdr/ordered_list/hdr_intrusive_michael.h index 864dcc1e..606d7f34 100644 --- a/tests/test-hdr/ordered_list/hdr_intrusive_michael.h +++ b/tests/test-hdr/ordered_list/hdr_intrusive_michael.h @@ -478,12 +478,14 @@ namespace ordlist { CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey ); CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal ); + gp.release(); gp = l.extract( arrItem[i].nKey ); CPPUNIT_ASSERT_EX( gp, "i=" << i ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey ); CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal ); + gp.release(); gp = l.get( arrItem[i].nKey ); CPPUNIT_CHECK( !gp ); @@ -511,12 +513,14 @@ namespace ordlist { CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey ); CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal ); + gp.release(); gp = l.extract_with( itm, other_less() ); CPPUNIT_ASSERT_EX( gp, "i=" << i ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == arrItem[i].nKey ); CPPUNIT_CHECK( gp->nVal == arrItem[i].nVal ); + gp.release(); gp = l.get_with( itm, other_less() ); CPPUNIT_CHECK( !gp ); @@ -571,14 +575,15 @@ namespace ordlist { for ( int i = 0; i < nLimit; ++i ) { { - { - rcu_lock lock; - value_type * pGet = l.get( a[i] ); - CPPUNIT_ASSERT( pGet != nullptr ); - CPPUNIT_CHECK( pGet->nKey == a[i] ); - CPPUNIT_CHECK( pGet->nVal == a[i] * 2 ); - } + rcu_lock lock; + value_type * pGet = l.get( a[i] ); + CPPUNIT_ASSERT( pGet != nullptr ); + CPPUNIT_CHECK( pGet->nKey == a[i] ); + CPPUNIT_CHECK( pGet->nVal == a[i] * 2 ); + } + { + rcu_lock lock; ep = l.extract( a[i] ); CPPUNIT_ASSERT( ep ); CPPUNIT_ASSERT( !ep.empty() ); @@ -586,6 +591,7 @@ namespace ordlist { CPPUNIT_CHECK( (*ep).nVal == a[i] * 2 ); } ep.release(); + { rcu_lock lock; CPPUNIT_CHECK( l.get( a[i] ) == nullptr ); @@ -613,14 +619,15 @@ namespace ordlist { for ( int i = 0; i < nLimit; ++i ) { other_item itm( a[i] ); { - { - rcu_lock lock; - value_type * pGet = l.get_with( itm, other_less() ); - CPPUNIT_ASSERT( pGet != nullptr ); - CPPUNIT_CHECK( pGet->nKey == a[i] ); - CPPUNIT_CHECK( pGet->nVal == a[i] * 2 ); - } + rcu_lock lock; + value_type * pGet = l.get_with( itm, other_less() ); + CPPUNIT_ASSERT( pGet != nullptr ); + CPPUNIT_CHECK( pGet->nKey == a[i] ); + CPPUNIT_CHECK( pGet->nVal == a[i] * 2 ); + } + { + rcu_lock lock; ep = l.extract_with( itm, other_less() ); CPPUNIT_ASSERT( ep ); CPPUNIT_ASSERT( !ep.empty() ); @@ -628,6 +635,7 @@ namespace ordlist { CPPUNIT_CHECK( ep->nVal == a[i] * 2 ); } ep.release(); + { rcu_lock lock; CPPUNIT_CHECK( l.get_with( itm, other_less() ) == nullptr ); -- 2.34.1