From dd9008b0f638e049779a29522055fee08fbc918f Mon Sep 17 00:00:00 2001 From: khizmax Date: Tue, 4 Nov 2014 16:52:26 +0300 Subject: [PATCH] intrusive::SkipListSet refactoring --- cds/intrusive/details/skip_list_base.h | 101 +++--- cds/intrusive/impl/skip_list.h | 293 +++++++----------- cds/intrusive/skip_list_nogc.h | 205 +++++------- cds/intrusive/skip_list_rcu.h | 252 ++++++--------- projects/Win/vc12/hdr-test-set.vcxproj | 4 +- .../Win/vc12/hdr-test-set.vcxproj.filters | 12 +- ...ptb.cpp => hdr_intrusive_skiplist_dhp.cpp} | 144 ++++----- ... => hdr_intrusive_skiplist_dhp_member.cpp} | 144 ++++----- .../set/hdr_intrusive_skiplist_hp.cpp | 17 +- .../test-hdr/set/hdr_intrusive_skiplist_set.h | 150 ++++----- 10 files changed, 563 insertions(+), 759 deletions(-) rename tests/test-hdr/set/{hdr_intrusive_skiplist_ptb.cpp => hdr_intrusive_skiplist_dhp.cpp} (72%) rename tests/test-hdr/set/{hdr_intrusive_skiplist_ptb_member.cpp => hdr_intrusive_skiplist_dhp_member.cpp} (68%) diff --git a/cds/intrusive/details/skip_list_base.h b/cds/intrusive/details/skip_list_base.h index 257e2bba..6d60c3d4 100644 --- a/cds/intrusive/details/skip_list_base.h +++ b/cds/intrusive/details/skip_list_base.h @@ -9,7 +9,6 @@ #include #include - namespace cds { namespace intrusive { /// SkipListSet related definitions /** @ingroup cds_intrusive_helper @@ -22,25 +21,26 @@ namespace cds { namespace intrusive { /// Skip list node /** Template parameters: - - GC - garbage collector - - Tag - a tag used to distinguish between different implementation. An incomplete type may be used as a tag. + - \p GC - garbage collector + - \p Tag - a \ref cds_intrusive_hook_tag "tag" */ template - class node { + class node + { public: - typedef GC gc ; ///< Garbage collector - typedef Tag tag ; ///< tag + typedef GC gc; ///< Garbage collector + typedef Tag tag; ///< tag - typedef cds::details::marked_ptr marked_ptr ; ///< marked pointer - typedef typename gc::template atomic_marked_ptr< marked_ptr> atomic_marked_ptr ; ///< atomic marked pointer specific for GC + typedef cds::details::marked_ptr marked_ptr; ///< marked pointer + typedef typename gc::template atomic_marked_ptr< marked_ptr> atomic_marked_ptr; ///< atomic marked pointer specific for GC //@cond typedef atomic_marked_ptr tower_item_type; //@endcond protected: - atomic_marked_ptr m_pNext ; ///< Next item in bottom-list (list at level 0) - unsigned int m_nHeight ; ///< Node height (size of m_arrNext array). For node at level 0 the height is 1. - atomic_marked_ptr * m_arrNext ; ///< Array of next items for levels 1 .. m_nHeight - 1. For node at level 0 \p m_arrNext is \p nullptr + atomic_marked_ptr m_pNext; ///< Next item in bottom-list (list at level 0) + unsigned int m_nHeight; ///< Node height (size of m_arrNext array). For node at level 0 the height is 1. + atomic_marked_ptr * m_arrNext; ///< Array of next items for levels 1 .. m_nHeight - 1. For node at level 0 \p m_arrNext is \p nullptr public: /// Constructs a node of height 1 (a bottom-list node) @@ -125,8 +125,7 @@ namespace cds { namespace intrusive { { return m_pNext == atomic_marked_ptr() && m_arrNext == nullptr - && m_nHeight <= 1 -; + && m_nHeight <= 1; } //@endcond }; @@ -154,8 +153,8 @@ namespace cds { namespace intrusive { /// Base hook /** \p Options are: - - opt::gc - garbage collector used. - - opt::tag - a tag + - \p opt::gc - garbage collector + - \p opt::tag - a \ref cds_intrusive_hook_tag "tag" */ template < typename... Options > struct base_hook: public hook< opt::base_hook_tag, Options... > @@ -167,8 +166,8 @@ namespace cds { namespace intrusive { Use \p offsetof macro to define \p MemberOffset \p Options are: - - opt::gc - garbage collector used. - - opt::tag - a tag + - \p opt::gc - garbage collector + - \p opt::tag - a \ref cds_intrusive_hook_tag "tag" */ template < size_t MemberOffset, typename... Options > struct member_hook: public hook< opt::member_hook_tag, Options... > @@ -184,8 +183,8 @@ namespace cds { namespace intrusive { See \ref node_traits for \p NodeTraits interface description \p Options are: - - opt::gc - garbage collector used. - - opt::tag - a tag + - \p opt::gc - garbage collector + - \p opt::tag - a \ref cds_intrusive_hook_tag "tag" */ template struct traits_hook: public hook< opt::traits_hook_tag, Options... > @@ -222,8 +221,8 @@ namespace cds { namespace intrusive { Stateful generators are supported. Available \p Type implementations: - - \ref xorshift - - \ref turbo_pascal + - \p skip_list::xorshift + - \p skip_list::turbo_pascal */ template struct random_level_generator { @@ -338,7 +337,7 @@ namespace cds { namespace intrusive { } }; - /// SkipListSet internal statistics + /// \p SkipListSet internal statistics template struct stat { typedef EventCounter event_counter ; ///< Event counter type @@ -424,7 +423,7 @@ namespace cds { namespace intrusive { //@endcond }; - /// SkipListSet empty internal statistics + /// \p SkipListSet empty internal statistics struct empty_stat { //@cond void onAddNode( unsigned int nHeight ) const {} @@ -476,12 +475,12 @@ namespace cds { namespace intrusive { }; //@endcond - /// Type traits for SkipListSet class - struct type_traits + /// \p SkipListSet traits + struct traits { /// Hook used /** - Possible values are: skip_list::base_hook, skip_list::member_hook, skip_list::traits_hook. + Possible values are: \p skip_list::base_hook, \p skip_list::member_hook, \p skip_list::traits_hook. */ typedef base_hook<> hook; @@ -499,20 +498,21 @@ namespace cds { namespace intrusive { /// Disposer /** - The functor used for dispose removed items. Default is opt::v::empty_disposer. + The functor used for dispose removed items. Default is \p opt::v::empty_disposer. */ typedef opt::v::empty_disposer disposer; /// Item counter /** The type for item counting feature. - Default is no item counter (\ref atomicity::empty_item_counter) + By default, item counting is disabled (\p atomicity::empty_item_counter) + \p atomicity::item_counter enables it. */ typedef atomicity::empty_item_counter item_counter; /// C++ memory ordering model /** - List of available memory ordering see opt::memory_model + List of available memory ordering see \p opt::memory_model */ typedef opt::v::relaxed_ordering memory_model; @@ -523,7 +523,7 @@ namespace cds { namespace intrusive { where half of the nodes that have level \p i pointers also have level i+1 pointers (i = 0..30). So, the height of a node is in range [0..31]. - See skip_list::random_level_generator option setter. + See \p skip_list::random_level_generator option setter. */ typedef turbo_pascal random_level_generator; @@ -537,18 +537,22 @@ namespace cds { namespace intrusive { */ typedef CDS_DEFAULT_ALLOCATOR allocator; - /// back-off strategy used + /// back-off strategy /** - If the option is not specified, the cds::backoff::Default is used. + If the option is not specified, the \p cds::backoff::Default is used. */ typedef cds::backoff::Default back_off; /// Internal statistics + /** + By default, internal statistics is disabled (\p skip_list::empty_stat). + Use \p skip_list::stat to enable it. + */ typedef empty_stat stat; /// RCU deadlock checking policy (only for \ref cds_intrusive_SkipListSet_rcu "RCU-based SkipListSet") /** - List of available options see opt::rcu_check_deadlock + List of available options see \p opt::rcu_check_deadlock */ typedef opt::v::rcu_throw_deadlock rcu_check_deadlock; @@ -558,10 +562,30 @@ namespace cds { namespace intrusive { //@endcond }; - /// Metafunction converting option list to SkipListSet traits + /// Metafunction converting option list to \p SkipListSet traits /** - This is a wrapper for cds::opt::make_options< type_traits, Options...> - \p Options list see \ref SkipListSet. + \p Options are: + - \p opt::hook - hook used. Possible values are: \p skip_list::base_hook, \p skip_list::member_hook, \p skip_list::traits_hook. + If the option is not specified, skip_list::base_hook<> and \p gc::HP is used. + - \p opt::compare - key comparison functor. No default functor is provided. + If the option is not specified, the \p opt::less is used. + - \p opt::less - specifies binary predicate used for key comparison. Default is \p std::less. + - \p opt::disposer - the functor used for dispose removed items. Default is \p opt::v::empty_disposer. Due the nature + of GC schema the disposer may be called asynchronously. + - \p opt::item_counter - the type of item counting feature. Default is disabled, i.e. \p atomicity::empty_item_counter. + To enable it use \p atomicity::item_counter + - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) + or \p opt::v::sequential_consistent (sequentially consisnent memory model). + - \p skip_list::random_level_generator - random level generator. Can be \p skip_list::xorshift, + \p skip_list::turbo_pascal (the default) or + user-provided one. See \p skip_list::random_level_generator option description for explanation. + - \p opt::allocator - although the skip-list is an intrusive container, + an allocator should be provided to maintain variable randomly-calculated height of the node + since the node can contain up to 32 next pointers. The allocator option is used to allocate an array of next pointers + for nodes which height is more than 1. Default is \ref CDS_DEFAULT_ALLOCATOR. + - \p opt::back_off - back-off strategy, default is \รง cds::backoff::Default. + - \p opt::stat - internal statistics. By default, it is disabled (\p skip_list::empty_stat). + To enable it use \p skip_list::stat */ template struct make_traits { @@ -569,7 +593,7 @@ namespace cds { namespace intrusive { typedef implementation_defined type ; ///< Metafunction result # else typedef typename cds::opt::make_options< - typename cds::opt::find_type_traits< type_traits, Options... >::type + typename cds::opt::find_type_traits< traits, Options... >::type ,Options... >::type type; # endif @@ -581,7 +605,6 @@ namespace cds { namespace intrusive { class head_node: public Node { typedef Node node_type; - typename node_type::atomic_marked_ptr m_Tower[skip_list::c_nHeightLimit]; public: @@ -646,7 +669,7 @@ namespace cds { namespace intrusive { } // namespace skip_list // Forward declaration - template + template class SkipListSet; }} // namespace cds::intrusive diff --git a/cds/intrusive/impl/skip_list.h b/cds/intrusive/impl/skip_list.h index b4b34067..62e4be0d 100644 --- a/cds/intrusive/impl/skip_list.h +++ b/cds/intrusive/impl/skip_list.h @@ -24,9 +24,9 @@ namespace cds { namespace intrusive { typedef BackOff back_off; typedef typename node_traits::node_type node_type; typedef typename node_traits::value_type value_type; - static bool const c_isConst = IsConst; + static CDS_CONSTEXPR bool const c_isConst = IsConst; - typedef typename std::conditional< c_isConst, value_type const &, value_type &>::type value_ref; + typedef typename std::conditional< c_isConst, value_type const&, value_type&>::type value_ref; protected: typedef typename node_type::marked_ptr marked_ptr; @@ -132,7 +132,7 @@ namespace cds { namespace intrusive { return *this; } - iterator& operator = (const iterator& src) + iterator& operator =(const iterator& src) { m_pNode = src.m_pNode; m_guard.copy( src.m_guard ); @@ -176,48 +176,24 @@ namespace cds { namespace intrusive { The lock-free variant of skip-list is implemented according to book - [2008] M.Herlihy, N.Shavit "The Art of Multiprocessor Programming", chapter 14.4 "A Lock-Free Concurrent Skiplist". - \note The algorithm described in this book cannot be directly adapted for C++ (roughly speaking, - the algo contains a lot of bugs). The \b libcds implementation applies the approach discovered - by M.Michael in his \ref cds_intrusive_MichaelList_hp "lock-free linked list". Template arguments: - - \p GC - Garbage collector used. Note the \p GC must be the same as the GC used for item type \p T (see skip_list::node). - - \p T - type to be stored in the list. The type must be based on skip_list::node (for skip_list::base_hook) - or it must have a member of type skip_list::node (for skip_list::member_hook). - - \p Traits - type traits. See skip_list::type_traits for explanation. - - It is possible to declare option-based list with cds::intrusive::skip_list::make_traits metafunction istead of \p Traits template - argument. - Template argument list \p Options of cds::intrusive::skip_list::make_traits metafunction are: - - opt::hook - hook used. Possible values are: skip_list::base_hook, skip_list::member_hook, skip_list::traits_hook. - If the option is not specified, skip_list::base_hook<> and gc::HP is used. - - opt::compare - key comparison functor. No default functor is provided. - If the option is not specified, the opt::less is used. - - opt::less - specifies binary predicate used for key comparison. Default is \p std::less. - - opt::disposer - the functor used for dispose removed items. Default is opt::v::empty_disposer. Due the nature - of GC schema the disposer may be called asynchronously. - - opt::item_counter - the type of item counting feature. Default is \ref atomicity::empty_item_counter that is no item counting. - - opt::memory_model - C++ memory ordering model. Can be opt::v::relaxed_ordering (relaxed memory model, the default) - or opt::v::sequential_consistent (sequentially consisnent memory model). - - skip_list::random_level_generator - random level generator. Can be skip_list::xorshift, skip_list::turbo_pascal or - user-provided one. See skip_list::random_level_generator option description for explanation. - Default is \p %skip_list::turbo_pascal. - - opt::allocator - although the skip-list is an intrusive container, - an allocator should be provided to maintain variable randomly-calculated height of the node - since the node can contain up to 32 next pointers. The allocator option is used to allocate an array of next pointers - for nodes which height is more than 1. Default is \ref CDS_DEFAULT_ALLOCATOR. - - opt::back_off - back-off strategy used. If the option is not specified, the cds::backoff::Default is used. - - opt::stat - internal statistics. Available types: skip_list::stat, skip_list::empty_stat (the default) - - \warning The skip-list requires up to 67 hazard pointers that may be critical for some GCs for which + - \p GC - Garbage collector used. Note the \p GC must be the same as the GC used for item type \p T, see \p skip_list::node. + - \p T - type to be stored in the list. The type must be based on \p skip_list::node (for \p skip_list::base_hook) + or it must have a member of type \p skip_list::node (for \p skip_list::member_hook). + - \p Traits - skip-list traits, default is \p skip_list::traits. + It is possible to declare option-based list with \p cds::intrusive::skip_list::make_traits metafunction istead of \p Traits + template argument. + + @warning The skip-list requires up to 67 hazard pointers that may be critical for some GCs for which the guard count is limited (like as \p gc::HP). Those GCs should be explicitly initialized with hazard pointer enough: \code cds::gc::HP myhp( 67 ) \endcode. Otherwise an run-time exception may be raised when you try to create skip-list object. - \note There are several specializations of \p %SkipListSet for each \p GC. You should include: + There are several specializations of \p %SkipListSet for each \p GC. You should include: - for \p gc::HP garbage collector - for \p gc::DHP garbage collector - - for \ref cds_intrusive_SkipListSet_nogc for persistent set + - for \ref cds_intrusive_SkipListSet_nogc for append-only set - for \ref cds_intrusive_SkipListSet_rcu "RCU type" Iterators @@ -228,13 +204,13 @@ namespace cds { namespace intrusive { so, the element cannot be reclaimed while the iterator object is alive. However, passing an iterator object between threads is dangerous. - \warning Due to concurrent nature of skip-list set it is not guarantee that you can iterate + @warning Due to concurrent nature of skip-list set it is not guarantee that you can iterate all elements in the set: any concurrent deletion can exclude the element pointed by the iterator from the set, and your iteration can be terminated before end of the set. Therefore, such iteration is more suitable for debugging purpose only Remember, each iterator object requires 2 additional hazard pointers, that may be - a limited resource for \p GC like as \p gc::HP (for \p gc::PTB the count of + a limited resource for \p GC like as \p gc::HP (for \p gc::DHP the count of guards is unlimited). The iterator class supports the following minimalistic interface: @@ -259,15 +235,15 @@ namespace cds { namespace intrusive { bool operator !=(iterator const& i ) const; }; \endcode - Note, the iterator object returned by \ref end, \p cend member functions points to \p nullptr and should not be dereferenced. + Note, the iterator object returned by \p end(), \p cend() member functions points to \p nullptr and should not be dereferenced. How to use - You should incorporate skip_list::node into your struct \p T and provide - appropriate skip_list::type_traits::hook in your \p Traits template parameters. Usually, for \p Traits you - define a struct based on skip_list::type_traits. + You should incorporate \p skip_list::node into your struct \p T and provide + appropriate \p skip_list::traits::hook in your \p Traits template parameters. Usually, for \p Traits you + define a struct based on \p skip_list::traits. - Example for gc::HP and base hook: + Example for \p gc::HP and base hook: \code // Include GC-related skip-list specialization #include @@ -301,8 +277,8 @@ namespace cds { namespace intrusive { }; - // Declare type_traits - struct my_traits: public cds::intrusive::skip_list::type_traits + // Declare your traits + struct my_traits: public cds::intrusive::skip_list::traits { typedef cds::intrusive::skip_list::base_hook< cds::opt::gc< cds::gc::HP > > hook; typedef my_data_cmp compare; @@ -339,7 +315,7 @@ namespace cds { namespace intrusive { class GC ,typename T #ifdef CDS_DOXYGEN_INVOKED - ,typename Traits = skip_list::type_traits + ,typename Traits = skip_list::traits #else ,typename Traits #endif @@ -347,28 +323,28 @@ namespace cds { namespace intrusive { class SkipListSet { public: - typedef T value_type ; ///< type of value stored in the skip-list - typedef Traits options ; ///< Traits template parameter + typedef GC gc; ///< Garbage collector + typedef T value_type; ///< type of value stored in the skip-list + typedef Traits traits; ///< Traits template parameter - typedef typename options::hook hook ; ///< hook type - typedef typename hook::node_type node_type ; ///< node type + typedef typename traits::hook hook; ///< hook type + typedef typename hook::node_type node_type; ///< node type # ifdef CDS_DOXYGEN_INVOKED typedef implementation_defined key_comparator ; ///< key comparison functor based on opt::compare and opt::less option setter. # else - typedef typename opt::details::make_comparator< value_type, options >::type key_comparator; + typedef typename opt::details::make_comparator< value_type, traits >::type key_comparator; # endif - typedef typename options::disposer disposer ; ///< disposer used - typedef typename get_node_traits< value_type, node_type, hook>::type node_traits ; ///< node traits + typedef typename traits::disposer disposer; ///< item disposer + typedef typename get_node_traits< value_type, node_type, hook>::type node_traits; ///< node traits - typedef GC gc ; ///< Garbage collector - typedef typename options::item_counter item_counter ; ///< Item counting policy used - typedef typename options::memory_model memory_model ; ///< Memory ordering. See cds::opt::memory_model option - typedef typename options::random_level_generator random_level_generator ; ///< random level generator - typedef typename options::allocator allocator_type ; ///< allocator for maintaining array of next pointers of the node - typedef typename options::back_off back_off ; ///< Back-off strategy - typedef typename options::stat stat ; ///< internal statistics type + typedef typename traits::item_counter item_counter; ///< Item counting policy + typedef typename traits::memory_model memory_model; ///< Memory ordering, see \p cds::opt::memory_model option + typedef typename traits::random_level_generator random_level_generator; ///< random level generator + typedef typename traits::allocator allocator_type; ///< allocator for maintaining array of next pointers of the node + typedef typename traits::back_off back_off; ///< Back-off strategy + typedef typename traits::stat stat; ///< internal statistics type public: typedef cds::gc::guarded_ptr< gc, value_type > guarded_ptr; ///< Guarded pointer @@ -376,7 +352,7 @@ namespace cds { namespace intrusive { /// Max node height. The actual node height should be in range [0 .. c_nMaxHeight) /** The max height is specified by \ref skip_list::random_level_generator "random level generator" constant \p m_nUpperBound - but it should be no more than 32 (\ref skip_list::c_nHeightLimit). + but it should be no more than 32 (\p skip_list::c_nHeightLimit). */ static unsigned int const c_nMaxHeight = std::conditional< (random_level_generator::c_nUpperBound <= skip_list::c_nHeightLimit), @@ -389,20 +365,20 @@ namespace cds { namespace intrusive { //@endcond protected: - typedef typename node_type::atomic_marked_ptr atomic_node_ptr ; ///< Atomic marked node pointer - typedef typename node_type::marked_ptr marked_node_ptr ; ///< Node marked pointer + typedef typename node_type::atomic_marked_ptr atomic_node_ptr; ///< Atomic marked node pointer + typedef typename node_type::marked_ptr marked_node_ptr; ///< Node marked pointer protected: //@cond typedef skip_list::details::intrusive_node_builder< node_type, atomic_node_ptr, allocator_type > intrusive_node_builder; typedef typename std::conditional< - std::is_same< typename options::internal_node_builder, cds::opt::none >::value + std::is_same< typename traits::internal_node_builder, cds::opt::none >::value ,intrusive_node_builder - ,typename options::internal_node_builder + ,typename traits::internal_node_builder >::type node_builder; - typedef std::unique_ptr< node_type, typename node_builder::node_disposer > scoped_node_ptr; + typedef std::unique_ptr< node_type, typename node_builder::node_disposer > scoped_node_ptr; // c_nMaxHeight * 2 - pPred/pSucc guards // + 1 - for erase, unlink @@ -412,19 +388,18 @@ namespace cds { namespace intrusive { node_type * pPrev[ c_nMaxHeight ]; node_type * pSucc[ c_nMaxHeight ]; - typename gc::template GuardArray< c_nMaxHeight * 2 > guards ; ///< Guards array for pPrev/pSucc - - node_type * pCur ; // guarded by guards; needed only for *ensure* function + typename gc::template GuardArray< c_nMaxHeight * 2 > guards; ///< Guards array for pPrev/pSucc + node_type * pCur; // guarded by guards; needed only for \p ensure() }; //@endcond protected: - skip_list::details::head_node< node_type > m_Head ; ///< head tower (max height) + skip_list::details::head_node< node_type > m_Head; ///< head tower (max height) - item_counter m_ItemCounter ; ///< item counter - random_level_generator m_RandomLevelGen ; ///< random level generator instance - atomics::atomic m_nHeight ; ///< estimated high level - mutable stat m_Stat ; ///< internal statistics + item_counter m_ItemCounter; ///< item counter + random_level_generator m_RandomLevelGen; ///< random level generator instance + atomics::atomic m_nHeight; ///< estimated high level + mutable stat m_Stat; ///< internal statistics protected: //@cond @@ -994,16 +969,15 @@ namespace cds { namespace intrusive { } /// Returns a forward const iterator addressing the first element in a set - //@{ const_iterator begin() const { return const_iterator( *m_Head.head() ); } + /// Returns a forward const iterator addressing the first element in a set const_iterator cbegin() const { return const_iterator( *m_Head.head() ); } - //@} /// Returns a forward iterator that addresses the location succeeding the last element in a set. iterator end() @@ -1012,16 +986,15 @@ namespace cds { namespace intrusive { } /// Returns a forward const iterator that addresses the location succeeding the last element in a set. - //@{ const_iterator end() const { return const_iterator(); } + /// Returns a forward const iterator that addresses the location succeeding the last element in a set. const_iterator cend() const { return const_iterator(); } - //@} public: /// Inserts new node @@ -1051,8 +1024,7 @@ namespace cds { namespace intrusive { \endcode 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 \p std::ref + The user-defined functor is called only if the inserting is success. */ template bool insert( value_type& val, Func f ) @@ -1117,14 +1089,11 @@ namespace cds { namespace intrusive { If new item has been inserted (i.e. \p bNew is \p true) then \p item and \p val arguments refer to the same thing. - 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 \p std::ref. - Returns std::pair where \p first is \p true if operation is successfull, \p second is \p true if new item has been added or \p false if the item with \p key already is in the set. + + @warning See \ref cds_intrusive_item_creating "insert item troubleshooting" */ template std::pair ensure( value_type& val, Func func ) @@ -1178,12 +1147,12 @@ namespace cds { namespace intrusive { The function searches the item \p val in the set and unlink it from the set if it is found and is equal to \p val. - Difference between \ref erase and \p unlink functions: \p erase finds a key - and deletes the item found. \p unlink finds an item by key and deletes it + Difference between \p erase() and \p %unlink() functions: \p %erase() finds a key + and deletes the item found. \p %unlink() finds an item by key and deletes it only if \p val is an item of that set, i.e. the pointer to item found is equal to &val . - The \ref disposer specified in \p Traits class template parameter is called + The \p disposer specified in \p Traits class template parameter is called by garbage collector \p GC asynchronously. The function returns \p true if success and \p false otherwise. @@ -1224,7 +1193,7 @@ namespace cds { namespace intrusive { Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. The \ref disposer specified in \p Traits class template parameter is called automatically - by garbage collector \p GC specified in class' template parameters when returned \ref guarded_ptr object + by garbage collector \p GC specified in class' template parameters when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses the GC's guard that can be limited resource. @@ -1274,8 +1243,8 @@ namespace cds { namespace intrusive { During unlinking, a concurrent thread may insert an item with key less than leftmost item's key. So, the function returns the item with minimum key at the moment of list traversing. - The \ref disposer specified in \p Traits class template parameter is called - by garbage collector \p GC automatically when returned \ref guarded_ptr object + The \p disposer specified in \p Traits class template parameter is called + by garbage collector \p GC automatically when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses the GC's guard that can be limited resource. @@ -1309,14 +1278,14 @@ namespace cds { namespace intrusive { During unlinking, a concurrent thread may insert an item with key greater than rightmost item's key. So, the function returns the item with maximum key at the moment of list traversing. - The \ref disposer specified in \p Traits class template parameter is called + The \p disposer specified in \p Traits class template parameter is called by garbage collector \p GC asynchronously when returned \ref guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses the GC's guard that can be limited resource. Usage: \code - typedef cds::intrusive::SkipListSet< cds::gc::HP, foo, my_traits > skip_list; + typedef cds::intrusive::SkipListSet< cds::gc::HP, foo, my_traits > skip_list; skip_list theList; // ... { @@ -1336,16 +1305,16 @@ namespace cds { namespace intrusive { /// Deletes the item from the set /** \anchor cds_intrusive_SkipListSet_hp_erase - The function searches an item with key equal to \p val in the set, + The function searches an item with key equal to \p key in the set, unlinks it from the set, and returns \p true. - If the item with key equal to \p val is not found the function return \p false. + If the item with key equal to \p key is not found the function return \p false. Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool erase( Q const& val ) + bool erase( Q const& key ) { - return erase_( val, key_comparator(), [](value_type const&) {} ); + return erase_( key, key_comparator(), [](value_type const&) {} ); } /// Deletes the item from the set with comparing functor \p pred @@ -1358,14 +1327,14 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool erase_with( Q const& val, Less pred ) + bool erase_with( Q const& key, Less pred ) { - return erase_( val, cds::opt::details::make_comparator_from_less(), [](value_type const&) {} ); + return erase_( key, cds::opt::details::make_comparator_from_less(), [](value_type const&) {} ); } /// Deletes the item from the set /** \anchor cds_intrusive_SkipListSet_hp_erase_func - The function searches an item with key equal to \p val in the set, + The function searches an item with key equal to \p key in the set, call \p f functor with item found, unlinks it from the set, and returns \p true. The \ref disposer specified in \p Traits class template parameter is called by garbage collector \p GC asynchronously. @@ -1376,16 +1345,15 @@ namespace cds { namespace intrusive { void operator()( value_type const& item ); }; \endcode - The functor can be passed by reference with boost:ref - If the item with key equal to \p val is not found the function return \p false. + If the item with key equal to \p key is not found the function return \p false. Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool erase( Q const& val, Func f ) + bool erase( Q const& key, Func f ) { - return erase_( val, key_comparator(), f ); + return erase_( key, key_comparator(), f ); } /// Deletes the item from the set with comparing functor \p pred @@ -1398,44 +1366,39 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool erase_with( Q const& val, Less pred, Func f ) + bool erase_with( Q const& key, Less pred, Func f ) { - return erase_( val, cds::opt::details::make_comparator_from_less(), f ); + return erase_( key, cds::opt::details::make_comparator_from_less(), f ); } - /// Finds the key \p val + /// Finds \p key /** \anchor cds_intrusive_SkipListSet_hp_find_func - The function searches the item with key equal to \p val and calls the functor \p f for item found. + The function searches the item with key equal to \p key and calls the functor \p f for item found. The interface of \p Func functor is: \code struct functor { - void operator()( value_type& item, Q& val ); + void operator()( value_type& item, Q& key ); }; \endcode - where \p item is the item found, \p val is the find function argument. - - You can pass \p f argument by value or by reference using \p std::ref. + where \p item is the item found, \p key is the find function argument. 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. The functor does not serialize simultaneous access to the set \p item. If such access is - possible you must provide your own synchronization schema on item level to exclude unsafe item modifications. - - The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor - can modify both arguments. + possible you must provide your own synchronization on item level to exclude unsafe item modifications. Note the compare functor specified for class \p Traits template parameter should accept a parameter of type \p Q that can be not the same as \p value_type. - The function returns \p true if \p val is found, \p false otherwise. + The function returns \p true if \p key is found, \p false otherwise. */ template - bool find( Q& val, Func f ) + bool find( Q& key, Func f ) { - return find_with_( val, key_comparator(), f ); + return find_with_( key, key_comparator(), f ); } - /// Finds the key \p val with \p pred predicate for comparing + /// Finds the key \p key with \p pred predicate for comparing /** The function is an analog of \ref cds_intrusive_SkipListSet_hp_find_func "find(Q&, Func)" but \p pred is used for key compare. @@ -1445,69 +1408,26 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool find_with( Q& val, Less pred, Func f ) - { - return find_with_( val, cds::opt::details::make_comparator_from_less(), f ); - } - - /// Finds the key \p val - /** \anchor cds_intrusive_SkipListSet_hp_find_cfunc - The function searches the item with key equal to \p val and calls the functor \p f for item found. - The interface of \p Func functor is: - \code - struct functor { - void operator()( value_type& item, Q const& val ); - }; - \endcode - where \p item is the item found, \p val is the find function argument. - - 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. - The functor does not serialize simultaneous access to the set \p item. If such access is - possible you must provide your own synchronization schema on item level to exclude unsafe item modifications. - - Note the compare functor specified for class \p Traits template parameter - should accept a parameter of type \p Q that can be not the same as \p value_type. - - The function returns \p true if \p val is found, \p false otherwise. - */ - template - bool find( Q const& val, Func f ) - { - return find_with_( val, key_comparator(), f ); - } - - /// Finds the key \p val with \p pred predicate for comparing - /** - The function is an analog of \ref cds_intrusive_SkipListSet_hp_find_cfunc "find(Q const&, Func)" - but \p pred is used for key compare. - \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q - in any order. - \p pred must imply the same element order as the comparator used for building the set. - */ - template - bool find_with( Q const& val, Less pred, Func f ) + bool find_with( Q& key, Less pred, Func f ) { - return find_with_( val, cds::opt::details::make_comparator_from_less(), f ); + return find_with_( key, cds::opt::details::make_comparator_from_less(), f ); } - /// Finds the key \p val + /// Finds \p key /** \anchor cds_intrusive_SkipListSet_hp_find_val - The function searches the item with key equal to \p val + The function searches the item with key equal to \p key and returns \p true if it is found, and \p false otherwise. Note the compare functor specified for class \p Traits template parameter should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool find( Q const & val ) + bool find( Q const& key ) { - return find_with_( val, key_comparator(), [](value_type& , Q const& ) {} ); + return find_with_( key, key_comparator(), [](value_type& , Q const& ) {} ); } - /// Finds the key \p val with comparing functor \p pred + /// Finds \p key with comparing functor \p pred /** The function is an analog of \ref cds_intrusive_SkipListSet_hp_find_val "find(Q const&)" but \p pred is used for comparing the keys. @@ -1516,17 +1436,17 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool find_with( Q const& val, Less pred ) + bool find_with( Q const& key, Less pred ) { - return find_with_( val, cds::opt::details::make_comparator_from_less(), [](value_type& , Q const& ) {} ); + return find_with_( key, cds::opt::details::make_comparator_from_less(), [](value_type& , Q const& ) {} ); } - /// Finds the key \p val and return the item found + /// Finds \p key and return the item found /** \anchor cds_intrusive_SkipListSet_hp_get - The function searches the item with key equal to \p val + The function searches the item with key equal to \p key and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p val is found, and \p false otherwise. - If \p val is not found the \p ptr parameter is not changed. + The function returns \p true if \p key is found, and \p false otherwise. + If \p key is not found the \p ptr parameter is not changed. The \ref disposer specified in \p Traits class template parameter is called by garbage collector \p GC asynchronously when returned \ref guarded_ptr object @@ -1552,12 +1472,12 @@ namespace cds { namespace intrusive { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& val ) + bool get( guarded_ptr& ptr, Q const& key ) { - return get_with_( ptr.guard(), val, key_comparator() ); + return get_with_( ptr.guard(), key, key_comparator() ); } - /// Finds the key \p val and return the item found + /// Finds \p key and return the item found /** The function is an analog of \ref cds_intrusive_SkipListSet_hp_get "get( guarded_ptr& ptr, Q const&)" but \p pred is used for comparing the keys. @@ -1567,17 +1487,17 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool get_with( guarded_ptr& ptr, Q const& val, Less pred ) + bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) { - return get_with_( ptr.guard(), val, cds::opt::details::make_comparator_from_less() ); + return get_with_( ptr.guard(), key, cds::opt::details::make_comparator_from_less() ); } /// Returns item count in the set /** The value returned depends on item counter type provided by \p Traits template parameter. - If it is atomicity::empty_item_counter this function always returns 0. - Therefore, the function is not suitable for checking the set emptiness, use \ref empty - member function for this purpose. + If it is \p atomicity::empty_item_counter this function always returns 0. + Therefore, the function is not suitable for checking the set emptiness, use \p empty() + for this purpose. */ size_t size() const { @@ -1590,7 +1510,7 @@ namespace cds { namespace intrusive { return m_Head.head()->next( 0 ).load( memory_model::memory_order_relaxed ) == nullptr; } - /// Clears the set (non-atomic) + /// Clears the set (not atomic) /** The function unlink all items from the set. The function is not atomic, i.e., in multi-threaded environment with parallel insertions @@ -1620,7 +1540,6 @@ namespace cds { namespace intrusive { { return m_Stat; } - }; }} // namespace cds::intrusive diff --git a/cds/intrusive/skip_list_nogc.h b/cds/intrusive/skip_list_nogc.h index 6326cd11..fe209b96 100644 --- a/cds/intrusive/skip_list_nogc.h +++ b/cds/intrusive/skip_list_nogc.h @@ -5,7 +5,6 @@ #include #include -#include // ref #include #include #include @@ -19,16 +18,16 @@ namespace cds { namespace intrusive { class node< cds::gc::nogc, Tag > { public: - typedef cds::gc::nogc gc ; ///< Garbage collector - typedef Tag tag ; ///< tag + typedef cds::gc::nogc gc; ///< Garbage collector + typedef Tag tag; ///< tag typedef atomics::atomic atomic_ptr; - typedef atomic_ptr tower_item_type; + typedef atomic_ptr tower_item_type; protected: - atomic_ptr m_pNext ; ///< Next item in bottom-list (list at level 0) - unsigned int m_nHeight ; ///< Node height (size of m_arrNext array). For node at level 0 the height is 1. - atomic_ptr * m_arrNext ; ///< Array of next items for levels 1 .. m_nHeight - 1. For node at level 0 \p m_arrNext is \p nullptr + atomic_ptr m_pNext; ///< Next item in bottom-list (list at level 0) + unsigned int m_nHeight; ///< Node height (size of m_arrNext array). For node at level 0 the height is 1. + atomic_ptr * m_arrNext; ///< Array of next items for levels 1 .. m_nHeight - 1. For node at level 0 \p m_arrNext is \p nullptr public: /// Constructs a node of height 1 (a bottom-list node) @@ -180,7 +179,7 @@ namespace cds { namespace intrusive { return *this; } - iterator& operator = (const iterator& src) + iterator& operator =(const iterator& src) { m_pNode = src.m_pNode; return *this; @@ -204,38 +203,17 @@ namespace cds { namespace intrusive { /** @ingroup cds_intrusive_map @anchor cds_intrusive_SkipListSet_nogc - This specialization is intended for so-called persistent usage when no item + This specialization is so-called append-only when no item reclamation may be performed. The class does not support deleting of list item. See \ref cds_intrusive_SkipListSet_hp "SkipListSet" for description of skip-list. Template arguments : - - \p T - type to be stored in the set. The type must be based on skip_list::node (for skip_list::base_hook) - or it must have a member of type skip_list::node (for skip_list::member_hook). - - \p Traits - type traits. See skip_list::type_traits for explanation. - - It is possible to declare option-based list with cds::intrusive::skip_list::make_traits metafunction istead of \p Traits template - argument. - Template argument list \p Options of cds::intrusive::skip_list::make_traits metafunction are: - - opt::hook - hook used. Possible values are: skip_list::base_hook, skip_list::member_hook, skip_list::traits_hook. - If the option is not specified, skip_list::base_hook<> and gc::HP is used. - - opt::compare - key comparison functor. No default functor is provided. - If the option is not specified, the opt::less is used. - - opt::less - specifies binary predicate used for key comparison. Default is \p std::less. - - opt::item_counter - the type of item counting feature. Default is \ref atomicity::empty_item_counter that is no item counting. - - opt::memory_model - C++ memory ordering model. Can be opt::v::relaxed_ordering (relaxed memory model, the default) - or opt::v::sequential_consistent (sequentially consisnent memory model). - - skip_list::random_level_generator - random level generator. Can be skip_list::xorshift, skip_list::turbo_pascal or - user-provided one. See skip_list::random_level_generator option description for explanation. - Default is \p %skip_list::turbo_pascal. - - opt::allocator - although the skip-list is an intrusive container, - an allocator should be provided to maintain variable randomly-calculated height of the node - since the node can contain up to 32 next pointers. The allocator option is used to allocate an array of next pointers - for nodes which height is more than 1. Default is \ref CDS_DEFAULT_ALLOCATOR. - - opt::back_off - back-off strategy used. If the option is not specified, the cds::backoff::Default is used. - - opt::stat - internal statistics. Available types: skip_list::stat, skip_list::empty_stat (the default) - - opt::disposer - the functor used for dispose removed items. Default is opt::v::empty_disposer. - The disposer is used only in object destructor and in \ref clear function. + - \p T - type to be stored in the set. The type must be based on \p skip_list::node (for \p skip_list::base_hook) + or it must have a member of type \p skip_list::node (for \p skip_list::member_hook). + - \p Traits - type traits, default is \p skip_list::traits. + It is possible to declare option-based list with \p cds::intrusive::skip_list::make_traits metafunction + istead of \p Traits template argument. Iterators @@ -268,9 +246,9 @@ namespace cds { namespace intrusive { How to use - You should incorporate skip_list::node into your struct \p T and provide - appropriate skip_list::type_traits::hook in your \p Traits template parameters. Usually, for \p Traits you - define a struct based on skip_list::type_traits. + You should incorporate \p skip_list::node into your struct \p T and provide + appropriate \p skip_list::traits::hook in your \p Traits template parameters. Usually, for \p Traits you + define a struct based on \p skip_list::traits. Example for base hook: \code @@ -305,15 +283,15 @@ namespace cds { namespace intrusive { }; - // Declare type_traits - struct my_traits: public cds::intrusive::skip_list::type_traits + // Declare traits + struct my_traits: public cds::intrusive::skip_list::traits { - typedef cds::intrusive::skip_list::base_hook< cds::opt::gc< cds::gc::nogc > > hook; + typedef cds::intrusive::skip_list::base_hook< cds::opt::gc< cds::gc::nogc > > hook; typedef my_data_cmp compare; }; // Declare skip-list set type - typedef cds::intrusive::SkipListSet< cds::gc::nogc, my_data, my_traits > traits_based_set; + typedef cds::intrusive::SkipListSet< cds::gc::nogc, my_data, my_traits > traits_based_set; \endcode Equivalent option-based code: @@ -336,14 +314,12 @@ namespace cds { namespace intrusive { ,cds::intrusive::opt::compare< my_data_cmp > >::type > option_based_set; - \endcode - */ template < typename T #ifdef CDS_DOXYGEN_INVOKED - ,typename Traits = skip_list::type_traits + ,typename Traits = skip_list::traits #else ,typename Traits #endif @@ -351,32 +327,32 @@ namespace cds { namespace intrusive { class SkipListSet< cds::gc::nogc, T, Traits > { public: - typedef T value_type ; ///< type of value stored in the skip-list - typedef Traits options ; ///< Traits template parameter + typedef cds::gc::nogc gc; ///< No garbage collector is used + typedef T value_type; ///< type of value stored in the skip-list + typedef Traits traits; ///< Traits template parameter - typedef typename options::hook hook ; ///< hook type - typedef typename hook::node_type node_type ; ///< node type + typedef typename traits::hook hook; ///< hook type + typedef typename hook::node_type node_type; ///< node type # ifdef CDS_DOXYGEN_INVOKED - typedef implementation_defined key_comparator ; ///< key comparison functor based on opt::compare and opt::less option setter. + typedef implementation_defined key_comparator; ///< key comparison functor based on \p Traits::compare and \p Traits::less # else - typedef typename opt::details::make_comparator< value_type, options >::type key_comparator; + typedef typename opt::details::make_comparator< value_type, traits >::type key_comparator; # endif - typedef typename get_node_traits< value_type, node_type, hook>::type node_traits ; ///< node traits + typedef typename get_node_traits< value_type, node_type, hook>::type node_traits; ///< node traits - typedef cds::gc::nogc gc ; ///< No garbage collector is used - typedef typename options::item_counter item_counter ; ///< Item counting policy used - typedef typename options::memory_model memory_model; ///< Memory ordering. See cds::opt::memory_model option - typedef typename options::random_level_generator random_level_generator ; ///< random level generator - typedef typename options::allocator allocator_type ; ///< allocator for maintaining array of next pointers of the node - typedef typename options::back_off back_off ; ///< Back-off trategy - typedef typename options::stat stat ; ///< internal statistics type - typedef typename options::disposer disposer ; ///< disposer used + typedef typename traits::item_counter item_counter; ///< Item counting policy + typedef typename traits::memory_model memory_model; ///< Memory ordering. See \p cds::opt::memory_model option + typedef typename traits::random_level_generator random_level_generator ; ///< random level generator + typedef typename traits::allocator allocator_type; ///< allocator for maintaining array of next pointers of the node + typedef typename traits::back_off back_off; ///< Back-off strategy + typedef typename traits::stat stat; ///< internal statistics type + typedef typename traits::disposer disposer; ///< disposer /// Max node height. The actual node height should be in range [0 .. c_nMaxHeight) /** The max height is specified by \ref skip_list::random_level_generator "random level generator" constant \p m_nUpperBound - but it should be no more than 32 (\ref skip_list::c_nHeightLimit). + but it should be no more than 32 (\p skip_list::c_nHeightLimit). */ static unsigned int const c_nMaxHeight = std::conditional< (random_level_generator::c_nUpperBound <= skip_list::c_nHeightLimit), @@ -389,16 +365,16 @@ namespace cds { namespace intrusive { //@endcond protected: - typedef typename node_type::atomic_ptr atomic_node_ptr ; ///< Atomic node pointer + typedef typename node_type::atomic_ptr atomic_node_ptr; ///< Atomic node pointer protected: //@cond typedef skip_list::details::intrusive_node_builder< node_type, atomic_node_ptr, allocator_type > intrusive_node_builder; typedef typename std::conditional< - std::is_same< typename options::internal_node_builder, cds::opt::none >::value + std::is_same< typename traits::internal_node_builder, cds::opt::none >::value ,intrusive_node_builder - ,typename options::internal_node_builder + ,typename traits::internal_node_builder >::type node_builder; typedef std::unique_ptr< node_type, typename node_builder::node_disposer > scoped_node_ptr; @@ -438,12 +414,12 @@ namespace cds { namespace intrusive { //@endcond protected: - head_node m_Head ; ///< head tower (max height) + head_node m_Head; ///< head tower (max height) - item_counter m_ItemCounter ; ///< item counter - random_level_generator m_RandomLevelGen ; ///< random level generator instance - atomics::atomic m_nHeight ; ///< estimated high level - mutable stat m_Stat ; ///< internal statistics + item_counter m_ItemCounter; ///< item counter + random_level_generator m_RandomLevelGen; ///< random level generator instance + atomics::atomic m_nHeight; ///< estimated high level + mutable stat m_Stat; ///< internal statistics protected: //@cond @@ -616,16 +592,15 @@ namespace cds { namespace intrusive { } /// Returns a forward const iterator addressing the first element in a set - //@{ const_iterator begin() const { return const_iterator( *m_Head.head() ); } + /// Returns a forward const iterator addressing the first element in a set const_iterator cbegin() const { return const_iterator( *m_Head.head() ); } - //@} /// Returns a forward iterator that addresses the location succeeding the last element in a set. iterator end() @@ -634,16 +609,15 @@ namespace cds { namespace intrusive { } /// Returns a forward const iterator that addresses the location succeeding the last element in a set. - //@{ const_iterator end() const { return const_iterator(); } + /// Returns a forward const iterator that addresses the location succeeding the last element in a set. const_iterator cend() const { return const_iterator(); } - //@} protected: //@cond @@ -728,6 +702,8 @@ namespace cds { namespace intrusive { Returns std::pair where \p first is \p true if operation is successfull, \p second is \p true if new item has been added or \p false if the item with \p key already is in the set. + + @warning See \ref cds_intrusive_item_creating "insert item troubleshooting" */ template std::pair ensure( value_type& val, Func func ) @@ -773,16 +749,16 @@ namespace cds { namespace intrusive { } } - /// Finds the key \p val + /// Finds \p key /** \anchor cds_intrusive_SkipListSet_nogc_find_func - The function searches the item with key equal to \p val and calls the functor \p f for item found. + The function searches the item with key equal to \p key and calls the functor \p f for item found. The interface of \p Func functor is: \code struct functor { - void operator()( value_type& item, Q& val ); + void operator()( value_type& item, Q& key ); }; \endcode - where \p item is the item found, \p val is the find function argument. + where \p item is the item found, \p key is the find function argument. You can pass \p f argument by value or by reference using \p std::ref. @@ -791,21 +767,21 @@ namespace cds { namespace intrusive { The functor does not serialize simultaneous access to the set \p item. If such access is possible you must provide your own synchronization schema on item level to exclude unsafe item modifications. - The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor + The \p key argument is non-const since it can be used as \p f functor destination i.e., the functor can modify both arguments. Note the hash functor specified for class \p Traits template parameter should accept a parameter of type \p Q that can be not the same as \p value_type. - The function returns \p true if \p val is found, \p false otherwise. + The function returns \p true if \p key is found, \p false otherwise. */ template - bool find( Q& val, Func f ) const + bool find( Q& key, Func f ) const { - return find_with_( val, key_comparator(), f ) != nullptr; + return find_with_( key, key_comparator(), f ) != nullptr; } - /// Finds the key \p val using \p pred predicate for comparing + /// Finds the key \p key using \p pred predicate for comparing /** The function is an analog of \ref cds_intrusive_SkipListSet_nogc_find_func "find(Q&, Func)" but \p pred predicate is used for key compare. @@ -813,71 +789,29 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - bool find_with( Q& val, Less pred, Func f ) const - { - return find_with_( val, cds::opt::details::make_comparator_from_less(), f ) != nullptr; - } - - /// Finds the key \p val - /** \anchor cds_intrusive_SkipListSet_nogc_find_cfunc - The function searches the item with key equal to \p val and calls the functor \p f for item found. - The interface of \p Func functor is: - \code - struct functor { - void operator()( value_type& item, Q const& val ); - }; - \endcode - where \p item is the item found, \p val is the find function argument. - - 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. - The functor does not serialize simultaneous access to the set \p item. If such access is - possible you must provide your own synchronization schema on item level to exclude unsafe item modifications. - - Note the hash functor specified for class \p Traits template parameter - should accept a parameter of type \p Q that can be not the same as \p value_type. - - The function returns \p true if \p val is found, \p false otherwise. - */ - template - bool find( Q const& val, Func f ) const - { - return find_with_( val, key_comparator(), f ) != nullptr; - } - - /// Finds the key \p val using \p pred predicate for comparing - /** - The function is an analog of \ref cds_intrusive_SkipListSet_nogc_find_cfunc "find(Q const&, Func)" - but \p pred predicate is used for key compare. - \p Less has the interface like \p std::less. - \p pred must imply the same element order as the comparator used for building the set. - */ - template - bool find_with( Q const& val, Less pred, Func f ) const + bool find_with( Q& key, Less pred, Func f ) const { - return find_with_( val, cds::opt::details::make_comparator_from_less(), f ) != nullptr; + return find_with_( key, cds::opt::details::make_comparator_from_less(), f ) != nullptr; } - /// Finds the key \p val + /// Finds \p key /** \anchor cds_intrusive_SkipListSet_nogc_find_val - The function searches the item with key equal to \p val + The function searches the item with key equal to \p key and returns \p true if it is found, and \p false otherwise. Note the hash functor specified for class \p Traits template parameter should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - value_type * find( Q const& val ) const + value_type * find( Q const& key ) const { - node_type * pNode = find_with_( val, key_comparator(), [](value_type& , Q const& ) {} ); + node_type * pNode = find_with_( key, key_comparator(), [](value_type& , Q const& ) {} ); if ( pNode ) return node_traits::to_value_ptr( pNode ); return nullptr; } - /// Finds the key \p val using \p pred predicate for comparing + /// Finds \p key using \p pred predicate for comparing /** The function is an analog of \ref cds_intrusive_SkipListSet_nogc_find_val "find(Q const&)" but \p pred predicate is used for key compare. @@ -885,9 +819,9 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the set. */ template - value_type * find_with( Q const& val, Less pred ) const + value_type * find_with( Q const& key, Less pred ) const { - node_type * pNode = find_with_( val, cds::opt::details::make_comparator_from_less(), [](value_type& , Q const& ) {} ); + node_type * pNode = find_with_( key, cds::opt::details::make_comparator_from_less(), [](value_type& , Q const& ) {} ); if ( pNode ) return node_traits::to_value_ptr( pNode ); return nullptr; @@ -951,9 +885,8 @@ namespace cds { namespace intrusive { /// Returns item count in the set /** The value returned depends on item counter type provided by \p Traits template parameter. - If it is atomicity::empty_item_counter this function always returns 0. - The function is not suitable for checking the set emptiness, use \ref empty - member function for this purpose. + For \p atomicity::empty_item_counter the function always returns 0. + The function is not suitable for checking the set emptiness, use \p empty(). */ size_t size() const { diff --git a/cds/intrusive/skip_list_rcu.h b/cds/intrusive/skip_list_rcu.h index 4a61dfc8..b8749b85 100644 --- a/cds/intrusive/skip_list_rcu.h +++ b/cds/intrusive/skip_list_rcu.h @@ -5,7 +5,6 @@ #include #include -#include // ref #include #include #include @@ -28,25 +27,25 @@ namespace cds { namespace intrusive { // Mark bits: // bit 0 - the item is logically deleted // bit 1 - the item is extracted (only for level 0) - typedef cds::details::marked_ptr marked_ptr ; ///< marked pointer - typedef atomics::atomic< marked_ptr > atomic_marked_ptr ; ///< atomic marked pointer - typedef atomic_marked_ptr tower_item_type; + typedef cds::details::marked_ptr marked_ptr; ///< marked pointer + typedef atomics::atomic< marked_ptr > atomic_marked_ptr; ///< atomic marked pointer + typedef atomic_marked_ptr tower_item_type; protected: - atomic_marked_ptr m_pNext ; ///< Next item in bottom-list (list at level 0) + atomic_marked_ptr m_pNext; ///< Next item in bottom-list (list at level 0) public: - node * m_pDelChain ; ///< Deleted node chain (local for a thread) + node * m_pDelChain; ///< Deleted node chain (local for a thread) # ifdef _DEBUG bool volatile m_bLinked; bool volatile m_bUnlinked; # endif protected: - unsigned int m_nHeight ; ///< Node height (size of m_arrNext array). For node at level 0 the height is 1. - atomic_marked_ptr * m_arrNext ; ///< Array of next items for levels 1 .. m_nHeight - 1. For node at level 0 \p m_arrNext is \p nullptr + unsigned int m_nHeight; ///< Node height (size of m_arrNext array). For node at level 0 the height is 1. + atomic_marked_ptr * m_arrNext; ///< Array of next items for levels 1 .. m_nHeight - 1. For node at level 0 \p m_arrNext is \p nullptr public: /// Constructs a node of height 1 (a bottom-list node) - node() + CDS_CONSTEXPR node() : m_pNext( nullptr ) , m_pDelChain( nullptr ) # ifdef _DEBUG @@ -101,7 +100,7 @@ namespace cds { namespace intrusive { assert( nLevel < height() ); assert( nLevel == 0 || (nLevel > 0 && m_arrNext != nullptr) ); - return nLevel ? m_arrNext[ nLevel - 1] : m_pNext; + return nLevel ? m_arrNext[nLevel - 1] : m_pNext; } /// Access to element of next pointer array (const version) @@ -110,7 +109,7 @@ namespace cds { namespace intrusive { assert( nLevel < height() ); assert( nLevel == 0 || nLevel > 0 && m_arrNext != nullptr ); - return nLevel ? m_arrNext[ nLevel - 1] : m_pNext; + return nLevel ? m_arrNext[nLevel - 1] : m_pNext; } /// Access to element of next pointer array (same as \ref next function) @@ -313,39 +312,14 @@ namespace cds { namespace intrusive { The lock-free variant of skip-list is implemented according to book - [2008] M.Herlihy, N.Shavit "The Art of Multiprocessor Programming", chapter 14.4 "A Lock-Free Concurrent Skiplist". - \note The algorithm described in this book cannot be directly adapted for C++ (roughly speaking, - the algo contains a lot of bugs). The \b libcds implementation applies the approach discovered - by M.Michael in his \ref cds_intrusive_MichaelList_hp "lock-free linked list". Template arguments: - \p RCU - one of \ref cds_urcu_gc "RCU type" - \p T - type to be stored in the list. The type must be based on \p skip_list::node (for \p skip_list::base_hook) or it must have a member of type \p skip_list::node (for \p skip_list::member_hook). - - \p Traits - type traits. See \p skip_list::type_traits (the default) for explanation. - - It is possible to declare option-based list with \p cds::intrusive::skip_list::make_traits metafunction instead of \p Traits template - argument. - Template argument list \p Options of \p %cds::intrusive::skip_list::make_traits metafunction is: - - \p opt::hook - hook used. Possible values are: \p skip_list::base_hook, \p skip_list::member_hook, \p skip_list::traits_hook. - If the option is not specified, skip_list::base_hook<> is used. - - \p opt::compare - key comparison functor. No default functor is provided. - If the option is not specified, the \p opt::less is used. - - \p opt::less - specifies binary predicate used for key comparison. Default is \p std::less. - - \p opt::disposer - the functor used for dispose removed items. Default is \p opt::v::empty_disposer. Due the nature - of GC schema the disposer may be called asynchronously. - - \p opt::item_counter - the type of item counting feature. Default is \p atomicity::empty_item_counter that is no item counting. - - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) - or \p opt::v::sequential_consistent (sequentially consisnent memory model). - - \p skip_list::random_level_generator - random level generator. Can be \p skip_list::xorshift, \p skip_list::turbo_pascal or - user-provided one. See \p skip_list::random_level_generator option description for explanation. - Default is \p %skip_list::turbo_pascal. - - \p opt::allocator - although the skip-list is an intrusive container, - an allocator should be provided to maintain variable randomly-calculated height of the node - since the node can contain up to 32 next pointers. The allocator option is used to allocate an array of next pointers - for nodes which height is more than 1. Default is \ref CDS_DEFAULT_ALLOCATOR. - - \p opt::back_off - back-off strategy used. If the option is not specified, the \p cds::backoff::Default is used. - - \p opt::stat - internal statistics. Available types: \p skip_list::stat, \p skip_list::empty_stat (the default) - - \p opt::rcu_check_deadlock - a deadlock checking policy. Default is \p opt::v::rcu_throw_deadlock + - \p Traits - set traits, default is \p skip_list::type_traits + It is possible to declare option-based list with \p cds::intrusive::skip_list::make_traits metafunction + instead of \p Traits template argument. @note Before including you should include appropriate RCU header file, see \ref cds_urcu_gc "RCU type" for list of existing RCU class and corresponding header files. @@ -378,7 +352,7 @@ namespace cds { namespace intrusive { // Traits for your skip-list. // At least, you should define cds::opt::less or cds::opt::compare for Foo struct - struct my_traits: public cds::intrusive::skip_list::type_traits + struct my_traits: public cds::intrusive::skip_list::traits { // ... }; @@ -428,8 +402,8 @@ namespace cds { namespace intrusive { How to use You should incorporate skip_list::node into your struct \p T and provide - appropriate skip_list::type_traits::hook in your \p Traits template parameters. Usually, for \p Traits you - define a struct based on \p skip_list::type_traits. + appropriate skip_list::traits::hook in your \p Traits template parameters. Usually, for \p Traits you + define a struct based on \p skip_list::traits. Example for cds::urcu::general_buffered<> RCU and base hook: \code @@ -470,9 +444,8 @@ namespace cds { namespace intrusive { } }; - - // Declare type_traits - struct my_traits: public cds::intrusive::skip_list::type_traits + // Declare traits + struct my_traits: public cds::intrusive::skip_list::traits { typedef cds::intrusive::skip_list::base_hook< cds::opt::gc< rcu_type > > hook; typedef my_data_cmp compare; @@ -511,7 +484,7 @@ namespace cds { namespace intrusive { class RCU ,typename T #ifdef CDS_DOXYGEN_INVOKED - ,typename Traits = skip_list::type_traits + ,typename Traits = skip_list::traits #else ,typename Traits #endif @@ -519,30 +492,30 @@ namespace cds { namespace intrusive { class SkipListSet< cds::urcu::gc< RCU >, T, Traits > { public: - typedef T value_type ; ///< type of value stored in the skip-list - typedef Traits options ; ///< Traits template parameter + typedef cds::urcu::gc< RCU > gc; ///< Garbage collector + typedef T value_type; ///< type of value stored in the skip-list + typedef Traits traits; ///< Traits template parameter - typedef typename options::hook hook ; ///< hook type - typedef typename hook::node_type node_type ; ///< node type + typedef typename traits::hook hook; ///< hook type + typedef typename hook::node_type node_type; ///< node type # ifdef CDS_DOXYGEN_INVOKED - typedef implementation_defined key_comparator ; ///< key comparison functor based on opt::compare and opt::less option setter. + typedef implementation_defined key_comparator ; ///< key comparison functor based on \p Traits::compare and \p Traits::less # else - typedef typename opt::details::make_comparator< value_type, options >::type key_comparator; + typedef typename opt::details::make_comparator< value_type, traits >::type key_comparator; # endif - typedef typename options::disposer disposer ; ///< disposer used - typedef typename get_node_traits< value_type, node_type, hook>::type node_traits ; ///< node traits - - typedef cds::urcu::gc< RCU > gc ; ///< Garbage collector - typedef typename options::item_counter item_counter; ///< Item counting policy used - typedef typename options::memory_model memory_model; ///< Memory ordering. See cds::opt::memory_model option - typedef typename options::random_level_generator random_level_generator ; ///< random level generator - typedef typename options::allocator allocator_type ; ///< allocator for maintaining array of next pointers of the node - typedef typename options::back_off back_off ; ///< Back-off trategy - typedef typename options::stat stat ; ///< internal statistics type - typedef typename options::rcu_check_deadlock rcu_check_deadlock ; ///< Deadlock checking policy - typedef typename gc::scoped_lock rcu_lock ; ///< RCU scoped lock + typedef typename traits::disposer disposer; ///< disposer + typedef typename get_node_traits< value_type, node_type, hook>::type node_traits; ///< node traits + + typedef typename traits::item_counter item_counter; ///< Item counting policy used + typedef typename traits::memory_model memory_model; ///< Memory ordering, see \p cds::opt::memory_model option + typedef typename traits::random_level_generator random_level_generator; ///< random level generator + typedef typename traits::allocator allocator_type; ///< allocator for maintaining array of next pointers of the node + typedef typename traits::back_off back_off; ///< Back-off strategy + typedef typename traits::stat stat; ///< internal statistics type + typedef typename traits::rcu_check_deadlock rcu_check_deadlock; ///< Deadlock checking policy + typedef typename gc::scoped_lock rcu_lock; ///< RCU scoped lock static CDS_CONSTEXPR const bool c_bExtractLockExternal = false; ///< Group of \p extract_xxx functions does not require external locking @@ -570,9 +543,9 @@ namespace cds { namespace intrusive { typedef skip_list::details::intrusive_node_builder< node_type, atomic_node_ptr, allocator_type > intrusive_node_builder; typedef typename std::conditional< - std::is_same< typename options::internal_node_builder, cds::opt::none >::value + std::is_same< typename traits::internal_node_builder, cds::opt::none >::value ,intrusive_node_builder - ,typename options::internal_node_builder + ,typename traits::internal_node_builder >::type node_builder; typedef std::unique_ptr< node_type, typename node_builder::node_disposer > scoped_node_ptr; @@ -600,13 +573,13 @@ namespace cds { namespace intrusive { //@endcond protected: - skip_list::details::head_node< node_type > m_Head ; ///< head tower (max height) + skip_list::details::head_node< node_type > m_Head; ///< head tower (max height) - item_counter m_ItemCounter ; ///< item counter - random_level_generator m_RandomLevelGen ; ///< random level generator instance - atomics::atomic m_nHeight ; ///< estimated high level + item_counter m_ItemCounter; ///< item counter + random_level_generator m_RandomLevelGen; ///< random level generator instance + atomics::atomic m_nHeight; ///< estimated high level atomics::atomic m_pDeferredDelChain ; ///< Deferred deleted node chain - mutable stat m_Stat ; ///< internal statistics + mutable stat m_Stat; ///< internal statistics protected: //@cond @@ -641,7 +614,7 @@ namespace cds { namespace intrusive { //@endcond public: - typedef cds::urcu::exempt_ptr< gc, value_type, value_type, node_disposer, void > exempt_ptr ; ///< pointer to extracted node + typedef cds::urcu::exempt_ptr< gc, value_type, value_type, node_disposer, void > exempt_ptr; ///< pointer to extracted node protected: //@cond @@ -1551,13 +1524,13 @@ retry: 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 \p std::ref. - RCU \p synchronize method can be called. RCU should not be locked. Returns std::pair where \p first is \p true if operation is successfull, \p second is \p true if new item has been added or \p false if the item with \p key already is in the set. + + @warning See \ref cds_intrusive_item_creating "insert item troubleshooting" */ template std::pair ensure( value_type& val, Func func ) @@ -1620,8 +1593,8 @@ retry: The function searches the item \p val in the set and unlink it from the set if it is found and is equal to \p val. - Difference between \ref erase and \p unlink functions: \p erase finds a key - and deletes the item found. \p unlink finds an item by key and deletes it + Difference between \p erase() and \p %unlink() functions: \p erase() finds a key + and deletes the item found. \p %unlink() searches an item by key and deletes it only if \p val is an item of that set, i.e. the pointer to item found is equal to &val . @@ -1791,18 +1764,18 @@ retry: /// Deletes the item from the set /** \anchor cds_intrusive_SkipListSet_rcu_erase - The function searches an item with key equal to \p val in the set, + The function searches an item with key equal to \p key in the set, unlinks it from the set, and returns \p true. - If the item with key equal to \p val is not found the function return \p false. + If the item with key equal to \p key is not found the function return \p false. Note the hash functor should accept a parameter of type \p Q that can be not the same as \p value_type. RCU \p synchronize method can be called. RCU should not be locked. */ template - bool erase( const Q& val ) + bool erase( const Q& key ) { - return do_erase( val, key_comparator(), [](value_type const&) {} ); + return do_erase( key, key_comparator(), [](value_type const&) {} ); } /// Delete the item from the set with comparing functor \p pred @@ -1813,14 +1786,14 @@ retry: \p pred must imply the same element order as the comparator used for building the set. */ template - bool erase_with( const Q& val, Less pred ) + bool erase_with( const Q& key, Less pred ) { - return do_erase( val, cds::opt::details::make_comparator_from_less(), [](value_type const&) {} ); + return do_erase( key, cds::opt::details::make_comparator_from_less(), [](value_type const&) {} ); } /// Deletes the item from the set /** \anchor cds_intrusive_SkipListSet_rcu_erase_func - The function searches an item with key equal to \p val in the set, + The function searches an item with key equal to \p key in the set, call \p f functor with item found, unlinks it from the set, and returns \p true. The \ref disposer specified in \p Traits class template parameter is called by garbage collector \p GC asynchronously. @@ -1831,18 +1804,16 @@ retry: void operator()( value_type const& item ); }; \endcode - The functor can be passed by reference with boost:ref - - If the item with key equal to \p val is not found the function return \p false. + If the item with key equal to \p key is not found the function return \p false. Note the hash functor should accept a parameter of type \p Q that can be not the same as \p value_type. RCU \p synchronize method can be called. RCU should not be locked. */ template - bool erase( Q const& val, Func f ) + bool erase( Q const& key, Func f ) { - return do_erase( val, key_comparator(), f ); + return do_erase( key, key_comparator(), f ); } /// Delete the item from the set with comparing functor \p pred @@ -1853,21 +1824,21 @@ retry: \p pred must imply the same element order as the comparator used for building the set. */ template - bool erase_with( Q const& val, Less pred, Func f ) + bool erase_with( Q const& key, Less pred, Func f ) { - return do_erase( val, cds::opt::details::make_comparator_from_less(), f ); + return do_erase( key, cds::opt::details::make_comparator_from_less(), f ); } - /// Finds the key \p val + /// Finds \p key /** @anchor cds_intrusive_SkipListSet_rcu_find_func - The function searches the item with key equal to \p val and calls the functor \p f for item found. + The function searches the item with key equal to \p key and calls the functor \p f for item found. The interface of \p Func functor is: \code struct functor { - void operator()( value_type& item, Q& val ); + void operator()( value_type& item, Q& key ); }; \endcode - where \p item is the item found, \p val is the find function argument. + where \p item is the item found, \p key is the find function argument. You can pass \p f argument by value or by reference using \p std::ref. @@ -1876,20 +1847,20 @@ retry: The functor does not serialize simultaneous access to the set \p item. If such access is possible you must provide your own synchronization schema on item level to exclude unsafe item modifications. - The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor + The \p key argument is non-const since it can be used as \p f functor destination i.e., the functor can modify both arguments. The function applies RCU lock internally. - The function returns \p true if \p val is found, \p false otherwise. + The function returns \p true if \p key is found, \p false otherwise. */ template - bool find( Q& val, Func f ) + bool find( Q& key, Func f ) { - return do_find_with( val, key_comparator(), f ); + return do_find_with( key, key_comparator(), f ); } - /// Finds the key \p val with comparing functor \p pred + /// Finds the key \p key with comparing functor \p pred /** The function is an analog of \ref cds_intrusive_SkipListSet_rcu_find_func "find(Q&, Func)" but \p cmp is used for key comparison. @@ -1897,66 +1868,25 @@ retry: \p cmp must imply the same element order as the comparator used for building the set. */ template - bool find_with( Q& val, Less pred, Func f ) - { - return do_find_with( val, cds::opt::details::make_comparator_from_less(), f ); - } - - /// Finds the key \p val - /** @anchor cds_intrusive_SkipListSet_rcu_find_cfunc - The function searches the item with key equal to \p val and calls the functor \p f for item found. - The interface of \p Func functor is: - \code - struct functor { - void operator()( value_type& item, Q const& val ); - }; - \endcode - where \p item is the item found, \p val is the find function argument. - - 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. - The functor does not serialize simultaneous access to the set \p item. If such access is - possible you must provide your own synchronization schema on item level to exclude unsafe item modifications. - - The function applies RCU lock internally. - - The function returns \p true if \p val is found, \p false otherwise. - */ - template - bool find( Q const& val, Func f ) - { - return do_find_with( val, key_comparator(), f ); - } - - /// Finds the key \p val with comparing functor \p pred - /** - The function is an analog of \ref cds_intrusive_SkipListSet_rcu_find_cfunc "find(Q const&, Func)" - but \p cmp is used for key comparison. - \p Less functor has the interface like \p std::less. - \p cmp must imply the same element order as the comparator used for building the set. - */ - template - bool find_with( Q const& val, Less pred, Func f ) + bool find_with( Q& key, Less pred, Func f ) { - return do_find_with( val, cds::opt::details::make_comparator_from_less(), f ); + return do_find_with( key, cds::opt::details::make_comparator_from_less(), f ); } - /// Finds the key \p val + /// Finds \p key /** @anchor cds_intrusive_SkipListSet_rcu_find_val - The function searches the item with key equal to \p val + The function searches the item with key equal to \p key and returns \p true if it is found, and \p false otherwise. The function applies RCU lock internally. */ template - bool find( Q const& val ) + bool find( Q const& key ) { - return do_find_with( val, key_comparator(), [](value_type& , Q const& ) {} ); + return do_find_with( key, key_comparator(), [](value_type& , Q const& ) {} ); } - /// Finds the key \p val with comparing functor \p pred + /// Finds \p key with comparing functor \p pred /** The function is an analog of \ref cds_intrusive_SkipListSet_rcu_find_val "find(Q const&)" but \p pred is used for key compare. @@ -1964,15 +1894,15 @@ retry: \p pred must imply the same element order as the comparator used for building the set. */ template - bool find_with( Q const& val, Less pred ) + bool find_with( Q const& key, Less pred ) { - return do_find_with( val, cds::opt::details::make_comparator_from_less(), [](value_type& , Q const& ) {} ); + return do_find_with( key, cds::opt::details::make_comparator_from_less(), [](value_type& , Q const& ) {} ); } - /// Finds the key \p val and return the item found + /// Finds \p key and return the item found /** \anchor cds_intrusive_SkipListSet_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 nullptr. + The function searches the item with key equal to \p key and returns the pointer to item found. + If \p key 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. @@ -2000,16 +1930,16 @@ retry: see \ref force_dispose for explanation. */ template - value_type * get( Q const& val ) + value_type * get( Q const& key ) { assert( gc::is_locked()); value_type * pFound; - return do_find_with( val, key_comparator(), [&pFound](value_type& found, Q const& ) { pFound = &found; } ) + return do_find_with( key, key_comparator(), [&pFound](value_type& found, Q const& ) { pFound = &found; } ) ? pFound : nullptr; } - /// Finds the key \p val and return the item found + /// Finds \p key and return the item found /** The function is an analog of \ref cds_intrusive_SkipListSet_rcu_get "get(Q const&)" but \p pred is used for comparing the keys. @@ -2019,12 +1949,12 @@ retry: \p pred must imply the same element order as the comparator used for building the set. */ template - value_type * get_with( Q const& val, Less pred ) + value_type * get_with( Q const& key, Less pred ) { assert( gc::is_locked()); value_type * pFound; - return do_find_with( val, cds::opt::details::make_comparator_from_less(), + return do_find_with( key, cds::opt::details::make_comparator_from_less(), [&pFound](value_type& found, Q const& ) { pFound = &found; } ) ? pFound : nullptr; } @@ -2032,8 +1962,8 @@ retry: /// Returns item count in the set /** The value returned depends on item counter type provided by \p Traits template parameter. - If it is atomicity::empty_item_counter this function always returns 0. - Therefore, the function is not suitable for checking the set emptiness, use \ref empty + For \p atomicity::empty_item_counter the function always returns 0. + Therefore, the function is not suitable for checking the set emptiness, use \p empty() member function for this purpose. */ size_t size() const @@ -2047,7 +1977,7 @@ retry: return m_Head.head()->next( 0 ).load( memory_model::memory_order_relaxed ) == nullptr; } - /// Clears the set (non-atomic) + /// Clears the set (not atomic) /** The function unlink all items from the set. The function is not atomic, thus, in multi-threaded environment with parallel insertions @@ -2058,7 +1988,7 @@ retry: \endcode the assertion could be raised. - For each item the \ref disposer will be called automatically after unlinking. + For each item the \p disposer will be called automatically after unlinking. */ void clear() { diff --git a/projects/Win/vc12/hdr-test-set.vcxproj b/projects/Win/vc12/hdr-test-set.vcxproj index 342715c1..5ed54a00 100644 --- a/projects/Win/vc12/hdr-test-set.vcxproj +++ b/projects/Win/vc12/hdr-test-set.vcxproj @@ -559,12 +559,12 @@ + + - - diff --git a/projects/Win/vc12/hdr-test-set.vcxproj.filters b/projects/Win/vc12/hdr-test-set.vcxproj.filters index 36b3542f..70d1633c 100644 --- a/projects/Win/vc12/hdr-test-set.vcxproj.filters +++ b/projects/Win/vc12/hdr-test-set.vcxproj.filters @@ -83,12 +83,6 @@ intrusive\skip_list - - intrusive\skip_list - - - intrusive\skip_list - intrusive\split_list @@ -311,5 +305,11 @@ container\split_list + + intrusive\skip_list + + + intrusive\skip_list + \ No newline at end of file diff --git a/tests/test-hdr/set/hdr_intrusive_skiplist_ptb.cpp b/tests/test-hdr/set/hdr_intrusive_skiplist_dhp.cpp similarity index 72% rename from tests/test-hdr/set/hdr_intrusive_skiplist_ptb.cpp rename to tests/test-hdr/set/hdr_intrusive_skiplist_dhp.cpp index 2ea52b97..094db5f9 100644 --- a/tests/test-hdr/set/hdr_intrusive_skiplist_ptb.cpp +++ b/tests/test-hdr/set/hdr_intrusive_skiplist_dhp.cpp @@ -7,13 +7,13 @@ namespace set { - void IntrusiveSkipListSet::skiplist_ptb_base_cmp() + void IntrusiveSkipListSet::skiplist_dhp_base_cmp() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -23,13 +23,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_less() + void IntrusiveSkipListSet::skiplist_dhp_base_less() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -39,13 +39,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmpmix() + void IntrusiveSkipListSet::skiplist_dhp_base_cmpmix() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -56,13 +56,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmp_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_cmp_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,co::stat< ci::skip_list::stat<> > @@ -73,13 +73,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_less_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_less_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,co::item_counter< cds::atomicity::item_counter > ,ci::opt::disposer< faked_disposer > @@ -90,13 +90,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmpmix_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_cmpmix_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -108,13 +108,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmp_xorshift() + void IntrusiveSkipListSet::skiplist_dhp_base_cmp_xorshift() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::compare< cmp > ,co::item_counter< cds::atomicity::item_counter > ,ci::opt::disposer< faked_disposer > @@ -125,13 +125,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_less_xorshift() + void IntrusiveSkipListSet::skiplist_dhp_base_less_xorshift() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::xorshift > @@ -142,13 +142,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmpmix_xorshift() + void IntrusiveSkipListSet::skiplist_dhp_base_cmpmix_xorshift() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -160,13 +160,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmp_xorshift_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_cmp_xorshift_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::compare< cmp > ,co::item_counter< cds::atomicity::item_counter > ,ci::opt::disposer< faked_disposer > @@ -178,13 +178,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_less_xorshift_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_less_xorshift_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -196,13 +196,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmpmix_xorshift_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_cmpmix_xorshift_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,co::item_counter< cds::atomicity::item_counter > ,ci::opt::disposer< faked_disposer > @@ -217,13 +217,13 @@ namespace set { //********* - void IntrusiveSkipListSet::skiplist_ptb_base_cmp_pascal() + void IntrusiveSkipListSet::skiplist_dhp_base_cmp_pascal() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::compare< cmp > ,co::item_counter< cds::atomicity::item_counter > ,ci::opt::disposer< faked_disposer > @@ -234,13 +234,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_less_pascal() + void IntrusiveSkipListSet::skiplist_dhp_base_less_pascal() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,co::item_counter< cds::atomicity::item_counter > ,ci::opt::disposer< faked_disposer > @@ -251,13 +251,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmpmix_pascal() + void IntrusiveSkipListSet::skiplist_dhp_base_cmpmix_pascal() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -269,13 +269,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmp_pascal_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_cmp_pascal_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::turbo_pascal > @@ -287,13 +287,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_less_pascal_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_less_pascal_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::turbo_pascal > @@ -305,13 +305,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_base_cmpmix_pascal_stat() + void IntrusiveSkipListSet::skiplist_dhp_base_cmpmix_pascal_stat() { - typedef base_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef base_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > + ci::opt::hook< ci::skip_list::base_hook< co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > diff --git a/tests/test-hdr/set/hdr_intrusive_skiplist_ptb_member.cpp b/tests/test-hdr/set/hdr_intrusive_skiplist_dhp_member.cpp similarity index 68% rename from tests/test-hdr/set/hdr_intrusive_skiplist_ptb_member.cpp rename to tests/test-hdr/set/hdr_intrusive_skiplist_dhp_member.cpp index f628dfba..fa04e380 100644 --- a/tests/test-hdr/set/hdr_intrusive_skiplist_ptb_member.cpp +++ b/tests/test-hdr/set/hdr_intrusive_skiplist_dhp_member.cpp @@ -6,13 +6,13 @@ #include "map/print_skiplist_stat.h" namespace set { - void IntrusiveSkipListSet::skiplist_ptb_member_cmp() + void IntrusiveSkipListSet::skiplist_dhp_member_cmp() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -22,13 +22,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_less() + void IntrusiveSkipListSet::skiplist_dhp_member_less() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -38,13 +38,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmpmix() + void IntrusiveSkipListSet::skiplist_dhp_member_cmpmix() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -55,13 +55,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmp_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_cmp_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,co::stat< ci::skip_list::stat<> > @@ -72,13 +72,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_less_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_less_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::stat< ci::skip_list::stat<> > @@ -89,13 +89,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmpmix_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_cmpmix_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -107,13 +107,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmp_xorshift() + void IntrusiveSkipListSet::skiplist_dhp_member_cmp_xorshift() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -124,13 +124,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_less_xorshift() + void IntrusiveSkipListSet::skiplist_dhp_member_less_xorshift() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -141,13 +141,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmpmix_xorshift() + void IntrusiveSkipListSet::skiplist_dhp_member_cmpmix_xorshift() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -159,13 +159,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmp_xorshift_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_cmp_xorshift_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -177,13 +177,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_less_xorshift_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_less_xorshift_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::xorshift > @@ -195,13 +195,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmpmix_xorshift_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_cmpmix_xorshift_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -215,13 +215,13 @@ namespace set { } - void IntrusiveSkipListSet::skiplist_ptb_member_cmp_pascal() + void IntrusiveSkipListSet::skiplist_dhp_member_cmp_pascal() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::turbo_pascal > @@ -232,13 +232,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_less_pascal() + void IntrusiveSkipListSet::skiplist_dhp_member_less_pascal() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::item_counter< cds::atomicity::item_counter > @@ -249,13 +249,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmpmix_pascal() + void IntrusiveSkipListSet::skiplist_dhp_member_cmpmix_pascal() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > @@ -267,13 +267,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmp_pascal_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_cmp_pascal_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::compare< cmp > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::turbo_pascal > @@ -285,13 +285,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_less_pascal_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_less_pascal_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,ci::skip_list::random_level_generator< ci::skip_list::turbo_pascal > @@ -303,13 +303,13 @@ namespace set { test_skiplist >(); } - void IntrusiveSkipListSet::skiplist_ptb_member_cmpmix_pascal_stat() + void IntrusiveSkipListSet::skiplist_dhp_member_cmpmix_pascal_stat() { - typedef member_int_item< ci::skip_list::node< cds::gc::PTB> > item; + typedef member_int_item< ci::skip_list::node< cds::gc::DHP> > item; - typedef ci::SkipListSet< cds::gc::PTB, item, + typedef ci::SkipListSet< cds::gc::DHP, item, ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > + ci::opt::hook< ci::skip_list::member_hook< offsetof(item, hMember), co::gc > > ,co::less< less > ,ci::opt::disposer< faked_disposer > ,co::compare< cmp > diff --git a/tests/test-hdr/set/hdr_intrusive_skiplist_hp.cpp b/tests/test-hdr/set/hdr_intrusive_skiplist_hp.cpp index 5919a65f..4ed25540 100644 --- a/tests/test-hdr/set/hdr_intrusive_skiplist_hp.cpp +++ b/tests/test-hdr/set/hdr_intrusive_skiplist_hp.cpp @@ -10,15 +10,14 @@ namespace set { void IntrusiveSkipListSet::skiplist_hp_base_cmp() { typedef base_int_item< ci::skip_list::node< cds::gc::HP> > item; - - typedef ci::SkipListSet< cds::gc::HP, item, - ci::skip_list::make_traits< - ci::opt::hook< ci::skip_list::base_hook< co::gc > > - ,co::compare< cmp > - ,ci::opt::disposer< faked_disposer > - ,co::item_counter< cds::atomicity::item_counter > - >::type - > set_type; + struct set_traits : public ci::skip_list::traits + { + typedef ci::skip_list::base_hook< co::gc > hook; + typedef cmp compare; + typedef faked_disposer disposer; + typedef cds::atomicity::item_counter item_counter; + }; + typedef ci::SkipListSet< cds::gc::HP, item, set_traits > set_type; test_skiplist >(); } diff --git a/tests/test-hdr/set/hdr_intrusive_skiplist_set.h b/tests/test-hdr/set/hdr_intrusive_skiplist_set.h index 9490b82b..342b456d 100644 --- a/tests/test-hdr/set/hdr_intrusive_skiplist_set.h +++ b/tests/test-hdr/set/hdr_intrusive_skiplist_set.h @@ -550,44 +550,44 @@ namespace set { void skiplist_hp_member_less_pascal_stat(); void skiplist_hp_member_cmpmix_pascal_stat(); - // Skip-list - gc::PTB - void skiplist_ptb_base_cmp(); - void skiplist_ptb_base_less(); - void skiplist_ptb_base_cmpmix(); - void skiplist_ptb_base_cmp_stat(); - void skiplist_ptb_base_less_stat(); - void skiplist_ptb_base_cmpmix_stat(); - void skiplist_ptb_base_cmp_xorshift(); - void skiplist_ptb_base_less_xorshift(); - void skiplist_ptb_base_cmpmix_xorshift(); - void skiplist_ptb_base_cmp_xorshift_stat(); - void skiplist_ptb_base_less_xorshift_stat(); - void skiplist_ptb_base_cmpmix_xorshift_stat(); - void skiplist_ptb_base_cmp_pascal(); - void skiplist_ptb_base_less_pascal(); - void skiplist_ptb_base_cmpmix_pascal(); - void skiplist_ptb_base_cmp_pascal_stat(); - void skiplist_ptb_base_less_pascal_stat(); - void skiplist_ptb_base_cmpmix_pascal_stat(); - - void skiplist_ptb_member_cmp(); - void skiplist_ptb_member_less(); - void skiplist_ptb_member_cmpmix(); - void skiplist_ptb_member_cmp_stat(); - void skiplist_ptb_member_less_stat(); - void skiplist_ptb_member_cmpmix_stat(); - void skiplist_ptb_member_cmp_xorshift(); - void skiplist_ptb_member_less_xorshift(); - void skiplist_ptb_member_cmpmix_xorshift(); - void skiplist_ptb_member_cmp_xorshift_stat(); - void skiplist_ptb_member_less_xorshift_stat(); - void skiplist_ptb_member_cmpmix_xorshift_stat(); - void skiplist_ptb_member_cmp_pascal(); - void skiplist_ptb_member_less_pascal(); - void skiplist_ptb_member_cmpmix_pascal(); - void skiplist_ptb_member_cmp_pascal_stat(); - void skiplist_ptb_member_less_pascal_stat(); - void skiplist_ptb_member_cmpmix_pascal_stat(); + // Skip-list - gc::DHP + void skiplist_dhp_base_cmp(); + void skiplist_dhp_base_less(); + void skiplist_dhp_base_cmpmix(); + void skiplist_dhp_base_cmp_stat(); + void skiplist_dhp_base_less_stat(); + void skiplist_dhp_base_cmpmix_stat(); + void skiplist_dhp_base_cmp_xorshift(); + void skiplist_dhp_base_less_xorshift(); + void skiplist_dhp_base_cmpmix_xorshift(); + void skiplist_dhp_base_cmp_xorshift_stat(); + void skiplist_dhp_base_less_xorshift_stat(); + void skiplist_dhp_base_cmpmix_xorshift_stat(); + void skiplist_dhp_base_cmp_pascal(); + void skiplist_dhp_base_less_pascal(); + void skiplist_dhp_base_cmpmix_pascal(); + void skiplist_dhp_base_cmp_pascal_stat(); + void skiplist_dhp_base_less_pascal_stat(); + void skiplist_dhp_base_cmpmix_pascal_stat(); + + void skiplist_dhp_member_cmp(); + void skiplist_dhp_member_less(); + void skiplist_dhp_member_cmpmix(); + void skiplist_dhp_member_cmp_stat(); + void skiplist_dhp_member_less_stat(); + void skiplist_dhp_member_cmpmix_stat(); + void skiplist_dhp_member_cmp_xorshift(); + void skiplist_dhp_member_less_xorshift(); + void skiplist_dhp_member_cmpmix_xorshift(); + void skiplist_dhp_member_cmp_xorshift_stat(); + void skiplist_dhp_member_less_xorshift_stat(); + void skiplist_dhp_member_cmpmix_xorshift_stat(); + void skiplist_dhp_member_cmp_pascal(); + void skiplist_dhp_member_less_pascal(); + void skiplist_dhp_member_cmpmix_pascal(); + void skiplist_dhp_member_cmp_pascal_stat(); + void skiplist_dhp_member_less_pascal_stat(); + void skiplist_dhp_member_cmpmix_pascal_stat(); // Skip-list - gc::nogc void skiplist_nogc_base_cmp(); @@ -667,43 +667,43 @@ namespace set { CPPUNIT_TEST(skiplist_hp_member_less_pascal_stat) CPPUNIT_TEST(skiplist_hp_member_cmpmix_pascal_stat) - CPPUNIT_TEST(skiplist_ptb_base_cmp) - CPPUNIT_TEST(skiplist_ptb_base_less) - CPPUNIT_TEST(skiplist_ptb_base_cmpmix) - CPPUNIT_TEST(skiplist_ptb_base_cmp_stat) - CPPUNIT_TEST(skiplist_ptb_base_less_stat) - CPPUNIT_TEST(skiplist_ptb_base_cmpmix_stat) - CPPUNIT_TEST(skiplist_ptb_base_cmp_xorshift) - CPPUNIT_TEST(skiplist_ptb_base_less_xorshift) - CPPUNIT_TEST(skiplist_ptb_base_cmpmix_xorshift) - CPPUNIT_TEST(skiplist_ptb_base_cmp_xorshift_stat) - CPPUNIT_TEST(skiplist_ptb_base_less_xorshift_stat) - CPPUNIT_TEST(skiplist_ptb_base_cmpmix_xorshift_stat) - CPPUNIT_TEST(skiplist_ptb_base_cmp_pascal) - CPPUNIT_TEST(skiplist_ptb_base_less_pascal) - CPPUNIT_TEST(skiplist_ptb_base_cmpmix_pascal) - CPPUNIT_TEST(skiplist_ptb_base_cmp_pascal_stat) - CPPUNIT_TEST(skiplist_ptb_base_less_pascal_stat) - CPPUNIT_TEST(skiplist_ptb_base_cmpmix_pascal_stat) - - CPPUNIT_TEST(skiplist_ptb_member_cmp) - CPPUNIT_TEST(skiplist_ptb_member_less) - CPPUNIT_TEST(skiplist_ptb_member_cmpmix) - CPPUNIT_TEST(skiplist_ptb_member_cmp_stat) - CPPUNIT_TEST(skiplist_ptb_member_less_stat) - CPPUNIT_TEST(skiplist_ptb_member_cmpmix_stat) - CPPUNIT_TEST(skiplist_ptb_member_cmp_xorshift) - CPPUNIT_TEST(skiplist_ptb_member_less_xorshift) - CPPUNIT_TEST(skiplist_ptb_member_cmpmix_xorshift) - CPPUNIT_TEST(skiplist_ptb_member_cmp_xorshift_stat) - CPPUNIT_TEST(skiplist_ptb_member_less_xorshift_stat) - CPPUNIT_TEST(skiplist_ptb_member_cmpmix_xorshift_stat) - CPPUNIT_TEST(skiplist_ptb_member_cmp_pascal) - CPPUNIT_TEST(skiplist_ptb_member_less_pascal) - CPPUNIT_TEST(skiplist_ptb_member_cmpmix_pascal) - CPPUNIT_TEST(skiplist_ptb_member_cmp_pascal_stat) - CPPUNIT_TEST(skiplist_ptb_member_less_pascal_stat) - CPPUNIT_TEST(skiplist_ptb_member_cmpmix_pascal_stat) + CPPUNIT_TEST(skiplist_dhp_base_cmp) + CPPUNIT_TEST(skiplist_dhp_base_less) + CPPUNIT_TEST(skiplist_dhp_base_cmpmix) + CPPUNIT_TEST(skiplist_dhp_base_cmp_stat) + CPPUNIT_TEST(skiplist_dhp_base_less_stat) + CPPUNIT_TEST(skiplist_dhp_base_cmpmix_stat) + CPPUNIT_TEST(skiplist_dhp_base_cmp_xorshift) + CPPUNIT_TEST(skiplist_dhp_base_less_xorshift) + CPPUNIT_TEST(skiplist_dhp_base_cmpmix_xorshift) + CPPUNIT_TEST(skiplist_dhp_base_cmp_xorshift_stat) + CPPUNIT_TEST(skiplist_dhp_base_less_xorshift_stat) + CPPUNIT_TEST(skiplist_dhp_base_cmpmix_xorshift_stat) + CPPUNIT_TEST(skiplist_dhp_base_cmp_pascal) + CPPUNIT_TEST(skiplist_dhp_base_less_pascal) + CPPUNIT_TEST(skiplist_dhp_base_cmpmix_pascal) + CPPUNIT_TEST(skiplist_dhp_base_cmp_pascal_stat) + CPPUNIT_TEST(skiplist_dhp_base_less_pascal_stat) + CPPUNIT_TEST(skiplist_dhp_base_cmpmix_pascal_stat) + + CPPUNIT_TEST(skiplist_dhp_member_cmp) + CPPUNIT_TEST(skiplist_dhp_member_less) + CPPUNIT_TEST(skiplist_dhp_member_cmpmix) + CPPUNIT_TEST(skiplist_dhp_member_cmp_stat) + CPPUNIT_TEST(skiplist_dhp_member_less_stat) + CPPUNIT_TEST(skiplist_dhp_member_cmpmix_stat) + CPPUNIT_TEST(skiplist_dhp_member_cmp_xorshift) + CPPUNIT_TEST(skiplist_dhp_member_less_xorshift) + CPPUNIT_TEST(skiplist_dhp_member_cmpmix_xorshift) + CPPUNIT_TEST(skiplist_dhp_member_cmp_xorshift_stat) + CPPUNIT_TEST(skiplist_dhp_member_less_xorshift_stat) + CPPUNIT_TEST(skiplist_dhp_member_cmpmix_xorshift_stat) + CPPUNIT_TEST(skiplist_dhp_member_cmp_pascal) + CPPUNIT_TEST(skiplist_dhp_member_less_pascal) + CPPUNIT_TEST(skiplist_dhp_member_cmpmix_pascal) + CPPUNIT_TEST(skiplist_dhp_member_cmp_pascal_stat) + CPPUNIT_TEST(skiplist_dhp_member_less_pascal_stat) + CPPUNIT_TEST(skiplist_dhp_member_cmpmix_pascal_stat) CPPUNIT_TEST(skiplist_nogc_base_cmp) CPPUNIT_TEST(skiplist_nogc_base_less) -- 2.34.1