From: khizmax Date: Tue, 15 Sep 2015 20:54:33 +0000 (+0300) Subject: Fixed bugs in update() implementation X-Git-Tag: v2.1.0~108 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e754c2428919ca026e405c1aaf1587c2f4a104c1;p=libcds.git Fixed bugs in update() implementation --- diff --git a/cds/container/michael_kvlist_nogc.h b/cds/container/michael_kvlist_nogc.h index a1586e89..ad0a7c4d 100644 --- a/cds/container/michael_kvlist_nogc.h +++ b/cds/container/michael_kvlist_nogc.h @@ -535,9 +535,8 @@ namespace cds { namespace container { std::pair ret = base_class::update_at( refHead, *pNode, [&pItemFound](bool, node_type& item, node_type&){ pItemFound = &item; }, bAllowInsert ); - assert( pItemFound != nullptr ); - if ( ret.first && ret.second ) + if ( ret.second ) pNode.release(); return std::make_pair( pItemFound, ret.second ); } diff --git a/cds/container/michael_map_nogc.h b/cds/container/michael_map_nogc.h index 2ac3d449..68d0c575 100644 --- a/cds/container/michael_map_nogc.h +++ b/cds/container/michael_map_nogc.h @@ -413,7 +413,8 @@ namespace cds { namespace container { if ( ret.second ) ++m_ItemCounter; - + else if ( ret.first == refBucket.end() ) + return std::make_pair( end(), false ); return std::make_pair( iterator( ret.first, &refBucket, m_Buckets + bucket_count() ), ret.second ); } //@cond diff --git a/cds/container/michael_map_rcu.h b/cds/container/michael_map_rcu.h index 53097d49..83bf4328 100644 --- a/cds/container/michael_map_rcu.h +++ b/cds/container/michael_map_rcu.h @@ -433,8 +433,8 @@ namespace cds { namespace container { template std::pair update( K const& key, Func func, bool bAllowInsert = true ) { - std::pair bRet = bucket( key ).update( key, func ); - if ( bRet.first && bRet.second ) + std::pair bRet = bucket( key ).update( key, func, bAllowInsert ); + if ( bRet.second ) ++m_ItemCounter; return bRet; } @@ -443,10 +443,7 @@ namespace cds { namespace container { CDS_DEPRECATED("ensure() is deprecated, use update()") std::pair ensure( K const& key, Func func ) { - std::pair bRet = bucket( key ).ensure( key, func ); - if ( bRet.first && bRet.second ) - ++m_ItemCounter; - return bRet; + return update( key, func, true ); } //@endcond