Fixed bugs in update() implementation
authorkhizmax <libcds.dev@gmail.com>
Tue, 15 Sep 2015 20:54:33 +0000 (23:54 +0300)
committerkhizmax <libcds.dev@gmail.com>
Tue, 15 Sep 2015 20:54:33 +0000 (23:54 +0300)
cds/container/michael_kvlist_nogc.h
cds/container/michael_map_nogc.h
cds/container/michael_map_rcu.h

index a1586e893b0db97de6b1a71dd59a484fa624e489..ad0a7c4d2b9662ceeceba7d4b6da90019116488a 100644 (file)
@@ -535,9 +535,8 @@ namespace cds { namespace container {
             std::pair<bool, bool> 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 );
         }
index 2ac3d4499350de40c4aa443c8314aea6307fe5d3..68d0c575a008337eb1a0f9f8b51dcd0a5264d98c 100644 (file)
@@ -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
index 53097d4936b3adf55aba969a28c5c406ac82f2ae..83bf43287f543addd18eb2c33c2611305cd438cc 100644 (file)
@@ -433,8 +433,8 @@ namespace cds { namespace container {
         template <typename K, typename Func>
         std::pair<bool, bool> update( K const& key, Func func, bool bAllowInsert = true )
         {
-            std::pair<bool, bool> bRet = bucket( key ).update( key, func );
-            if ( bRet.first && bRet.second )
+            std::pair<bool, bool> 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<bool, bool> ensure( K const& key, Func func )
         {
-            std::pair<bool, bool> bRet = bucket( key ).ensure( key, func );
-            if ( bRet.first && bRet.second )
-                ++m_ItemCounter;
-            return bRet;
+            return update( key, func, true );
         }
         //@endcond