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 :
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;
/// 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<
>::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<int>
+ default is \p cds::opt::v::random2_permutation<int>
*/
template <typename... Options>
struct make_traits {
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
}
};
- struct intrusive_type_traits: public original_type_traits {
+ struct intrusive_type_traits: public original_type_traits
+ {
typedef node_disposer disposer;
};
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 <class GC, typename T, typename Traits = segmented_queue::type_traits >
+ template <class GC, typename T, typename Traits = segmented_queue::traits >
class SegmentedQueue:
#ifdef CDS_DOXYGEN_INVOKED
public cds::intrusive::SegmentedQueue< GC, T, Traits >
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
{
return cxx_node_allocator().MoveNew( std::forward<Args>( args )... );
}
-
- struct dummy_disposer {
- void operator()( value_type * p )
- {}
- };
//@endcond
public:
return false;
}
- /// Synonym for <tt>enqueue(value_type const&)</tt> 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 <typename Q, typename Func>
- bool enqueue( Q const& data, Func f )
+ template <typename Func>
+ 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 <tt>enqueue(Q const&, Func)</tt> function
- template <typename Q, typename Func>
- 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 <typename Func>
+ bool push_with( Func f )
+ {
+ return enqueue_with( f );
}
/// Enqueues data of type \ref value_type constructed with <tt>std::forward<Args>(args)...</tt>
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 <typename Q, typename Func>
- bool dequeue( Q& dest, Func f )
+ template <typename Func>
+ 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 <tt>dequeue( Q&, Func )</tt> function
+ /// Synonym for \p dequeue_with() function
template <typename Q, typename Func>
- 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<value_type, value_type> functor;
- return dequeue( dest, functor() );
+ return dequeue_with( f );
}
- /// Synonym for <tt>dequeue(value_type&)</tt> function
+ /// Synonym for \p dequeue() function
bool pop( value_type& dest )
{
return dequeue( dest );
/// SegmentedQueue internal statistics. May be used for debugging or profiling
template <typename Counter = cds::atomicity::event_counter >
- struct stat {
+ struct stat
+ {
typedef Counter counter_type; ///< Counter type
counter_type m_nPush; ///< Push count
//@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;
/// 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<
>::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<int>
+ default is \p cds::opt::v::random2_permutation<int>
*/
template <typename... Options>
struct make_traits {
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
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 <class GC, typename T, typename Traits = segmented_queue::type_traits >
+ template <class GC, typename T, typename Traits = segmented_queue::traits >
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
segment(); //=delete
};
- typedef typename opt::details::alignment_setter< atomics::atomic<segment *>, options::alignment >::type aligned_segment_ptr;
+ typedef typename opt::details::alignment_setter< atomics::atomic<segment *>, traits::alignment >::type aligned_segment_ptr;
//@endcond
protected:
cds::container::BasketQueue
cds::container::OptimisticQueue
cds::container::RWQueue
+ cds::container::SegmentedQueue
1.6.0 23.09.2014
General release
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_msqueue_hp.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_optimisticqueue_dhp.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_optimisticqueue_hp.cpp" />\r
+ <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue_dhp.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue_hp.cpp" />\r
- <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue_ptb.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_tsigas_cycle_queue.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_vyukovmpmc_cycle_queue.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_moirqueue_dhp.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_optimistic_hp.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_queue_register.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_rwqueue.cpp" />\r
+ <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue_dhp.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue_hp.cpp" />\r
- <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue_ptb.cpp" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_vyukov_mpmc_cyclic.cpp" />\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_msqueue.h" />\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue.h" />\r
- <ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_singlelink_node.h" />\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_queue.h" />\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_queue_new.h" />\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue.h" />\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue_hp.cpp">\r
<Filter>intrusive</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue_ptb.cpp">\r
- <Filter>intrusive</Filter>\r
- </ClCompile>\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_tsigas_cycle_queue.cpp">\r
<Filter>intrusive</Filter>\r
</ClCompile>\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue_hp.cpp">\r
<Filter>container</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue_ptb.cpp">\r
- <Filter>container</Filter>\r
- </ClCompile>\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_vyukov_mpmc_cyclic.cpp">\r
<Filter>container</Filter>\r
</ClCompile>\r
<ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_optimistic_hp.cpp">\r
<Filter>container</Filter>\r
</ClCompile>\r
+ <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue_dhp.cpp">\r
+ <Filter>intrusive</Filter>\r
+ </ClCompile>\r
+ <ClCompile Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue_dhp.cpp">\r
+ <Filter>container</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_msqueue.h">\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_segmented_queue.h">\r
<Filter>intrusive</Filter>\r
</ClInclude>\r
- <ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_intrusive_singlelink_node.h">\r
- <Filter>intrusive</Filter>\r
- </ClInclude>\r
<ClInclude Include="..\..\..\tests\test-hdr\queue\hdr_segmented_queue.h">\r
<Filter>container</Filter>\r
</ClInclude>\r
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 \
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 := \
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 )
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()
};
--- /dev/null
+//$$CDS-header$$
+
+#include "hdr_intrusive_segmented_queue.h"
+#include <cds/intrusive/segmented_queue.h>
+#include <cds/gc/dhp.h>
+
+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<queue_type>();
+ }
+
+ 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<queue_type>();
+ }
+
+ 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<queue_type>();
+ }
+
+ 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<queue_type>();
+ }
+
+} // 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<queue_type>();
}
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<queue_type>();
}
+++ /dev/null
-//$$CDS-header$$
-
-#include "hdr_intrusive_segmented_queue.h"
-#include <cds/intrusive/segmented_queue.h>
-#include <cds/gc/ptb.h>
-
-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<queue_type>();
- }
-
- 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<queue_type>();
- }
-
- 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<queue_type>();
- }
-
- 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<queue_type>();
- }
-
-} // namespace queue
+++ /dev/null
-//$$CDS-header$$
-
-#ifndef CDSTEST_HDR_TEST_INTRUSIVE_SINGLELINK_NODE_H
-#define CDSTEST_HDR_TEST_INTRUSIVE_SINGLELINK_NODE_H
-
-#include <cds/intrusive/details/single_link_struct.h>
-
-namespace queue {
- namespace ci = cds::intrusive;
- namespace co = cds::opt;
-
- template <typename GC>
- struct base_hook_item: public ci::single_link::node< GC >
- {
- int nVal;
- int nDisposeCount;
-
- base_hook_item()
- : nDisposeCount(0)
- {}
- };
-
- template <typename GC>
- 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
#include "cppunit/cppunit_proxy.h"
#include <cds/intrusive/details/base.h>
-#include <functional> // ref
#include "size_check.h"
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 <typename Queue>
void test()
{
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
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 )
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()
};
--- /dev/null
+//$$CDS-header$$
+
+#include "hdr_segmented_queue.h"
+#include <cds/container/segmented_queue.h>
+#include <cds/gc/dhp.h>
+
+namespace queue {
+
+ void HdrSegmentedQueue::SegmQueue_DHP()
+ {
+ typedef cds::container::SegmentedQueue< cds::gc::DHP, item > queue_type;
+ test<queue_type>();
+ }
+
+ 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<queue_type>();
+ }
+
+ 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<queue_type>();
+ }
+
+ 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<queue_type>();
+ }
+
+} // namespace queue
void HdrSegmentedQueue::SegmQueue_HP()
{
typedef cds::container::SegmentedQueue< cds::gc::HP, item > queue_type;
-
test<queue_type>();
}
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<queue_type>();
}
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<queue_type>();
}
+++ /dev/null
-//$$CDS-header$$
-
-#include "hdr_segmented_queue.h"
-#include <cds/container/segmented_queue.h>
-#include <cds/gc/ptb.h>
-
-namespace queue {
-
- void HdrSegmentedQueue::SegmQueue_PTB()
- {
- typedef cds::container::SegmentedQueue< cds::gc::PTB, item > queue_type;
-
- test<queue_type>();
- }
-
- 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<queue_type>();
- }
-
- 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<queue_type>();
- }
-
- 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<queue_type>();
- }
-
-} // namespace queue
#include <cds/intrusive/segmented_queue.h>
#include <cds/gc/hp.h>
-#include <cds/gc/hrc.h> //TODO: remove this line!
#include <cds/gc/dhp.h>
#include <boost/intrusive/slist.hpp>
#include <cds/container/segmented_queue.h>
#include <cds/gc/hp.h>
-#include <cds/gc/hrc.h> //TODO: remove this line!
#include <cds/gc/dhp.h>
#include "queue/std_queue.h"