From: khizmax Date: Thu, 9 Oct 2014 10:43:55 +0000 (+0400) Subject: SegmentedQueue refactoring X-Git-Tag: v2.0.0~210 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=commitdiff_plain;h=e38aa8b1f1c6467817e50d6381e9a00ea03b4d13 SegmentedQueue refactoring --- diff --git a/cds/container/msqueue.h b/cds/container/msqueue.h index 42c5c5aa..c09d0a19 100644 --- a/cds/container/msqueue.h +++ b/cds/container/msqueue.h @@ -253,7 +253,7 @@ namespace cds { namespace container { return false; } - /// Enqueues \p data to the queue using a functor + /// Enqueues data to the queue using a functor /** \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 : diff --git a/cds/container/segmented_queue.h b/cds/container/segmented_queue.h index f5c506c8..73ae5a11 100644 --- a/cds/container/segmented_queue.h +++ b/cds/container/segmented_queue.h @@ -24,7 +24,7 @@ namespace cds { namespace container { typedef cds::intrusive::segmented_queue::empty_stat empty_stat; /// SegmentedQueue default type traits - struct type_traits { + struct traits { /// Item allocator. Default is \ref CDS_DEFAULT_ALLOCATOR typedef CDS_DEFAULT_ALLOCATOR node_allocator; @@ -58,7 +58,7 @@ namespace cds { namespace container { /// Metafunction converting option list to traits for SegmentedQueue /** - The metafunction can be useful if a few fields in \ref type_traits should be changed. + The metafunction can be useful if a few fields in \p segmented_queue::traits should be changed. For example: \code typedef cds::container::segmented_queue::make_traits< @@ -66,21 +66,21 @@ namespace cds { namespace container { >::type my_segmented_queue_traits; \endcode This code creates \p %SegmentedQueue type traits with item counting feature, - all other \p type_traits members left unchanged. + all other \p segmented_queue::traits members left unchanged. \p Options are: - \p opt::node_allocator - node allocator. - - \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default) - - \p opt::item_counter - item counting feature. Note that atomicity::empty_item_counetr is not suitable + - \p opt::stat - internal statistics, possible type: \p segmented_queue::stat, \p segmented_queue::empty_stat (the default) + - \p opt::item_counter - item counting feature. Note that \p atomicity::empty_item_counetr is not suitable for segmented queue. - \p opt::memory_model - memory model, default is \p opt::v::relaxed_ordering. See option description for the full list of possible models - - \p opt::alignment - the alignmentfor critical data, see option description for explanation + - \p opt::alignment - the alignment of critical data, see option description for explanation - \p opt::allocator - the allocator used to maintain segments. - \p opt::lock_type - a mutual exclusion lock type used to maintain internal list of allocated segments. Default is \p cds::opt::Spin, \p std::mutex is also suitable. - \p opt::permutation_generator - a random permutation generator for sequence [0, quasi_factor), - default is cds::opt::v::random2_permutation + default is \p cds::opt::v::random2_permutation */ template struct make_traits { @@ -88,7 +88,7 @@ namespace cds { namespace container { 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 @@ -114,7 +114,8 @@ namespace cds { namespace container { } }; - struct intrusive_type_traits: public original_type_traits { + struct intrusive_type_traits: public original_type_traits + { typedef node_disposer disposer; }; @@ -161,11 +162,11 @@ namespace cds { namespace container { Template parameters: - \p GC - a garbage collector, possible types are cds::gc::HP, cds::gc::PTB - \p T - the type of values stored in the queue - - \p Traits - queue type traits, default is segmented_queue::type_traits. - segmented_queue::make_traits metafunction can be used to construct your + - \p Traits - queue type traits, default is \p segmented_queue::type_traits. + \p segmented_queue::make_traits metafunction can be used to construct your type traits. */ - template + template class SegmentedQueue: #ifdef CDS_DOXYGEN_INVOKED public cds::intrusive::SegmentedQueue< GC, T, Traits > @@ -178,11 +179,11 @@ namespace cds { namespace container { typedef typename maker::type base_class; //@endcond public: - typedef GC gc ; ///< Garbage collector - typedef T value_type ; ///< type of the value stored in the queue - typedef Traits options ; ///< Queue's traits + typedef GC gc; ///< Garbage collector + typedef T value_type; ///< type of the value stored in the queue + typedef Traits traits; ///< Queue traits - typedef typename options::node_allocator node_allocator; ///< Node allocator + typedef typename traits::node_allocator node_allocator; ///< Node allocator typedef typename base_class::memory_model memory_model; ///< Memory ordering. See cds::opt::memory_model option typedef typename base_class::item_counter item_counter; ///< Item counting policy, see cds::opt::item_counter option setter typedef typename base_class::stat stat ; ///< Internal statistics policy @@ -211,11 +212,6 @@ namespace cds { namespace container { { return cxx_node_allocator().MoveNew( std::forward( args )... ); } - - struct dummy_disposer { - void operator()( value_type * p ) - {} - }; //@endcond public: @@ -246,45 +242,40 @@ namespace cds { namespace container { return false; } - /// Synonym for enqueue(value_type const&) function - bool push( value_type const& val ) - { - return enqueue( val ); - } - - /// Inserts a new element at last segment of the queue using copy functor + /// Enqueues data to the queue using a functor /** - \p Func is a functor called to copy value \p data of type \p Q - which may be differ from type \ref value_type 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()(value_type& dest, Q const& data) - { - // // Code to copy \p data to \p dest - dest = data; - } - }; + cds::container::SegmentedQueue< 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. */ - template - bool enqueue( Q const& data, Func f ) + template + bool enqueue_with( Func f ) { scoped_node_ptr p( alloc_node() ); - f( *p, data ); - if ( base_class::enqueue( *p )) { + f( *p ); + if ( base_class::enqueue( *p ) ) { p.release(); return true; } return false; } - /// Synonym for enqueue(Q const&, Func) function - template - bool push( Q const& data, Func f ) + + /// Synonym for \p enqueue() member function + bool push( value_type const& val ) { - return enqueue( data, f ); + return enqueue( val ); + } + + /// Synonym for \p enqueue_with() member function + template + bool push_with( Func f ) + { + return enqueue_with( f ); } /// Enqueues data of type \ref value_type constructed with std::forward(args)... @@ -299,54 +290,48 @@ namespace cds { namespace container { return false; } - /// Removes an element from first segment of the queue + /// 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. + If queue is empty, the function returns \p false, \p dest is unchanged. + */ + bool dequeue( value_type& dest ) + { + return dequeue_with( [&dest]( value_type& src ) { dest = src; }); + } + + /// Dequeues a value using a functor /** - \p Func is a functor called to copy dequeued value to \p dest of type \p Q - which may be differ from type \ref value_type stored in the queue. - The functor's interface is: + \p Func is a functor called to copy dequeued value. + The functor takes one argument - a reference to removed node: \code - struct myFunctor { - void operator()(Q& dest, value_type const& data) - { - // Code to copy \p data to \p dest - dest = data; - } - }; + cds:container::MSQueue< cds::gc::HP, Foo > myQueue; + Bar bar; + myQueue.dequeue_with( [&bar]( Foo& src ) { bar = std::move( src );}); \endcode - You may use \p boost:ref construction to pass functor \p f by reference. + The functor is called only if the queue is not empty. */ - template - bool dequeue( Q& dest, Func f ) + template + bool dequeue_with( Func f ) { value_type * p = base_class::dequeue(); if ( p ) { - f( dest, *p ); + f( *p ); gc::template retire< typename maker::node_disposer >( p ); return true; } return false; } - /// Synonym for dequeue( Q&, Func ) function + /// Synonym for \p dequeue_with() function template - bool pop( Q& dest, Func f ) - { - return dequeue( dest, 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. - If queue is empty, the function returns \p false, \p dest is unchanged. - */ - bool dequeue( value_type& dest ) + bool pop_with( Func f ) { - typedef cds::details::trivial_assign functor; - return dequeue( dest, functor() ); + return dequeue_with( f ); } - /// Synonym for dequeue(value_type&) function + /// Synonym for \p dequeue() function bool pop( value_type& dest ) { return dequeue( dest ); diff --git a/cds/intrusive/segmented_queue.h b/cds/intrusive/segmented_queue.h index 36e8abf1..85a7796b 100644 --- a/cds/intrusive/segmented_queue.h +++ b/cds/intrusive/segmented_queue.h @@ -24,7 +24,8 @@ namespace cds { namespace intrusive { /// SegmentedQueue internal statistics. May be used for debugging or profiling template - struct stat { + struct stat + { typedef Counter counter_type; ///< Counter type counter_type m_nPush; ///< Push count @@ -69,8 +70,8 @@ namespace cds { namespace intrusive { //@endcond }; - /// SegmentedQueue default type traits - struct type_traits { + /// SegmentedQueue default traits + struct traits { /// Element disposer that is called when the item to be dequeued. Default is opt::v::empty_disposer (no disposer) typedef opt::v::empty_disposer disposer; @@ -103,7 +104,7 @@ namespace cds { namespace intrusive { /// Metafunction converting option list to traits for SegmentedQueue /** - The metafunction can be useful if a few fields in \ref type_traits should be changed. + The metafunction can be useful if a few fields in \p segmented_queue::traits should be changed. For example: \code typedef cds::intrusive::segmented_queue::make_traits< @@ -111,21 +112,21 @@ namespace cds { namespace intrusive { >::type my_segmented_queue_traits; \endcode This code creates \p %SegmentedQueue type traits with item counting feature, - all other \p type_traits members left unchanged. + all other \p %segmented_queue::traits members left unchanged. \p Options are: - \p opt::disposer - the functor used for dispose removed items. - - \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default) - - \p opt::item_counter - item counting feature. Note that atomicity::empty_item_counetr is not suitable + - \p opt::stat - internal statistics, possible type: \p segmented_queue::stat, \p segmented_queue::empty_stat (the default) + - \p opt::item_counter - item counting feature. Note that \p atomicity::empty_item_counetr is not suitable for segmented queue. - \p opt::memory_model - memory model, default is \p opt::v::relaxed_ordering. See option description for the full list of possible models - \p opt::alignment - the alignment for critical data, see option description for explanation - - \p opt::allocator - the allocator used t maintain segments. + - \p opt::allocator - the allocator to be used for maintaining segments. - \p opt::lock_type - a mutual exclusion lock type used to maintain internal list of allocated segments. Default is \p cds::opt::Spin, \p std::mutex is also suitable. - \p opt::permutation_generator - a random permutation generator for sequence [0, quasi_factor), - default is cds::opt::v::random2_permutation + default is \p cds::opt::v::random2_permutation */ template struct make_traits { @@ -133,7 +134,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 @@ -177,27 +178,27 @@ namespace cds { namespace intrusive { Template parameters: - \p GC - a garbage collector, possible types are cds::gc::HP, cds::gc::PTB - \p T - the type of values stored in the queue - - \p Traits - queue type traits, default is segmented_queue::type_traits. - segmented_queue::make_traits metafunction can be used to construct the + - \p Traits - queue type traits, default is \p segmented_queue::traits. + \p segmented_queue::make_traits metafunction can be used to construct the type traits. The queue stores the pointers to enqueued items so no special node hooks are needed. */ - template + template class SegmentedQueue { public: - typedef GC gc ; ///< Garbage collector - typedef T value_type ; ///< type of the value stored in the queue - typedef Traits options ; ///< Queue's traits - - typedef typename options::disposer disposer ; ///< value disposer, called only in \p clear() when the element to be dequeued - typedef typename options::allocator allocator ; ///< Allocator maintaining the segments - typedef typename options::memory_model memory_model; ///< Memory ordering. See cds::opt::memory_model option - typedef typename options::item_counter item_counter; ///< Item counting policy, see cds::opt::item_counter option setter - typedef typename options::stat stat ; ///< Internal statistics policy - typedef typename options::lock_type lock_type ; ///< Type of mutex for maintaining an internal list of allocated segments. - typedef typename options::permutation_generator permutation_generator; ///< Random permutation generator for sequence [0, quasi-factor) + typedef GC gc; ///< Garbage collector + typedef T value_type; ///< type of the value stored in the queue + typedef Traits traits; ///< Queue traits + + typedef typename traits::disposer disposer ; ///< value disposer, called only in \p clear() when the element to be dequeued + typedef typename traits::allocator allocator; ///< Allocator maintaining the segments + typedef typename traits::memory_model memory_model; ///< Memory ordering. See cds::opt::memory_model option + typedef typename traits::item_counter item_counter; ///< Item counting policy, see cds::opt::item_counter option setter + typedef typename traits::stat stat; ///< Internal statistics policy + typedef typename traits::lock_type lock_type; ///< Type of mutex for maintaining an internal list of allocated segments. + typedef typename traits::permutation_generator permutation_generator; ///< Random permutation generator for sequence [0, quasi-factor) static const size_t m_nHazardPtrCount = 2 ; ///< Count of hazard pointer required for the algorithm @@ -234,7 +235,7 @@ namespace cds { namespace intrusive { segment(); //=delete }; - typedef typename opt::details::alignment_setter< atomics::atomic, options::alignment >::type aligned_segment_ptr; + typedef typename opt::details::alignment_setter< atomics::atomic, traits::alignment >::type aligned_segment_ptr; //@endcond protected: diff --git a/change.log b/change.log index a457c7cf..3e8089d4 100644 --- a/change.log +++ b/change.log @@ -10,6 +10,7 @@ cds::container::BasketQueue cds::container::OptimisticQueue cds::container::RWQueue + cds::container::SegmentedQueue 1.6.0 23.09.2014 General release diff --git a/projects/Win/vc12/hdr-test-queue.vcxproj b/projects/Win/vc12/hdr-test-queue.vcxproj index 461d1e33..1486e0ec 100644 --- a/projects/Win/vc12/hdr-test-queue.vcxproj +++ b/projects/Win/vc12/hdr-test-queue.vcxproj @@ -547,8 +547,8 @@ + - @@ -559,14 +559,13 @@ + - - diff --git a/projects/Win/vc12/hdr-test-queue.vcxproj.filters b/projects/Win/vc12/hdr-test-queue.vcxproj.filters index e5089e33..605c3263 100644 --- a/projects/Win/vc12/hdr-test-queue.vcxproj.filters +++ b/projects/Win/vc12/hdr-test-queue.vcxproj.filters @@ -22,9 +22,6 @@ intrusive - - intrusive - intrusive @@ -37,9 +34,6 @@ container - - container - container @@ -80,6 +74,12 @@ container + + intrusive + + + container + @@ -88,9 +88,6 @@ intrusive - - intrusive - container diff --git a/projects/source.test-hdr.mk b/projects/source.test-hdr.mk index 8940eed1..2ae45dc5 100644 --- a/projects/source.test-hdr.mk +++ b/projects/source.test-hdr.mk @@ -119,7 +119,7 @@ CDS_TESTHDR_QUEUE := \ tests/test-hdr/queue/hdr_queue_register.cpp \ tests/test-hdr/queue/hdr_intrusive_fcqueue.cpp \ tests/test-hdr/queue/hdr_intrusive_segmented_queue_hp.cpp \ - tests/test-hdr/queue/hdr_intrusive_segmented_queue_ptb.cpp \ + tests/test-hdr/queue/hdr_intrusive_segmented_queue_dhp.cpp \ tests/test-hdr/queue/hdr_intrusive_tsigas_cycle_queue.cpp \ tests/test-hdr/queue/hdr_intrusive_vyukovmpmc_cycle_queue.cpp \ tests/test-hdr/queue/hdr_basketqueue_hp.cpp \ @@ -133,7 +133,7 @@ CDS_TESTHDR_QUEUE := \ tests/test-hdr/queue/hdr_optimistic_dhp.cpp \ tests/test-hdr/queue/hdr_rwqueue.cpp \ tests/test-hdr/queue/hdr_segmented_queue_hp.cpp \ - tests/test-hdr/queue/hdr_segmented_queue_ptb.cpp \ + tests/test-hdr/queue/hdr_segmented_queue_dhp.cpp \ tests/test-hdr/queue/hdr_vyukov_mpmc_cyclic.cpp CDS_TESTHDR_SET := \ diff --git a/tests/test-hdr/queue/hdr_intrusive_segmented_queue.h b/tests/test-hdr/queue/hdr_intrusive_segmented_queue.h index a448c3ee..5847af6e 100644 --- a/tests/test-hdr/queue/hdr_intrusive_segmented_queue.h +++ b/tests/test-hdr/queue/hdr_intrusive_segmented_queue.h @@ -185,10 +185,10 @@ namespace queue { void SegmQueue_HP_shuffle(); void SegmQueue_HP_stat(); - void SegmQueue_PTB(); - void SegmQueue_PTB_mutex(); - void SegmQueue_PTB_shuffle(); - void SegmQueue_PTB_stat(); + void SegmQueue_DHP(); + void SegmQueue_DHP_mutex(); + void SegmQueue_DHP_shuffle(); + void SegmQueue_DHP_stat(); CPPUNIT_TEST_SUITE(HdrIntrusiveSegmentedQueue) CPPUNIT_TEST( SegmQueue_HP ) @@ -196,10 +196,10 @@ namespace queue { CPPUNIT_TEST( SegmQueue_HP_shuffle ) CPPUNIT_TEST( SegmQueue_HP_stat ) - CPPUNIT_TEST( SegmQueue_PTB ) - CPPUNIT_TEST( SegmQueue_PTB_mutex ) - CPPUNIT_TEST( SegmQueue_PTB_shuffle ) - CPPUNIT_TEST( SegmQueue_PTB_stat ) + CPPUNIT_TEST( SegmQueue_DHP ) + CPPUNIT_TEST( SegmQueue_DHP_mutex ) + CPPUNIT_TEST( SegmQueue_DHP_shuffle ) + CPPUNIT_TEST( SegmQueue_DHP_stat ) CPPUNIT_TEST_SUITE_END() }; diff --git a/tests/test-hdr/queue/hdr_intrusive_segmented_queue_dhp.cpp b/tests/test-hdr/queue/hdr_intrusive_segmented_queue_dhp.cpp new file mode 100644 index 00000000..23f4cfef --- /dev/null +++ b/tests/test-hdr/queue/hdr_intrusive_segmented_queue_dhp.cpp @@ -0,0 +1,60 @@ +//$$CDS-header$$ + +#include "hdr_intrusive_segmented_queue.h" +#include +#include + +namespace queue { + + void HdrIntrusiveSegmentedQueue::SegmQueue_DHP() + { + struct queue_traits : public cds::intrusive::segmented_queue::traits + { + typedef Disposer disposer; + }; + typedef cds::intrusive::SegmentedQueue< cds::gc::DHP, item, queue_traits > queue_type; + + test(); + } + + void HdrIntrusiveSegmentedQueue::SegmQueue_DHP_mutex() + { + struct queue_traits : public + cds::intrusive::segmented_queue::make_traits < + cds::intrusive::opt::disposer< Disposer > + ,cds::opt::lock_type < std::mutex > + > ::type + {}; + typedef cds::intrusive::SegmentedQueue< cds::gc::DHP, item, queue_traits > queue_type; + + test(); + } + + void HdrIntrusiveSegmentedQueue::SegmQueue_DHP_shuffle() + { + typedef cds::intrusive::SegmentedQueue< cds::gc::DHP, item, + cds::intrusive::segmented_queue::make_traits< + cds::intrusive::opt::disposer< Disposer > + ,cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::permutation_generator< cds::opt::v::random_shuffle_permutation<> > + >::type + > queue_type; + + test(); + } + + void HdrIntrusiveSegmentedQueue::SegmQueue_DHP_stat() + { + typedef cds::intrusive::SegmentedQueue< cds::gc::DHP, item, + cds::intrusive::segmented_queue::make_traits< + cds::intrusive::opt::disposer< Disposer > + ,cds::opt::item_counter< cds::atomicity::item_counter > + ,cds::opt::permutation_generator< cds::opt::v::random_permutation<> > + ,cds::opt::stat< cds::intrusive::segmented_queue::stat<> > + >::type + > queue_type; + + test(); + } + +} // namespace queue diff --git a/tests/test-hdr/queue/hdr_intrusive_segmented_queue_hp.cpp b/tests/test-hdr/queue/hdr_intrusive_segmented_queue_hp.cpp index f22d7d3c..4eea7bd0 100644 --- a/tests/test-hdr/queue/hdr_intrusive_segmented_queue_hp.cpp +++ b/tests/test-hdr/queue/hdr_intrusive_segmented_queue_hp.cpp @@ -8,23 +8,24 @@ namespace queue { void HdrIntrusiveSegmentedQueue::SegmQueue_HP() { - typedef cds::intrusive::SegmentedQueue< cds::gc::HP, item, - cds::intrusive::segmented_queue::make_traits< - cds::intrusive::opt::disposer< Disposer > - >::type - > queue_type; + struct queue_traits : public cds::intrusive::segmented_queue::traits + { + typedef Disposer disposer; + }; + typedef cds::intrusive::SegmentedQueue< cds::gc::HP, item, queue_traits > queue_type; test(); } void HdrIntrusiveSegmentedQueue::SegmQueue_HP_mutex() { - typedef cds::intrusive::SegmentedQueue< cds::gc::HP, item, - cds::intrusive::segmented_queue::make_traits< + struct queue_traits : public + cds::intrusive::segmented_queue::make_traits < cds::intrusive::opt::disposer< Disposer > - ,cds::opt::lock_type< std::mutex > - >::type - > queue_type; + ,cds::opt::lock_type < std::mutex > + > ::type + {}; + typedef cds::intrusive::SegmentedQueue< cds::gc::HP, item, queue_traits > queue_type; test(); } diff --git a/tests/test-hdr/queue/hdr_intrusive_segmented_queue_ptb.cpp b/tests/test-hdr/queue/hdr_intrusive_segmented_queue_ptb.cpp deleted file mode 100644 index aa43ae2c..00000000 --- a/tests/test-hdr/queue/hdr_intrusive_segmented_queue_ptb.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//$$CDS-header$$ - -#include "hdr_intrusive_segmented_queue.h" -#include -#include - -namespace queue { - - void HdrIntrusiveSegmentedQueue::SegmQueue_PTB() - { - typedef cds::intrusive::SegmentedQueue< cds::gc::PTB, item, - cds::intrusive::segmented_queue::make_traits< - cds::intrusive::opt::disposer< Disposer > - >::type - > queue_type; - - test(); - } - - void HdrIntrusiveSegmentedQueue::SegmQueue_PTB_mutex() - { - typedef cds::intrusive::SegmentedQueue< cds::gc::PTB, item, - cds::intrusive::segmented_queue::make_traits< - cds::intrusive::opt::disposer< Disposer > - ,cds::opt::lock_type< std::mutex > - >::type - > queue_type; - - test(); - } - - void HdrIntrusiveSegmentedQueue::SegmQueue_PTB_shuffle() - { - typedef cds::intrusive::SegmentedQueue< cds::gc::PTB, item, - cds::intrusive::segmented_queue::make_traits< - cds::intrusive::opt::disposer< Disposer > - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::permutation_generator< cds::opt::v::random_shuffle_permutation<> > - >::type - > queue_type; - - test(); - } - - void HdrIntrusiveSegmentedQueue::SegmQueue_PTB_stat() - { - typedef cds::intrusive::SegmentedQueue< cds::gc::PTB, item, - cds::intrusive::segmented_queue::make_traits< - cds::intrusive::opt::disposer< Disposer > - ,cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::permutation_generator< cds::opt::v::random_permutation<> > - ,cds::opt::stat< cds::intrusive::segmented_queue::stat<> > - >::type - > queue_type; - - test(); - } - -} // namespace queue diff --git a/tests/test-hdr/queue/hdr_intrusive_singlelink_node.h b/tests/test-hdr/queue/hdr_intrusive_singlelink_node.h deleted file mode 100644 index a3d2f94f..00000000 --- a/tests/test-hdr/queue/hdr_intrusive_singlelink_node.h +++ /dev/null @@ -1,37 +0,0 @@ -//$$CDS-header$$ - -#ifndef CDSTEST_HDR_TEST_INTRUSIVE_SINGLELINK_NODE_H -#define CDSTEST_HDR_TEST_INTRUSIVE_SINGLELINK_NODE_H - -#include - -namespace queue { - namespace ci = cds::intrusive; - namespace co = cds::opt; - - template - struct base_hook_item: public ci::single_link::node< GC > - { - int nVal; - int nDisposeCount; - - base_hook_item() - : nDisposeCount(0) - {} - }; - - template - struct member_hook_item - { - int nVal; - int nDisposeCount; - ci::single_link::node< GC > hMember; - - member_hook_item() - : nDisposeCount(0) - {} - }; - -} // queue - -#endif // #ifndef CDSTEST_HDR_TEST_INTRUSIVE_SINGLELINK_NODE_H diff --git a/tests/test-hdr/queue/hdr_segmented_queue.h b/tests/test-hdr/queue/hdr_segmented_queue.h index f7621ad7..91ef3013 100644 --- a/tests/test-hdr/queue/hdr_segmented_queue.h +++ b/tests/test-hdr/queue/hdr_segmented_queue.h @@ -5,7 +5,6 @@ #include "cppunit/cppunit_proxy.h" #include -#include // ref #include "size_check.h" namespace queue { @@ -24,27 +23,6 @@ namespace queue { size_t nVal; }; - struct push_functor { - void operator()( item& dest, other_item const& src ) const - { - dest.nVal = src.nVal; - } - }; - - struct pop_functor { - size_t nCount; - - void operator()( other_item& dest, item const& src ) - { - dest.nVal = src.nVal; - ++nCount; - } - - pop_functor() - : nCount(0) - {} - }; - template void test() { @@ -108,26 +86,25 @@ namespace queue { other_item itm; itm.nVal = i; if ( i & 1 ) { - CPPUNIT_ASSERT( q.push( itm, push_functor() )); + CPPUNIT_ASSERT( q.push_with( [&itm]( item& dest ) { dest.nVal = itm.nVal; } )); } else { - CPPUNIT_ASSERT( q.enqueue( itm, push_functor() )); + CPPUNIT_ASSERT( q.enqueue_with( [&itm]( item& dest ) { dest.nVal = itm.nVal; } )); } CPPUNIT_CHECK( misc::check_size( q, i + 1 )); CPPUNIT_CHECK( !q.empty() ); } { - pop_functor pf; other_item v; nCount = 0; while ( !q.empty() ) { if ( nCount & 1 ) { - CPPUNIT_ASSERT( q.pop( v, std::ref(pf) )); + CPPUNIT_ASSERT( q.pop_with( [&v, &nCount]( item& src ) {v.nVal = src.nVal; ++nCount; } )); } else { - CPPUNIT_ASSERT( q.dequeue( v, std::ref(pf) )); + CPPUNIT_ASSERT( q.dequeue_with( [&v, &nCount]( item& src ) {v.nVal = src.nVal; ++nCount; } )); } // It is possible c_nItemCount % quasi_factor() != 0 @@ -217,10 +194,10 @@ namespace queue { void SegmQueue_HP_shuffle(); void SegmQueue_HP_stat(); - void SegmQueue_PTB(); - void SegmQueue_PTB_mutex(); - void SegmQueue_PTB_shuffle(); - void SegmQueue_PTB_stat(); + void SegmQueue_DHP(); + void SegmQueue_DHP_mutex(); + void SegmQueue_DHP_shuffle(); + void SegmQueue_DHP_stat(); CPPUNIT_TEST_SUITE(HdrSegmentedQueue) CPPUNIT_TEST( SegmQueue_HP ) @@ -228,10 +205,10 @@ namespace queue { CPPUNIT_TEST( SegmQueue_HP_shuffle ) CPPUNIT_TEST( SegmQueue_HP_stat ) - CPPUNIT_TEST( SegmQueue_PTB ) - CPPUNIT_TEST( SegmQueue_PTB_mutex ) - CPPUNIT_TEST( SegmQueue_PTB_shuffle ) - CPPUNIT_TEST( SegmQueue_PTB_stat ) + CPPUNIT_TEST( SegmQueue_DHP ) + CPPUNIT_TEST( SegmQueue_DHP_mutex ) + CPPUNIT_TEST( SegmQueue_DHP_shuffle ) + CPPUNIT_TEST( SegmQueue_DHP_stat ) CPPUNIT_TEST_SUITE_END() }; diff --git a/tests/test-hdr/queue/hdr_segmented_queue_dhp.cpp b/tests/test-hdr/queue/hdr_segmented_queue_dhp.cpp new file mode 100644 index 00000000..cbe87dd9 --- /dev/null +++ b/tests/test-hdr/queue/hdr_segmented_queue_dhp.cpp @@ -0,0 +1,52 @@ +//$$CDS-header$$ + +#include "hdr_segmented_queue.h" +#include +#include + +namespace queue { + + void HdrSegmentedQueue::SegmQueue_DHP() + { + typedef cds::container::SegmentedQueue< cds::gc::DHP, item > queue_type; + test(); + } + + void HdrSegmentedQueue::SegmQueue_DHP_mutex() + { + typedef cds::container::SegmentedQueue< cds::gc::DHP, item, + cds::container::segmented_queue::make_traits< + cds::opt::lock_type< std::mutex > + >::type + > queue_type; + + test(); + } + + void HdrSegmentedQueue::SegmQueue_DHP_shuffle() + { + struct queue_traits : public cds::container::segmented_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + typedef cds::opt::v::random_shuffle_permutation<> permutation_generator; + }; + typedef cds::container::SegmentedQueue< cds::gc::DHP, item, queue_traits > queue_type; + + test(); + } + + void HdrSegmentedQueue::SegmQueue_DHP_stat() + { + struct queue_traits : public + cds::container::segmented_queue::make_traits < + cds::opt::item_counter< cds::atomicity::item_counter > + , cds::opt::permutation_generator< cds::opt::v::random_permutation<> > + , cds::opt::stat < cds::container::segmented_queue::stat<> > + > ::type + {}; + typedef cds::container::SegmentedQueue< cds::gc::DHP, item, queue_traits > queue_type; + + test(); + } + +} // namespace queue diff --git a/tests/test-hdr/queue/hdr_segmented_queue_hp.cpp b/tests/test-hdr/queue/hdr_segmented_queue_hp.cpp index 057df7a2..7e2a72bc 100644 --- a/tests/test-hdr/queue/hdr_segmented_queue_hp.cpp +++ b/tests/test-hdr/queue/hdr_segmented_queue_hp.cpp @@ -9,7 +9,6 @@ namespace queue { void HdrSegmentedQueue::SegmQueue_HP() { typedef cds::container::SegmentedQueue< cds::gc::HP, item > queue_type; - test(); } @@ -26,25 +25,26 @@ namespace queue { void HdrSegmentedQueue::SegmQueue_HP_shuffle() { - typedef cds::container::SegmentedQueue< cds::gc::HP, item, - cds::container::segmented_queue::make_traits< - cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::permutation_generator< cds::opt::v::random_shuffle_permutation<> > - >::type - > queue_type; + struct queue_traits : public cds::container::segmented_queue::traits + { + typedef cds::atomicity::item_counter item_counter; + typedef cds::opt::v::random_shuffle_permutation<> permutation_generator; + }; + typedef cds::container::SegmentedQueue< cds::gc::HP, item, queue_traits > queue_type; test(); } void HdrSegmentedQueue::SegmQueue_HP_stat() { - typedef cds::container::SegmentedQueue< cds::gc::HP, item, - cds::container::segmented_queue::make_traits< + struct queue_traits : public + cds::container::segmented_queue::make_traits < cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::permutation_generator< cds::opt::v::random_permutation<> > - ,cds::opt::stat< cds::container::segmented_queue::stat<> > - >::type - > queue_type; + , cds::opt::permutation_generator< cds::opt::v::random_permutation<> > + , cds::opt::stat < cds::container::segmented_queue::stat<> > + > ::type + {}; + typedef cds::container::SegmentedQueue< cds::gc::HP, item, queue_traits > queue_type; test(); } diff --git a/tests/test-hdr/queue/hdr_segmented_queue_ptb.cpp b/tests/test-hdr/queue/hdr_segmented_queue_ptb.cpp deleted file mode 100644 index 6d8ad498..00000000 --- a/tests/test-hdr/queue/hdr_segmented_queue_ptb.cpp +++ /dev/null @@ -1,52 +0,0 @@ -//$$CDS-header$$ - -#include "hdr_segmented_queue.h" -#include -#include - -namespace queue { - - void HdrSegmentedQueue::SegmQueue_PTB() - { - typedef cds::container::SegmentedQueue< cds::gc::PTB, item > queue_type; - - test(); - } - - void HdrSegmentedQueue::SegmQueue_PTB_mutex() - { - typedef cds::container::SegmentedQueue< cds::gc::PTB, item, - cds::container::segmented_queue::make_traits< - cds::opt::lock_type< std::mutex > - >::type - > queue_type; - - test(); - } - - void HdrSegmentedQueue::SegmQueue_PTB_shuffle() - { - typedef cds::container::SegmentedQueue< cds::gc::PTB, item, - cds::container::segmented_queue::make_traits< - cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::permutation_generator< cds::opt::v::random_shuffle_permutation<> > - >::type - > queue_type; - - test(); - } - - void HdrSegmentedQueue::SegmQueue_PTB_stat() - { - typedef cds::container::SegmentedQueue< cds::gc::PTB, item, - cds::container::segmented_queue::make_traits< - cds::opt::item_counter< cds::atomicity::item_counter > - ,cds::opt::permutation_generator< cds::opt::v::random_permutation<> > - ,cds::opt::stat< cds::container::segmented_queue::stat<> > - >::type - > queue_type; - - test(); - } - -} // namespace queue diff --git a/tests/unit/queue/intrusive_queue_type.h b/tests/unit/queue/intrusive_queue_type.h index e073626c..a51982ff 100644 --- a/tests/unit/queue/intrusive_queue_type.h +++ b/tests/unit/queue/intrusive_queue_type.h @@ -13,7 +13,6 @@ #include #include -#include //TODO: remove this line! #include #include diff --git a/tests/unit/queue/queue_type.h b/tests/unit/queue/queue_type.h index 2c98a4ef..cfd1c66c 100644 --- a/tests/unit/queue/queue_type.h +++ b/tests/unit/queue/queue_type.h @@ -15,7 +15,6 @@ #include #include -#include //TODO: remove this line! #include #include "queue/std_queue.h"