From 9281ab2e4ece2722f271f02cea4c51f46c6d57bf Mon Sep 17 00:00:00 2001 From: khizmax Date: Wed, 8 Oct 2014 16:48:08 +0400 Subject: [PATCH] container::OptimisticQueue refactoring --- cds/container/msqueue.h | 5 +- cds/container/optimistic_queue.h | 329 ++++++++++-------- projects/Win/vc12/hdr-test-queue.vcxproj | 4 +- .../Win/vc12/hdr-test-queue.vcxproj.filters | 12 +- tests/test-hdr/queue/hdr_optimistic_dhp.cpp | 117 +++++++ tests/test-hdr/queue/hdr_optimistic_hp.cpp | 117 +++++++ tests/test-hdr/queue/hdr_optimistic_hzp.cpp | 107 ------ tests/test-hdr/queue/hdr_optimistic_ptb.cpp | 107 ------ tests/test-hdr/queue/hdr_queue.h | 44 --- tests/test-hdr/queue/hdr_queue_new.h | 7 +- tests/unit/queue/queue_defs.h | 20 +- tests/unit/queue/queue_type.h | 72 ++-- 12 files changed, 477 insertions(+), 464 deletions(-) create mode 100644 tests/test-hdr/queue/hdr_optimistic_dhp.cpp create mode 100644 tests/test-hdr/queue/hdr_optimistic_hp.cpp delete mode 100644 tests/test-hdr/queue/hdr_optimistic_hzp.cpp delete mode 100644 tests/test-hdr/queue/hdr_optimistic_ptb.cpp diff --git a/cds/container/msqueue.h b/cds/container/msqueue.h index 3592fe3c..7b467f83 100644 --- a/cds/container/msqueue.h +++ b/cds/container/msqueue.h @@ -52,7 +52,6 @@ namespace cds { namespace container { /// Metafunction converting option list to \p msqueue::traits /** - This is a wrapper for cds::opt::make_options< type_traits, Options...> Supported \p Options are: - opt::allocator - allocator (like \p std::allocator) used for allocating queue nodes. Default is \ref CDS_DEFAULT_ALLOCATOR - opt::back_off - back-off strategy used, default is \p cds::backoff::empty. @@ -69,8 +68,8 @@ namespace cds { namespace container { \code typedef cds::container::MSQueue< cds::gc::HP, Foo, typename cds::container::msqueue::make_traits< - cds::opt::item_counte< cds::atomicity::item_counter >, - cds::opt::stat< cds::intrusive::msqueue::stat<> > + cds::opt::item_counter< cds::atomicity::item_counter >, + cds::opt::stat< cds::container::msqueue::stat<> > >::type > myQueue; \endcode diff --git a/cds/container/optimistic_queue.h b/cds/container/optimistic_queue.h index bfe5e078..800e654c 100644 --- a/cds/container/optimistic_queue.h +++ b/cds/container/optimistic_queue.h @@ -4,21 +4,100 @@ #define __CDS_CONTAINER_OPTIMISTIC_QUEUE_H #include -#include // ref #include #include -#include namespace cds { namespace container { + /// OptimisticQueue related definitions + /** @ingroup cds_nonintrusive_helper + */ + namespace optimistic_queue { + /// Internal statistics + template ::counter_type > + using stat = cds::intrusive::optimistic_queue::stat< Counter >; + + /// Dummy internal statistics + typedef cds::intrusive::optimistic_queue::empty_stat empty_stat; + + /// MSQueue default type traits + struct traits + { + /// Node allocator + typedef CDS_DEFAULT_ALLOCATOR allocator; + + /// Back-off strategy + typedef cds::backoff::empty back_off; + + /// Item counting feature; by default, disabled. Use \p cds::atomicity::item_counter to enable item counting + typedef atomicity::empty_item_counter item_counter; + + /// Internal statistics (by default, disabled) + /** + Possible option value are: \p optimistic_queue::stat, \p optimistic_queue::empty_stat (the default), + user-provided class that supports \p %optimistic_queue::stat interface. + */ + typedef optimistic_queue::empty_stat stat; + + /// 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). + */ + typedef opt::v::relaxed_ordering memory_model; + + /// Alignment of internal queue data. Default is \p opt::cache_line_alignment + enum { alignment = opt::cache_line_alignment }; + }; + + /// Metafunction converting option list to \p msqueue::traits + /** + Supported \p Options are: + - opt::allocator - allocator (like \p std::allocator) used for allocating queue nodes. Default is \ref CDS_DEFAULT_ALLOCATOR + - opt::back_off - back-off strategy used, default is \p cds::backoff::empty. + - opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled) + To enable item counting use \p cds::atomicity::item_counter + - opt::stat - the type to gather internal statistics. + Possible statistics types are: \p optimistic_queue::stat, \p optimistic_queue::empty_stat, + user-provided class that supports \p %optimistic_queue::stat interface. + Default is \p %optimistic_queue::empty_stat. + - opt::alignment - the alignment for internal queue data. Default is \p opt::cache_line_alignment + - 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). + + Example: declare \p OptimisticQueue with item counting and internal statistics + \code + typedef cds::container::OptimisticQueue< cds::gc::HP, Foo, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter >, + cds::opt::stat< cds::container::optimistic_queue::stat<> > + >::type + > myQueue; + \endcode + */ + template + struct make_traits { +# ifdef CDS_DOXYGEN_INVOKED + typedef implementation_defined type; ///< Metafunction result +# else + typedef typename cds::opt::make_options< + typename cds::opt::find_type_traits< traits, Options... >::type + , Options... + >::type type; +# endif + }; + } // namespace optimistic_queue + //@cond namespace details { - template + template struct make_optimistic_queue { typedef GC gc; typedef T value_type; + typedef Traits traits; + /* struct default_options { typedef cds::backoff::empty back_off; typedef CDS_DEFAULT_ALLOCATOR allocator; @@ -27,13 +106,9 @@ namespace cds { namespace container { typedef opt::v::relaxed_ordering memory_model; enum { alignment = opt::cache_line_alignment }; }; + */ - typedef typename opt::make_options< - typename cds::opt::find_type_traits< default_options, Options... >::type - ,Options... - >::type options; - - struct node_type: public intrusive::optimistic_queue::node< gc > + struct node_type: public cds::intrusive::optimistic_queue::node< gc > { value_type m_value; @@ -47,8 +122,8 @@ namespace cds { namespace container { {} }; - typedef typename options::allocator::template rebind::other allocator_type; - typedef cds::details::Allocator< node_type, allocator_type > cxx_allocator; + typedef typename traits::allocator::template rebind::other allocator_type; + typedef cds::details::Allocator< node_type, allocator_type > cxx_allocator; struct node_deallocator { @@ -58,18 +133,14 @@ namespace cds { namespace container { } }; - typedef intrusive::OptimisticQueue< gc, - node_type - ,intrusive::opt::hook< - intrusive::optimistic_queue::base_hook< opt::gc > - > - ,opt::back_off< typename options::back_off > - ,intrusive::opt::disposer< node_deallocator > - ,opt::item_counter< typename options::item_counter > - ,opt::stat< typename options::stat > - ,opt::alignment< options::alignment > - ,opt::memory_model< typename options::memory_model > - > type; + struct intrusive_traits : public traits + { + typedef cds::intrusive::optimistic_queue::base_hook< opt::gc > hook; + typedef node_deallocator disposer; + static CDS_CONSTEXPR const opt::link_check_type link_checker = cds::intrusive::optimistic_queue::traits::link_checker; + }; + + typedef intrusive::OptimisticQueue< gc, node_type, intrusive_traits > type; }; } // namespace details //@endcond @@ -77,69 +148,67 @@ namespace cds { namespace container { /// Optimistic queue /** @ingroup cds_nonintrusive_queue Implementation of Ladan-Mozes & Shavit optimistic queue algorithm. - - \par Source: - [2008] Edya Ladan-Mozes, Nir Shavit "An Optimistic Approach to Lock-Free FIFO Queues" + - [2008] Edya Ladan-Mozes, Nir Shavit "An Optimistic Approach to Lock-Free FIFO Queues" Template arguments: - \p GC - garbage collector type: gc::HP, gc::PTB. Note that gc::HRC is not supported - - \p T - type to be stored in the queue - - \p Options - options - - \p Options are: - - opt::back_off - back-off strategy used. If the option is not specified, the cds::backoff::empty is used. - - opt::allocator - allocator (like \p std::allocator) used for nodes allocation. Default is \ref CDS_DEFAULT_ALLOCATOR - - opt::item_counter - the type of item counting feature. Default is \ref atomicity::empty_item_counter - - opt::stat - the type to gather internal statistics for debugging and profiling purposes. - Possible option value are: intrusive::optimistic_queue::stat, intrusive::optimistic_queue::dummy_stat (the default), - user-provided class that supports intrusive::optimistic_queue::stat interface. - Generic option intrusive::queue_stat and intrusive::queue_dummy_stat are acceptable too, however, - they will be automatically converted to intrusive::optimistic_queue::stat and intrusive::optimistic_queue::dummy_stat - respectively. - - opt::alignment - the alignment for internal queue data. Default is opt::cache_line_alignment - - 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). - - Warning gc::HRC is not supported for this implementation. + - \p T - type of values to be stored in the queue + - \p Traits - queue traits, default is \p optimistic_queue::traits. You can use \p optimistic_queue::make_traits + metafunction to make your traits or just derive your traits from \p %optimistic_queue::traits: + \code + struct myTraits: public cds::container::optimistic_queue::traits { + typedef cds::intrusive::optimistic_queue::stat<> stat; + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::OptimisticQueue< cds::gc::HP, Foo, myTraits > myQueue; + + // Equivalent make_traits example: + typedef cds::container::OptimisticQueue< cds::gc::HP, Foo, + typename cds::container::optimistic_queue::make_traits< + cds::opt::stat< cds::container::optimistic_queue::stat<> >, + cds::opt::item_counter< cds::atomicity::item_counter > + >::type + > myQueue; + \endcode */ - template + template class OptimisticQueue: #ifdef CDS_DOXYGEN_INVOKED - intrusive::OptimisticQueue< GC, intrusive::optimistic_queue::node< T >, Options... > + private intrusive::OptimisticQueue< GC, cds::intrusive::optimistic_queue::node< T >, Traits > #else - details::make_optimistic_queue< GC, T, Options... >::type + private details::make_optimistic_queue< GC, T, Traits >::type #endif { //@cond - typedef details::make_optimistic_queue< GC, T, Options... > options; - typedef typename options::type base_class; + typedef details::make_optimistic_queue< GC, T, Traits > maker; + typedef typename maker::type base_class; //@endcond public: /// Rebind template arguments - template + template struct rebind { - typedef OptimisticQueue< GC2, T2, Options2...> other ; ///< Rebinding result + typedef OptimisticQueue< GC2, T2, Traits2 > other ; ///< Rebinding result }; public: - typedef T value_type ; ///< Value type stored in the stack + typedef GC gc; ///< Garbage collector + typedef T value_type; ///< Value type to be stored in the queue + typedef Traits traits; ///< Queue traits - typedef typename base_class::gc gc ; ///< Garbage collector used - typedef typename base_class::back_off back_off ; ///< Back-off strategy used - typedef typename options::allocator_type allocator_type ; ///< Allocator type used for allocate/deallocate the nodes - typedef typename options::options::item_counter item_counter ; ///< Item counting policy used - typedef typename options::options::stat stat ; ///< Internal statistics policy used - typedef typename base_class::memory_model memory_model ; ///< Memory ordering. See cds::opt::memory_model option + typedef typename base_class::back_off back_off; ///< Back-off strategy used + typedef typename maker::allocator_type allocator_type; ///< Allocator type used for allocate/deallocate the nodes + typedef typename base_class::item_counter item_counter; ///< Item counting policy used + typedef typename base_class::stat stat; ///< Internal statistics policy used + typedef typename base_class::memory_model memory_model; ///< Memory ordering. See \p cds::opt::memory_model option static CDS_CONSTEXPR_CONST size_t c_nHazardPtrCount = base_class::c_nHazardPtrCount; ///< Count of hazard pointer required for the algorithm protected: - typedef typename options::node_type node_type ; ///< queue node type (derived from intrusive::optimistic_queue::node) - //@cond - typedef typename options::cxx_allocator cxx_allocator; - typedef typename options::node_deallocator node_deallocator; // deallocate node + typedef typename maker::node_type node_type; ///< queue node type (derived from intrusive::optimistic_queue::node) + typedef typename maker::cxx_allocator cxx_allocator; + typedef typename maker::node_deallocator node_deallocator; // deallocate node typedef typename base_class::node_traits node_traits; //@endcond @@ -181,22 +250,10 @@ namespace cds { namespace container { ~OptimisticQueue() {} - /// Returns queue's item count (see \ref intrusive::OptimisticQueue::size for explanation) - size_t size() const - { - return base_class::size(); - } - - /// Returns reference to internal statistics - const stat& statistics() const - { - return base_class::statistics(); - } - /// Enqueues \p val value into the queue. /** The function makes queue node in dynamic memory calling copy constructor for \p val - and then it calls intrusive::OptimisticQueue::enqueue. + and then it calls \p intrusive::OptimisticQueue::enqueue. Returns \p true if success, \p false otherwise. */ bool enqueue( const value_type& val ) @@ -209,29 +266,21 @@ namespace cds { namespace container { return false; } - /// Enqueues \p data to queue using copy functor + /// Enqueues \p data to queue using a functor /** - \p Func is a functor called to copy value \p data of type \p Type - which may be differ from type \p T stored in the queue. - The functor's interface is: + \p Func is a functor called to create node. + The functor \p f takes one argument - a reference to a new node of type \ref value_type : \code - struct myFunctor { - void operator()(T& dest, SOURCE const& data) - { - // // Code to copy \p data to \p dest - dest = data; - } - }; + cds::container::OptimisticQueue< cds::gc::HP, Foo > myQueue; + Bar bar; + myQueue.enqueue_with( [&bar]( Foo& dest ) { dest = bar; } ); \endcode - You may use \p boost:ref construction to pass functor \p f by reference. - - Requirements The functor \p Func should not throw any exception. */ - template - bool enqueue( const Type& data, Func f ) + template + bool enqueue_with( Func f ) { scoped_node_ptr p( alloc_node() ); - f( p->m_value, data ); + f( p->m_value ); if ( base_class::enqueue( *p )) { p.release(); return true; @@ -251,74 +300,68 @@ namespace cds { namespace container { return false; } - /// Dequeues a value using copy functor - /** - \p Func is a functor called to copy dequeued value to \p dest of type \p Type - which may be differ from type \p T stored in the queue. - The functor's interface is: - \code - struct myFunctor { - void operator()(Type& dest, T const& data) - { - // Code to copy \p data to \p dest - dest = data; - } - }; - \endcode - You may use \p boost:ref construction to pass functor \p f by reference. - - Requirements The functor \p Func should not throw any exception. - */ - template - bool dequeue( Type& dest, Func f ) + /// Synonym for \p enqueue() function + bool push( const value_type& val ) { - typename base_class::dequeue_result res; - if ( base_class::do_dequeue( res )) { - f( dest, node_traits::to_value_ptr( *res.pNext )->m_value ); - - base_class::dispose_result( res ); + return enqueue( val ); + } - return true; - } - return false; + /// Synonym for \p enqueue_with() function + template + bool push_with( Func f ) + { + return enqueue_with( f ); } /// Dequeues a value from the queue /** If queue is not empty, the function returns \p true, \p dest contains copy of - dequeued value. The assignment operator for type \ref value_type is invoked. + dequeued value. The assignment operator for type \p value_type is invoked. + If queue is empty, the function returns \p false, \p dest is unchanged. */ bool dequeue( value_type& dest ) { typedef cds::details::trivial_assign functor; - return dequeue( dest, functor() ); + return dequeue_with( [&dest]( value_type& src ) { dest = src; } ); } - /// Synonym for \ref enqueue function - bool push( const value_type& val ) + /// Dequeues a value using a functor + /** + \p Func is a functor called to copy dequeued value. + The functor takes one argument - a reference to removed node: + \code + cds:container::OptimisticQueue< cds::gc::HP, Foo > myQueue; + Bar bar; + myQueue.dequeue_with( [&bar]( Foo& src ) { bar = std::move( src );}); + \endcode + The functor is called only if the queue is not empty. + */ + template + bool dequeue_with( Func f ) { - return enqueue( val ); - } + typename base_class::dequeue_result res; + if ( base_class::do_dequeue( res ) ) { + f( node_traits::to_value_ptr( *res.pNext )->m_value ); - /// Synonym for template version of \ref enqueue function - template - bool push( const Type& data, Func f ) - { - return enqueue( data, f ); + base_class::dispose_result( res ); + + return true; + } + return false; } - /// Synonym for \ref dequeue function + /// Synonym for \ref dequeue() function bool pop( value_type& dest ) { return dequeue( dest ); } - /// Synonym for template version of \ref dequeue function - template - bool pop( Type& dest, Func f ) + /// Synonym for template version of \p dequeue_with() function + template + bool pop_with( Func f ) { - return dequeue( dest, f ); + return dequeue_with( f ); } /// Checks if the queue is empty @@ -335,6 +378,20 @@ namespace cds { namespace container { { base_class::clear(); } + + /// Returns queue's item count + /** \copydetails cds::intrusive::OptimisticQueue::size() + */ + size_t size() const + { + return base_class::size(); + } + + /// Returns reference to internal statistics + const stat& statistics() const + { + return base_class::statistics(); + } }; }} // namespace cds::container diff --git a/projects/Win/vc12/hdr-test-queue.vcxproj b/projects/Win/vc12/hdr-test-queue.vcxproj index 0f7646ad..461d1e33 100644 --- a/projects/Win/vc12/hdr-test-queue.vcxproj +++ b/projects/Win/vc12/hdr-test-queue.vcxproj @@ -555,8 +555,8 @@ - - + + diff --git a/projects/Win/vc12/hdr-test-queue.vcxproj.filters b/projects/Win/vc12/hdr-test-queue.vcxproj.filters index 5b34321c..e5089e33 100644 --- a/projects/Win/vc12/hdr-test-queue.vcxproj.filters +++ b/projects/Win/vc12/hdr-test-queue.vcxproj.filters @@ -31,12 +31,6 @@ intrusive - - container - - - container - container @@ -80,6 +74,12 @@ intrusive + + container + + + container + diff --git a/tests/test-hdr/queue/hdr_optimistic_dhp.cpp b/tests/test-hdr/queue/hdr_optimistic_dhp.cpp new file mode 100644 index 00000000..aa6ce381 --- /dev/null +++ b/tests/test-hdr/queue/hdr_optimistic_dhp.cpp @@ -0,0 +1,117 @@ +//$$CDS-header$$ + +#include +#include + +#include "queue/hdr_queue_new.h" + +namespace queue { + + void HdrTestQueue::OptimisticQueue_DHP() + { + test_no_ic >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_Counted() + { + struct queue_traits : public cds::container::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + test_ic >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_relax() + { + struct queue_traits : public cds::container::optimistic_queue::traits + { + typedef cds::opt::v::relaxed_ordering memory_model; + }; + test_no_ic >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_Counted_relax() + { + struct queue_traits : public cds::container::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + typedef cds::opt::v::relaxed_ordering memory_model; + }; + test_ic < + cds::container::OptimisticQueue< cds::gc::DHP, int, queue_traits > >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_seqcst() + { + test_no_ic< + cds::container::OptimisticQueue< cds::gc::DHP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::memory_model< cds::opt::v::sequential_consistent> + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_Counted_seqcst() + { + test_ic< + cds::container::OptimisticQueue< cds::gc::DHP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::memory_model< cds::opt::v::sequential_consistent> + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_relax_align() + { + test_no_ic< + cds::container::OptimisticQueue< cds::gc::DHP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + ,cds::opt::alignment< 16 > + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_Counted_relax_align() + { + test_ic< + cds::container::OptimisticQueue< cds::gc::DHP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> + ,cds::opt::alignment< 32 > + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_seqcst_align() + { + test_no_ic< + cds::container::OptimisticQueue< cds::gc::DHP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::memory_model< cds::opt::v::sequential_consistent> + ,cds::opt::alignment< cds::opt::no_special_alignment > + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_DHP_Counted_seqcst_align() + { + test_ic< + cds::container::OptimisticQueue< cds::gc::DHP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::memory_model< cds::opt::v::sequential_consistent> + ,cds::opt::alignment< cds::opt::cache_line_alignment > + >::type + > + >(); + } + +} // namespace queue diff --git a/tests/test-hdr/queue/hdr_optimistic_hp.cpp b/tests/test-hdr/queue/hdr_optimistic_hp.cpp new file mode 100644 index 00000000..b73d0d30 --- /dev/null +++ b/tests/test-hdr/queue/hdr_optimistic_hp.cpp @@ -0,0 +1,117 @@ +//$$CDS-header$$ + +#include +#include + +#include "queue/hdr_queue_new.h" + +namespace queue { + + void HdrTestQueue::OptimisticQueue_HP() + { + test_no_ic >(); + } + + void HdrTestQueue::OptimisticQueue_HP_Counted() + { + struct queue_traits : public cds::container::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + test_ic >(); + } + + void HdrTestQueue::OptimisticQueue_HP_relax() + { + struct queue_traits : public cds::container::optimistic_queue::traits + { + typedef cds::opt::v::relaxed_ordering memory_model; + }; + test_no_ic >(); + } + + void HdrTestQueue::OptimisticQueue_HP_Counted_relax() + { + struct queue_traits : public cds::container::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + typedef cds::opt::v::relaxed_ordering memory_model; + }; + test_ic < + cds::container::OptimisticQueue< cds::gc::HP, int, queue_traits > >(); + } + + void HdrTestQueue::OptimisticQueue_HP_seqcst() + { + test_no_ic< + cds::container::OptimisticQueue< cds::gc::HP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::memory_model< cds::opt::v::sequential_consistent> + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_HP_Counted_seqcst() + { + test_ic< + cds::container::OptimisticQueue< cds::gc::HP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::memory_model< cds::opt::v::sequential_consistent> + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_HP_relax_align() + { + test_no_ic< + cds::container::OptimisticQueue< cds::gc::HP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::memory_model< cds::opt::v::relaxed_ordering> + ,cds::opt::alignment< 16 > + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_HP_Counted_relax_align() + { + test_ic< + cds::container::OptimisticQueue< cds::gc::HP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> + ,cds::opt::alignment< 32 > + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_HP_seqcst_align() + { + test_no_ic< + cds::container::OptimisticQueue< cds::gc::HP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::memory_model< cds::opt::v::sequential_consistent> + ,cds::opt::alignment< cds::opt::no_special_alignment > + >::type + > + >(); + } + + void HdrTestQueue::OptimisticQueue_HP_Counted_seqcst_align() + { + test_ic< + cds::container::OptimisticQueue< cds::gc::HP, int, + typename cds::container::optimistic_queue::make_traits< + cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::memory_model< cds::opt::v::sequential_consistent> + ,cds::opt::alignment< cds::opt::cache_line_alignment > + >::type + > + >(); + } + +} // namespace queue diff --git a/tests/test-hdr/queue/hdr_optimistic_hzp.cpp b/tests/test-hdr/queue/hdr_optimistic_hzp.cpp deleted file mode 100644 index 250fd06a..00000000 --- a/tests/test-hdr/queue/hdr_optimistic_hzp.cpp +++ /dev/null @@ -1,107 +0,0 @@ -//$$CDS-header$$ - -#include -#include - -#include "queue/hdr_queue.h" - -namespace queue { - - void Queue_TestHeader::OptimisticQueue_HP() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_Counted() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_relax() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_Counted_relax() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_seqcst() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_Counted_seqcst() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_relax_align() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 16 > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_Counted_relax_align() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 32 > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_seqcst_align() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::no_special_alignment > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_HP_Counted_seqcst_align() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::HP, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::cache_line_alignment > - > - >(); - } - -} // namespace queue diff --git a/tests/test-hdr/queue/hdr_optimistic_ptb.cpp b/tests/test-hdr/queue/hdr_optimistic_ptb.cpp deleted file mode 100644 index 0a89daa2..00000000 --- a/tests/test-hdr/queue/hdr_optimistic_ptb.cpp +++ /dev/null @@ -1,107 +0,0 @@ -//$$CDS-header$$ - -#include -#include - -#include "queue/hdr_queue.h" - -namespace queue { - - void Queue_TestHeader::OptimisticQueue_PTB() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_Counted() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_relax() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_Counted_relax() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_seqcst() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_Counted_seqcst() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_relax_align() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 16 > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_Counted_relax_align() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 32 > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_seqcst_align() - { - testNoItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::no_special_alignment > - > - >(); - } - - void Queue_TestHeader::OptimisticQueue_PTB_Counted_seqcst_align() - { - testWithItemCounter< - cds::container::OptimisticQueue< cds::gc::PTB, int - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::cache_line_alignment > - > - >(); - } - -} // namespace queue diff --git a/tests/test-hdr/queue/hdr_queue.h b/tests/test-hdr/queue/hdr_queue.h index db33b922..728885e8 100644 --- a/tests/test-hdr/queue/hdr_queue.h +++ b/tests/test-hdr/queue/hdr_queue.h @@ -139,28 +139,6 @@ namespace queue { } public: - void OptimisticQueue_HP(); - void OptimisticQueue_HP_relax(); - void OptimisticQueue_HP_seqcst(); - void OptimisticQueue_HP_relax_align(); - void OptimisticQueue_HP_seqcst_align(); - void OptimisticQueue_HP_Counted(); - void OptimisticQueue_HP_Counted_relax(); - void OptimisticQueue_HP_Counted_seqcst(); - void OptimisticQueue_HP_Counted_relax_align(); - void OptimisticQueue_HP_Counted_seqcst_align(); - - void OptimisticQueue_PTB(); - void OptimisticQueue_PTB_relax(); - void OptimisticQueue_PTB_seqcst(); - void OptimisticQueue_PTB_relax_align(); - void OptimisticQueue_PTB_seqcst_align(); - void OptimisticQueue_PTB_Counted(); - void OptimisticQueue_PTB_Counted_relax(); - void OptimisticQueue_PTB_Counted_seqcst(); - void OptimisticQueue_PTB_Counted_relax_align(); - void OptimisticQueue_PTB_Counted_seqcst_align(); - void FCQueue_deque(); void FCQueue_deque_elimination(); void FCQueue_deque_mutex(); @@ -177,28 +155,6 @@ namespace queue { void RWQueue_Counted(); CPPUNIT_TEST_SUITE(Queue_TestHeader) - CPPUNIT_TEST(OptimisticQueue_HP); - CPPUNIT_TEST(OptimisticQueue_HP_relax); - CPPUNIT_TEST(OptimisticQueue_HP_seqcst); - CPPUNIT_TEST(OptimisticQueue_HP_relax_align); - CPPUNIT_TEST(OptimisticQueue_HP_seqcst_align); - CPPUNIT_TEST(OptimisticQueue_HP_Counted); - CPPUNIT_TEST(OptimisticQueue_HP_Counted_relax); - CPPUNIT_TEST(OptimisticQueue_HP_Counted_seqcst); - CPPUNIT_TEST(OptimisticQueue_HP_Counted_relax_align); - CPPUNIT_TEST(OptimisticQueue_HP_Counted_seqcst_align); - - CPPUNIT_TEST(OptimisticQueue_PTB); - CPPUNIT_TEST(OptimisticQueue_PTB_relax); - CPPUNIT_TEST(OptimisticQueue_PTB_seqcst); - CPPUNIT_TEST(OptimisticQueue_PTB_relax_align); - CPPUNIT_TEST(OptimisticQueue_PTB_seqcst_align); - CPPUNIT_TEST(OptimisticQueue_PTB_Counted); - CPPUNIT_TEST(OptimisticQueue_PTB_Counted_relax); - CPPUNIT_TEST(OptimisticQueue_PTB_Counted_seqcst); - CPPUNIT_TEST(OptimisticQueue_PTB_Counted_relax_align); - CPPUNIT_TEST(OptimisticQueue_PTB_Counted_seqcst_align); - CPPUNIT_TEST(FCQueue_deque) CPPUNIT_TEST(FCQueue_deque_elimination) CPPUNIT_TEST(FCQueue_deque_mutex) diff --git a/tests/test-hdr/queue/hdr_queue_new.h b/tests/test-hdr/queue/hdr_queue_new.h index e10b82d4..4fb373ee 100644 --- a/tests/test-hdr/queue/hdr_queue_new.h +++ b/tests/test-hdr/queue/hdr_queue_new.h @@ -244,7 +244,6 @@ namespace queue { void MoirQueue_DHP_Counted_relax_align(); void MoirQueue_DHP_Counted_seqcst_align(); -/* void OptimisticQueue_HP(); void OptimisticQueue_HP_relax(); void OptimisticQueue_HP_seqcst(); @@ -266,7 +265,7 @@ namespace queue { void OptimisticQueue_DHP_Counted_seqcst(); void OptimisticQueue_DHP_Counted_relax_align(); void OptimisticQueue_DHP_Counted_seqcst_align(); -*/ + void BasketQueue_HP(); void BasketQueue_HP_relax(); void BasketQueue_HP_seqcst(); @@ -349,7 +348,7 @@ namespace queue { CPPUNIT_TEST(MoirQueue_DHP_Counted_seqcst); CPPUNIT_TEST(MoirQueue_DHP_Counted_relax_align); CPPUNIT_TEST(MoirQueue_DHP_Counted_seqcst_align); -/* + CPPUNIT_TEST(OptimisticQueue_HP); CPPUNIT_TEST(OptimisticQueue_HP_relax); CPPUNIT_TEST(OptimisticQueue_HP_seqcst); @@ -371,7 +370,7 @@ namespace queue { CPPUNIT_TEST(OptimisticQueue_DHP_Counted_seqcst); CPPUNIT_TEST(OptimisticQueue_DHP_Counted_relax_align); CPPUNIT_TEST(OptimisticQueue_DHP_Counted_seqcst_align); -*/ + CPPUNIT_TEST(BasketQueue_HP); CPPUNIT_TEST(BasketQueue_HP_relax); CPPUNIT_TEST(BasketQueue_HP_seqcst); diff --git a/tests/unit/queue/queue_defs.h b/tests/unit/queue/queue_defs.h index 29c1b8f5..1731ad3e 100644 --- a/tests/unit/queue/queue_defs.h +++ b/tests/unit/queue/queue_defs.h @@ -61,11 +61,11 @@ TEST_CASE(OptimisticQueue_HP_seqcst, ITEM_TYPE ) \ TEST_CASE(OptimisticQueue_HP_ic, ITEM_TYPE ) \ TEST_CASE(OptimisticQueue_HP_stat, ITEM_TYPE ) \ - TEST_CASE(OptimisticQueue_PTB, ITEM_TYPE ) \ - TEST_CASE(OptimisticQueue_PTB_michaelAlloc, ITEM_TYPE ) \ - TEST_CASE(OptimisticQueue_PTB_seqcst, ITEM_TYPE ) \ - TEST_CASE(OptimisticQueue_PTB_ic, ITEM_TYPE ) \ - TEST_CASE(OptimisticQueue_PTB_stat, ITEM_TYPE ) + TEST_CASE(OptimisticQueue_DHP, ITEM_TYPE ) \ + TEST_CASE(OptimisticQueue_DHP_michaelAlloc, ITEM_TYPE ) \ + TEST_CASE(OptimisticQueue_DHP_seqcst, ITEM_TYPE ) \ + TEST_CASE(OptimisticQueue_DHP_ic, ITEM_TYPE ) \ + TEST_CASE(OptimisticQueue_DHP_stat, ITEM_TYPE ) #define CDSUNIT_TEST_OptimisticQueue \ CPPUNIT_TEST(OptimisticQueue_HP) \ @@ -73,11 +73,11 @@ CPPUNIT_TEST(OptimisticQueue_HP_seqcst) \ CPPUNIT_TEST(OptimisticQueue_HP_ic) \ CPPUNIT_TEST(OptimisticQueue_HP_stat) \ - CPPUNIT_TEST(OptimisticQueue_PTB) \ - CPPUNIT_TEST(OptimisticQueue_PTB_michaelAlloc) \ - CPPUNIT_TEST(OptimisticQueue_PTB_seqcst) \ - CPPUNIT_TEST(OptimisticQueue_PTB_ic) \ - CPPUNIT_TEST(OptimisticQueue_PTB_stat) + CPPUNIT_TEST(OptimisticQueue_DHP) \ + CPPUNIT_TEST(OptimisticQueue_DHP_michaelAlloc) \ + CPPUNIT_TEST(OptimisticQueue_DHP_seqcst) \ + CPPUNIT_TEST(OptimisticQueue_DHP_ic) \ + CPPUNIT_TEST(OptimisticQueue_DHP_stat) // BasketQueue diff --git a/tests/unit/queue/queue_type.h b/tests/unit/queue/queue_type.h index 6b450956..1060ea11 100644 --- a/tests/unit/queue/queue_type.h +++ b/tests/unit/queue/queue_type.h @@ -149,56 +149,38 @@ namespace queue { // OptimisticQueue - typedef cds::container::OptimisticQueue< cds::gc::HP, - Value - > OptimisticQueue_HP; - - typedef cds::container::OptimisticQueue< cds::gc::HP, - Value - ,cds::opt::allocator< memory::MichaelAllocator > - > OptimisticQueue_HP_michaelAlloc; - - typedef cds::container::OptimisticQueue< cds::gc::HP, - Value - ,cds::opt::memory_model< cds::opt::v::sequential_consistent > - > OptimisticQueue_HP_seqcst; - - typedef cds::container::OptimisticQueue< cds::gc::PTB, - Value - > OptimisticQueue_PTB; - - typedef cds::container::OptimisticQueue< cds::gc::PTB, - Value - ,cds::opt::allocator< memory::MichaelAllocator > - > OptimisticQueue_PTB_michaelAlloc; - - typedef cds::container::OptimisticQueue< cds::gc::PTB, - Value - ,cds::opt::memory_model< cds::opt::v::sequential_consistent > - > OptimisticQueue_PTB_seqcst; + typedef cds::container::OptimisticQueue< cds::gc::HP, Value > OptimisticQueue_HP; + typedef cds::container::OptimisticQueue< cds::gc::PTB, Value > OptimisticQueue_PTB; + struct traits_OptimisticQueue_michaelAlloc : public cds::container::optimistic_queue::traits + { + typedef memory::MichaelAllocator allocator; + }; + typedef cds::container::OptimisticQueue< cds::gc::HP, Value, traits_OptimisticQueue_michaelAlloc > OptimisticQueue_HP_michaelAlloc; + typedef cds::container::OptimisticQueue< cds::gc::DHP, Value, traits_OptimisticQueue_michaelAlloc > OptimisticQueue_DHP_michaelAlloc; - // OptimisticQueue + item counter - typedef cds::container::OptimisticQueue< cds::gc::HP, - Value - ,cds::opt::item_counter< cds::atomicity::item_counter > - > OptimisticQueue_HP_ic; + struct traits_OptimisticQueue_seqcst : public cds::container::optimistic_queue::traits + { + typedef cds::opt::v::sequential_consistent memory_model; + }; + typedef cds::container::OptimisticQueue< cds::gc::HP, Value, traits_OptimisticQueue_seqcst > OptimisticQueue_HP_seqcst; + typedef cds::container::OptimisticQueue< cds::gc::DHP, Value, traits_OptimisticQueue_seqcst > OptimisticQueue_DHP_seqcst; - typedef cds::container::OptimisticQueue< cds::gc::PTB, - Value - ,cds::opt::item_counter< cds::atomicity::item_counter > - > OptimisticQueue_PTB_ic; + struct traits_OptimisticQueue_ic : public cds::container::optimistic_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + }; + typedef cds::container::OptimisticQueue< cds::gc::HP, Value, traits_OptimisticQueue_ic > OptimisticQueue_HP_ic; + typedef cds::container::OptimisticQueue< cds::gc::DHP, Value, traits_OptimisticQueue_ic > OptimisticQueue_DHP_ic; - // OptimisticQueue + stat - typedef cds::container::OptimisticQueue< cds::gc::HP, - Value - ,cds::opt::stat< cds::intrusive::queue_stat<> > - > OptimisticQueue_HP_stat; + struct traits_OptimisticQueue_stat : public + cds::container::optimistic_queue::make_traits < + cds::opt::stat < cds::intrusive::queue_stat<> > + > ::type + {}; + typedef cds::container::OptimisticQueue< cds::gc::HP, Value, traits_OptimisticQueue_stat > OptimisticQueue_HP_stat; + typedef cds::container::OptimisticQueue< cds::gc::DHP, Value, traits_OptimisticQueue_stat > OptimisticQueue_DHP_stat; - typedef cds::container::OptimisticQueue< cds::gc::PTB, - Value - ,cds::opt::stat< cds::intrusive::queue_stat<> > - > OptimisticQueue_PTB_stat; // TsigasCycleQueue class TsigasCycleQueue_dyn -- 2.34.1