X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=cds%2Fcontainer%2Ftsigas_cycle_queue.h;h=ad835b3323781517603f76bbc58f3ba9d1d12bce;hb=f3d187182434846ab9608307037258421101feb9;hp=c4661898a6e8a55bad57e25a0f1ba6ee5373848e;hpb=cd515d6402be81b84e2eb0c9d4cf0a1ca9e4d95a;p=libcds.git diff --git a/cds/container/tsigas_cycle_queue.h b/cds/container/tsigas_cycle_queue.h index c4661898..ad835b33 100644 --- a/cds/container/tsigas_cycle_queue.h +++ b/cds/container/tsigas_cycle_queue.h @@ -51,8 +51,10 @@ namespace cds { namespace container { buffer for required type via \p rebind metafunction. For \p TsigasCycleQueue queue the buffer size should have power-of-2 size. + + You should use any initialized buffer type, see \p opt::buffer. */ - typedef cds::opt::v::dynamic_buffer< void * > buffer; + typedef cds::opt::v::initialized_dynamic_buffer< void * > buffer; /// Node allocator typedef CDS_DEFAULT_ALLOCATOR allocator; @@ -70,21 +72,21 @@ namespace cds { namespace container { */ typedef opt::v::relaxed_ordering memory_model; - /// Alignment for internal queue data. Default is \p opt::cache_line_alignment - enum { alignment = opt::cache_line_alignment }; + /// Padding for internal critical atomic data. Default is \p opt::cache_line_padding + enum { padding = opt::cache_line_padding }; }; /// Metafunction converting option list to \p tsigas_queue::traits /** Supported \p Options are: - \p opt::buffer - the buffer type for internal cyclic array. Possible types are: - \p opt::v::dynamic_buffer (the default), \p opt::v::static_buffer. The type of + \p opt::v::initialized_dynamic_buffer (the default), \p opt::v::initialized_static_buffer. The type of element in the buffer is not important: it will be changed via \p rebind metafunction. - \p opt::allocator - allocator (like \p std::allocator) used for allocating queue items. Default is \ref CDS_DEFAULT_ALLOCATOR - \p opt::back_off - back-off strategy used, default is \p cds::backoff::empty. - \p 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 - - \p opt::alignment - the alignment for internal queue data. Default is \p opt::cache_line_alignment + - \p opt::padding - padding for internal critical atomic data. Default is \p opt::cache_line_padding - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) or \p opt::v::sequential_consistent (sequentially consisnent memory model). @@ -92,8 +94,8 @@ namespace cds { namespace container { \code typedef cds::container::TsigasCycleQueue< Foo, typename cds::container::tsigas_queue::make_traits< - cds::opt::buffer< cds::opt::v::static_buffer< void *, 1024 >, - cds::opt::item_counte< cds::atomicity::item_counter > + cds::opt::buffer< cds::opt::v::initialized_static_buffer< void *, 1024 >, + cds::opt::item_counter< cds::atomicity::item_counter > >::type > myQueue; \endcode @@ -179,7 +181,7 @@ namespace cds { namespace container { // Queue of Foo, capacity is 1024, statically allocated buffer: typedef cds::container::TsigasCycleQueue< Foo, typename cds::container::tsigas_queue::make_traits< - cds::opt::buffer< cds::opt::v::static_buffer< Foo, 1024 > > + cds::opt::buffer< cds::opt::v::initialized_static_buffer< Foo, 1024 > > >::type > static_queue; static_queue stQueue; @@ -187,7 +189,7 @@ namespace cds { namespace container { // Queue of Foo, capacity is 1024, dynamically allocated buffer: typedef cds::container::TsigasCycleQueue< Foo typename cds::container::tsigas_queue::make_traits< - cds::opt::buffer< cds::opt::v::dynamic_buffer< Foo > > + cds::opt::buffer< cds::opt::v::initialized_dynamic_buffer< Foo > > >::type > dynamic_queue; dynamic_queue dynQueue( 1024 ); @@ -259,7 +261,7 @@ namespace cds { namespace container { public: /// Initialize empty queue of capacity \p nCapacity /** - If internal buffer type is \p cds::opt::v::static_buffer, the \p nCapacity parameter is ignored. + If internal buffer type is \p cds::opt::v::initialized_static_buffer, the \p nCapacity parameter is ignored. Note, the real capacity of queue is \p nCapacity - 2. */ @@ -284,6 +286,17 @@ namespace cds { namespace container { return false; } + /// Enqueues \p val value into the queue, move semantics + bool enqueue( value_type&& val ) + { + scoped_node_ptr p( alloc_node_move( std::move( val ))); + if ( base_class::enqueue( *p ) ) { + p.release(); + return true; + } + return false; + } + /// Enqueues data to the queue using a functor /** \p Func is a functor called to create node. @@ -318,12 +331,18 @@ namespace cds { namespace container { return false; } - /// Synonym for template version of \p enqueue() function + /// Synonym for \p enqueue( value_type const& ) bool push( value_type const& data ) { return enqueue( data ); } + /// Synonym for \p enqueue( value_type&& ) + bool push( value_type&& data ) + { + return enqueue( std::move( data )); + } + /// Synonym for \p enqueue_with() function template bool push_with( Func f ) @@ -362,7 +381,7 @@ namespace cds { namespace container { */ bool dequeue( value_type& dest ) { - return dequeue_with( [&dest]( value_type& src ) { dest = src; } ); + return dequeue_with( [&dest]( value_type& src ) { dest = std::move( src );}); } /// Synonym for \p dequeue() function