From a56706849a99e7949018bfbe4814abe3e2ad238e Mon Sep 17 00:00:00 2001 From: khizmax Date: Thu, 9 Oct 2014 08:48:47 +0400 Subject: [PATCH] OptimisticQueue, RWQueue refactoring (issues #1,#2,#3) --- cds/container/optimistic_queue.h | 14 +------------- cds/container/rwqueue.h | 9 +++------ projects/source.test-hdr.mk | 4 ++-- tests/unit/queue/intrusive_queue_type.h | 16 +++++++++++----- tests/unit/queue/queue_type.h | 9 +++++---- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/cds/container/optimistic_queue.h b/cds/container/optimistic_queue.h index 800e654c..cf1b0d63 100644 --- a/cds/container/optimistic_queue.h +++ b/cds/container/optimistic_queue.h @@ -97,17 +97,6 @@ namespace cds { namespace container { typedef T value_type; typedef Traits traits; - /* - struct default_options { - typedef cds::backoff::empty back_off; - typedef CDS_DEFAULT_ALLOCATOR allocator; - typedef atomicity::empty_item_counter item_counter; - typedef intrusive::optimistic_queue::dummy_stat stat; - typedef opt::v::relaxed_ordering memory_model; - enum { alignment = opt::cache_line_alignment }; - }; - */ - struct node_type: public cds::intrusive::optimistic_queue::node< gc > { value_type m_value; @@ -171,7 +160,7 @@ namespace cds { namespace container { > myQueue; \endcode */ - template + template class OptimisticQueue: #ifdef CDS_DOXYGEN_INVOKED private intrusive::OptimisticQueue< GC, cds::intrusive::optimistic_queue::node< T >, Traits > @@ -322,7 +311,6 @@ namespace cds { namespace container { */ bool dequeue( value_type& dest ) { - typedef cds::details::trivial_assign functor; return dequeue_with( [&dest]( value_type& src ) { dest = src; } ); } diff --git a/cds/container/rwqueue.h b/cds/container/rwqueue.h index 16226707..0ee16f90 100644 --- a/cds/container/rwqueue.h +++ b/cds/container/rwqueue.h @@ -36,8 +36,6 @@ namespace cds { namespace container { - 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::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 mutex-based \p %RWQueue with item counting \code @@ -107,7 +105,6 @@ namespace cds { namespace container { typedef typename traits::lock_type lock_type; ///< Locking primitive 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 protected: //@cond @@ -216,7 +213,7 @@ namespace cds { namespace container { bool enqueue( value_type const& data ) { scoped_node_ptr p( alloc_node( data )); - if ( enqueue_node( p )) { + if ( enqueue_node( p.get() )) { p.release(); return true; } @@ -238,7 +235,7 @@ namespace cds { namespace container { { scoped_node_ptr p( alloc_node() ); f( p->m_value ); - if ( enqueue_node( p ) ) { + if ( enqueue_node( p.get() )) { p.release(); return true; } @@ -277,7 +274,7 @@ namespace cds { namespace container { */ bool dequeue( value_type& dest ) { - return dequeue( [&dest]( value_type * src ) { dest = src; } ); + return dequeue_with( [&dest]( value_type& src ) { dest = src; } ); } /// Dequeues a value using a functor diff --git a/projects/source.test-hdr.mk b/projects/source.test-hdr.mk index 4b4fce3f..8940eed1 100644 --- a/projects/source.test-hdr.mk +++ b/projects/source.test-hdr.mk @@ -129,8 +129,8 @@ CDS_TESTHDR_QUEUE := \ tests/test-hdr/queue/hdr_moirqueue_dhp.cpp \ tests/test-hdr/queue/hdr_msqueue_hp.cpp \ tests/test-hdr/queue/hdr_msqueue_dhp.cpp \ - tests/test-hdr/queue/hdr_optimistic_hzp.cpp \ - tests/test-hdr/queue/hdr_optimistic_ptb.cpp \ + tests/test-hdr/queue/hdr_optimistic_hp.cpp \ + 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 \ diff --git a/tests/unit/queue/intrusive_queue_type.h b/tests/unit/queue/intrusive_queue_type.h index 9a0e99b5..e073626c 100644 --- a/tests/unit/queue/intrusive_queue_type.h +++ b/tests/unit/queue/intrusive_queue_type.h @@ -452,7 +452,7 @@ namespace queue { // ********************************************* // Queue statistics namespace std { - + /* // cds::intrusive::queue_stat template static inline std::ostream& operator <<(std::ostream& o, cds::intrusive::queue_stat const& s) @@ -470,6 +470,7 @@ namespace std { { return o; } + */ template @@ -519,12 +520,17 @@ namespace std { static inline std::ostream& operator <<( std::ostream& o, cds::intrusive::optimistic_queue::stat const& s ) { return o - << static_cast const&>( s ) - << "\t\t" - << "\t\t fix list call: " << s.m_FixListCount.get() << "\n"; + << "\tStatistics:\n" + << "\t\t Enqueue count: " << s.m_EnqueueCount.get() << "\n" + << "\t\t Enqueue race: " << s.m_EnqueueRace.get() << "\n" + << "\t\t Dequeue count: " << s.m_DequeueCount.get() << "\n" + << "\t\t Dequeue race: " << s.m_DequeueRace.get() << "\n" + << "\t\tAdvance tail error: " << s.m_AdvanceTailError.get() << "\n" + << "\t\t Bad tail: " << s.m_BadTail.get() << "\n" + << "\t\t fix list call: " << s.m_FixListCount.get() << "\n"; } - static inline std::ostream& operator <<( std::ostream& o, cds::intrusive::optimistic_queue::dummy_stat const& s ) + static inline std::ostream& operator <<( std::ostream& o, cds::intrusive::optimistic_queue::empty_stat const& s ) { return o; } diff --git a/tests/unit/queue/queue_type.h b/tests/unit/queue/queue_type.h index 2bb57bb0..9fa554f6 100644 --- a/tests/unit/queue/queue_type.h +++ b/tests/unit/queue/queue_type.h @@ -150,7 +150,7 @@ namespace queue { // OptimisticQueue typedef cds::container::OptimisticQueue< cds::gc::HP, Value > OptimisticQueue_HP; - typedef cds::container::OptimisticQueue< cds::gc::PTB, Value > OptimisticQueue_PTB; + typedef cds::container::OptimisticQueue< cds::gc::DHP, Value > OptimisticQueue_DHP; struct traits_OptimisticQueue_michaelAlloc : public cds::container::optimistic_queue::traits { @@ -175,7 +175,7 @@ namespace queue { struct traits_OptimisticQueue_stat : public cds::container::optimistic_queue::make_traits < - cds::opt::stat < cds::intrusive::queue_stat<> > + cds::opt::stat < cds::intrusive::optimistic_queue::stat<> > > ::type {}; typedef cds::container::OptimisticQueue< cds::gc::HP, Value, traits_OptimisticQueue_stat > OptimisticQueue_HP_stat; @@ -384,7 +384,7 @@ namespace queue { cds::opt::lock_type< std::mutex > >::type {}; - typedef cds::container::RWQueue< Value, traits_RWQueue_mutex > traits_RWQueue_mutex; + typedef cds::container::RWQueue< Value, traits_RWQueue_mutex > RWQueue_mutex; // FCQueue class traits_FCQueue_elimination: @@ -500,7 +500,7 @@ namespace queue { // ********************************************* // Queue statistics namespace std { - + /* template static inline std::ostream& operator <<(std::ostream& o, cds::intrusive::queue_stat const& s) { @@ -517,6 +517,7 @@ namespace std { { return o; } + */ template static inline std::ostream& operator <<(std::ostream& o, cds::container::basket_queue::stat const& s) -- 2.34.1