Replace cds::ref/boost::ref with std::ref, remove cds::unref and cds/ref.h header
[libcds.git] / cds / intrusive / split_list_rcu.h
index 2d655c1ccbcb2fa848727c38642d820f230a5227..1faf970e6e51756ecc2a4a224dc5cab6985a77e3 100644 (file)
@@ -3,7 +3,7 @@
 #ifndef __CDS_INTRUSIVE_SPLIT_LIST_RCU_H
 #define __CDS_INTRUSIVE_SPLIT_LIST_RCU_H
 
-#include <cds/intrusive/split_list_base.h>
+#include <cds/intrusive/details/split_list_base.h>
 #include <cds/details/binary_functor_wrapper.h>
 
 namespace cds { namespace intrusive {
@@ -126,7 +126,7 @@ namespace cds { namespace intrusive {
         public:
             bool insert_at( dummy_node_type * pHead, value_type& val )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::insert_at( h, val );
             }
@@ -134,7 +134,7 @@ namespace cds { namespace intrusive {
             template <typename Func>
             bool insert_at( dummy_node_type * pHead, value_type& val, Func f )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::insert_at( h, val, f );
             }
@@ -142,14 +142,14 @@ namespace cds { namespace intrusive {
             template <typename Func>
             std::pair<bool, bool> ensure_at( dummy_node_type * pHead, value_type& val, Func func )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::ensure_at( h, val, func );
             }
 
             bool unlink_at( dummy_node_type * pHead, value_type& val )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::unlink_at( h, val );
             }
@@ -157,7 +157,7 @@ namespace cds { namespace intrusive {
             template <typename Q, typename Compare, typename Func>
             bool erase_at( dummy_node_type * pHead, split_list::details::search_value_type<Q> const& val, Compare cmp, Func f )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::erase_at( h, val, cmp, f );
             }
@@ -165,7 +165,7 @@ namespace cds { namespace intrusive {
             template <typename Q, typename Compare>
             bool erase_at( dummy_node_type * pHead, split_list::details::search_value_type<Q> const& val, Compare cmp )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::erase_at( h, val, cmp );
             }
@@ -173,7 +173,7 @@ namespace cds { namespace intrusive {
             template <typename Q, typename Compare>
             value_type * extract_at( dummy_node_type * pHead, split_list::details::search_value_type<Q>& val, Compare cmp )
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::extract_at( h, val, cmp );
             }
@@ -181,7 +181,7 @@ namespace cds { namespace intrusive {
             template <typename Q, typename Compare, typename Func>
             bool find_at( dummy_node_type * pHead, split_list::details::search_value_type<Q>& val, Compare cmp, Func f ) const
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::find_at( h, val, cmp, f );
             }
@@ -189,7 +189,7 @@ namespace cds { namespace intrusive {
             template <typename Q, typename Compare>
             bool find_at( dummy_node_type * pHead, split_list::details::search_value_type<Q> const & val, Compare cmp ) const
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::find_at( h, val, cmp );
             }
@@ -197,7 +197,7 @@ namespace cds { namespace intrusive {
             template <typename Q, typename Compare>
             value_type * get_at( dummy_node_type * pHead, split_list::details::search_value_type<Q>& val, Compare cmp ) const
             {
-                assert( pHead != null_ptr<dummy_node_type *>() );
+                assert( pHead != nullptr );
                 bucket_head_type h(pHead);
                 return base_class::get_at( h, val, cmp );
             }
@@ -235,7 +235,7 @@ namespace cds { namespace intrusive {
     protected:
         ordered_list_wrapper    m_List              ;   ///< Ordered list containing split-list items
         bucket_table            m_Buckets           ;   ///< bucket table
-        CDS_ATOMIC::atomic<size_t> m_nBucketCountLog2  ;   ///< log2( current bucket count )
+        atomics::atomic<size_t> m_nBucketCountLog2  ;   ///< log2( current bucket count )
         item_counter            m_ItemCounter       ;   ///< Item counter
         hash                    m_HashFunctor       ;   ///< Hash functor
 
@@ -260,7 +260,7 @@ namespace cds { namespace intrusive {
 
         size_t bucket_no( size_t nHash ) const
         {
-            return nHash & ( (1 << m_nBucketCountLog2.load(CDS_ATOMIC::memory_order_relaxed)) - 1 );
+            return nHash & ( (1 << m_nBucketCountLog2.load(atomics::memory_order_relaxed)) - 1 );
         }
 
         static size_t parent_bucket( size_t nBucket )
@@ -275,11 +275,11 @@ namespace cds { namespace intrusive {
             size_t nParent = parent_bucket( nBucket );
 
             dummy_node_type * pParentBucket = m_Buckets.bucket( nParent );
-            if ( pParentBucket == null_ptr<dummy_node_type *>() ) {
+            if ( pParentBucket == nullptr ) {
                 pParentBucket = init_bucket( nParent );
             }
 
-            assert( pParentBucket != null_ptr<dummy_node_type *>() );
+            assert( pParentBucket != nullptr );
 
             // Allocate a dummy node for new bucket
             {
@@ -300,7 +300,7 @@ namespace cds { namespace intrusive {
             back_off bkoff;
             while ( true ) {
                 dummy_node_type volatile * p = m_Buckets.bucket( nBucket );
-                if ( p != null_ptr<dummy_node_type volatile *>() )
+                if ( p != nullptr )
                     return const_cast<dummy_node_type *>( p );
                 bkoff();
             }
@@ -311,7 +311,7 @@ namespace cds { namespace intrusive {
             size_t nBucket = bucket_no( nHash );
 
             dummy_node_type * pHead = m_Buckets.bucket( nBucket );
-            if ( pHead == null_ptr<dummy_node_type *>() )
+            if ( pHead == nullptr )
                 pHead = init_bucket( nBucket );
 
             assert( pHead->is_dummy() );
@@ -338,10 +338,10 @@ namespace cds { namespace intrusive {
 
         void    inc_item_count()
         {
-            size_t sz = m_nBucketCountLog2.load(CDS_ATOMIC::memory_order_relaxed);
+            size_t sz = m_nBucketCountLog2.load(atomics::memory_order_relaxed);
             if ( ( ++m_ItemCounter >> sz ) > m_Buckets.load_factor() && ((size_t)(1 << sz )) < m_Buckets.capacity() )
             {
-                m_nBucketCountLog2.compare_exchange_strong( sz, sz + 1, CDS_ATOMIC::memory_order_seq_cst, CDS_ATOMIC::memory_order_relaxed );
+                m_nBucketCountLog2.compare_exchange_strong( sz, sz + 1, atomics::memory_order_seq_cst, atomics::memory_order_relaxed );
             }
         }
 
@@ -351,15 +351,10 @@ namespace cds { namespace intrusive {
             size_t nHash = hash_value( val );
             split_list::details::search_value_type<Q>  sv( val, split_list::regular_hash( nHash ));
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
-#       ifdef CDS_CXX11_LAMBDA_SUPPORT
             return m_List.find_at( pHead, sv, cmp,
-                [&f](value_type& item, split_list::details::search_value_type<Q>& val){ cds::unref(f)(item, val.val ); });
-#       else
-            split_list::details::find_functor_wrapper<Func> ffw( f );
-            return m_List.find_at( pHead, sv, cmp, cds::ref(ffw) );
-#       endif
+                [&f](value_type& item, split_list::details::search_value_type<Q>& val){ f(item, val.val ); });
         }
 
         template <typename Q, typename Compare>
@@ -368,7 +363,7 @@ namespace cds { namespace intrusive {
             size_t nHash = hash_value( val );
             split_list::details::search_value_type<Q const>  sv( val, split_list::regular_hash( nHash ));
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             return m_List.find_at( pHead, sv, cmp );
         }
@@ -379,7 +374,7 @@ namespace cds { namespace intrusive {
             size_t nHash = hash_value( val );
             split_list::details::search_value_type<Q const>  sv( val, split_list::regular_hash( nHash ));
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             return m_List.get_at( pHead, sv, cmp );
         }
@@ -390,7 +385,7 @@ namespace cds { namespace intrusive {
             size_t nHash = hash_value( val );
             split_list::details::search_value_type<Q const>  sv( val, split_list::regular_hash( nHash ));
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             value_type * pNode = m_List.extract_at( pHead, sv, cmp );
             if ( pNode )
@@ -410,7 +405,7 @@ namespace cds { namespace intrusive {
             size_t nHash = hash_value( val );
             split_list::details::search_value_type<Q const>  sv( val, split_list::regular_hash( nHash ));
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             if ( m_List.erase_at( pHead, sv, cmp ) ) {
                 --m_ItemCounter;
@@ -425,7 +420,7 @@ namespace cds { namespace intrusive {
             size_t nHash = hash_value( val );
             split_list::details::search_value_type<Q const>  sv( val, split_list::regular_hash( nHash ));
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             if ( m_List.erase_at( pHead, sv, cmp, f )) {
                 --m_ItemCounter;
@@ -474,7 +469,7 @@ namespace cds { namespace intrusive {
         {
             size_t nHash = hash_value( val );
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             node_traits::to_node_ptr( val )->m_nHash = split_list::regular_hash( nHash );
 
@@ -501,7 +496,7 @@ namespace cds { namespace intrusive {
             where \p val is the item inserted. User-defined functor \p f should guarantee that during changing
             \p val no any other changes could be made on this set's item by concurrent threads.
             The user-defined functor is called only if the inserting is success and may be passed by reference
-            using <tt>boost::ref</tt>
+            using \p std::ref.
 
             The function makes RCU lock internally.
         */
@@ -510,7 +505,7 @@ namespace cds { namespace intrusive {
         {
             size_t nHash = hash_value( val );
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             node_traits::to_node_ptr( val )->m_nHash = split_list::regular_hash( nHash );
 
@@ -541,7 +536,7 @@ namespace cds { namespace intrusive {
             The functor can change non-key fields of the \p item; however, \p func must guarantee
             that during changing no any other modifications could be made on this item by concurrent threads.
 
-            You can pass \p func argument by value or by reference using <tt>boost::ref</tt> or cds::ref.
+            You can pass \p func argument by value or by reference using \p std::ref.
 
             The function makes RCU lock internally.
 
@@ -554,7 +549,7 @@ namespace cds { namespace intrusive {
         {
             size_t nHash = hash_value( val );
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             node_traits::to_node_ptr( val )->m_nHash = split_list::regular_hash( nHash );
 
@@ -582,7 +577,7 @@ namespace cds { namespace intrusive {
         {
             size_t nHash = hash_value( val );
             dummy_node_type * pHead = get_bucket( nHash );
-            assert( pHead != null_ptr<dummy_node_type *>() );
+            assert( pHead != nullptr );
 
             if ( m_List.unlink_at( pHead, val ) ) {
                 --m_ItemCounter;
@@ -744,7 +739,7 @@ namespace cds { namespace intrusive {
             \endcode
             where \p item is the item found, \p val is the <tt>find</tt> function argument.
 
-            You can pass \p f argument by value or by reference using <tt>boost::ref</tt> or cds::ref.
+            You can pass \p f argument by value or by reference using \p std::ref.
 
             The functor can change non-key fields of \p item. Note that the functor is only guarantee
             that \p item cannot be disposed during functor is executing.
@@ -791,7 +786,7 @@ namespace cds { namespace intrusive {
             \endcode
             where \p item is the item found, \p val is the <tt>find</tt> function argument.
 
-            You can pass \p f argument by value or by reference using <tt>boost::ref</tt> or cds::ref.
+            You can pass \p f argument by value or by reference using \p std::ref.
 
             The functor can change non-key fields of \p item. Note that the functor is only guarantee
             that \p item cannot be disposed during functor is executing.
@@ -851,7 +846,7 @@ namespace cds { namespace intrusive {
         /// Finds the key \p val and return the item found
         /** \anchor cds_intrusive_SplitListSet_rcu_get
             The function searches the item with key equal to \p val and returns the pointer to item found.
-            If \p val is not found it returns \p NULL.
+            If \p val is not found it returns \p nullptr.
 
             Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type.