Fixed typo
[libcds.git] / cds / container / vyukov_mpmc_cycle_queue.h
index 354af99563b7c6e580070ed613b95051925a52b6..c452e1b5916205f0c36eb001c3b04d218953c5d9 100644 (file)
@@ -1,11 +1,11 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
 
@@ -25,7 +25,7 @@
     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #ifndef CDSLIB_CONTAINER_VYUKOV_MPMC_CYCLE_QUEUE_H
@@ -49,21 +49,25 @@ namespace cds { namespace container {
             /// Buffer type for internal array
             /*
                 The type of element for the buffer is not important: the queue rebinds
-                buffer for required type via \p rebind metafunction.
+                the buffer for required type via \p rebind metafunction.
 
                 For \p VyukovMPMCCycleQueue queue the buffer size should have power-of-2 size.
+
+                You should use only uninitialized buffer for the queue -
+                \p cds::opt::v::uninitialized_dynamic_buffer (the default),
+                \p cds::opt::v::uninitialized_static_buffer.
             */
-            typedef cds::opt::v::dynamic_buffer< void * > buffer;
+            typedef cds::opt::v::uninitialized_dynamic_buffer< void * > buffer;
 
             /// A functor to clean item dequeued.
             /**
                 The functor calls the destructor for queue item.
                 After an item is dequeued, \p value_cleaner cleans the cell that the item has been occupied.
-                If \p T is a complex type, \p value_cleaner may be the useful feature.
+                If \p T is a complex type, \p value_cleaner may be useful feature.
 
-                Default value is \ref opt::v::destruct_cleaner
+                Default value is \ref opt::v::auto_cleaner
             */
-            typedef cds::opt::v::destruct_cleaner value_cleaner;
+            typedef cds::opt::v::auto_cleaner value_cleaner;
 
             /// Item counting feature; by default, disabled. Use \p cds::atomicity::item_counter to enable item counting
             typedef cds::atomicity::empty_item_counter item_counter;
@@ -71,7 +75,7 @@ namespace cds { namespace container {
             /// 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).
+                or \p opt::v::sequential_consistent (sequentially consistent memory model).
             */
             typedef opt::v::relaxed_ordering    memory_model;
 
@@ -84,7 +88,6 @@ namespace cds { namespace container {
             /// Single-consumer version
             /**
                 For single-consumer version of algorithm some additional functions
-
                 (\p front(), \p pop_front()) is available.
 
                 Default is \p false
@@ -95,14 +98,14 @@ namespace cds { namespace container {
         /// Metafunction converting option list to \p vyukov_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::buffer - an uninitialized buffer type for internal cyclic array. Possible types are:
+                \p opt::v::uninitialized_dynamic_buffer (the default), \p opt::v::uninitialized_static_buffer. The type of
                 element in the buffer is not important: it will be changed via \p rebind metafunction.
             - \p opt::value_cleaner - a functor to clean item dequeued.
                 The functor calls the destructor for queue item.
                 After an item is dequeued, \p value_cleaner cleans the cell that the item has been occupied.
                 If \p T is a complex type, \p value_cleaner can be an useful feature.
-                Default value is \ref opt::v::destruct_cleaner
+                Default value is \ref opt::v::auto_cleaner
             - \p opt::back_off - back-off strategy used. If the option is not specified, the \p cds::backoff::Default is used.
             - \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
@@ -114,7 +117,7 @@ namespace cds { namespace container {
             \code
             typedef cds::container::VyukovMPMCCycleQueue< Foo,
                 typename cds::container::vyukov_queue::make_traits<
-                    cds::opt::buffer< cds::opt::v::static_buffer< void *, 1024 >,
+                    cds::opt::buffer< cds::opt::v::uninitialized_static_buffer< void *, 1024 >,
                     cds::opt::item_counte< cds::atomicity::item_counter >
                 >::type
             > myQueue;
@@ -179,7 +182,7 @@ namespace cds { namespace container {
         typedef T value_type;   ///< Value type to be stored in the queue
         typedef Traits traits;  ///< Queue traits
         typedef typename traits::item_counter  item_counter;  ///< Item counter type
-        typedef typename traits::memory_model  memory_model;  ///< Memory ordering. See cds::opt::memory_model option
+        typedef typename traits::memory_model  memory_model;  ///< Memory ordering. See \p cds::opt::memory_model option
         typedef typename traits::value_cleaner value_cleaner; ///< Value cleaner, see \p vyukov_queue::traits::value_cleaner
         typedef typename traits::back_off  back_off;          ///< back-off strategy
 
@@ -222,7 +225,7 @@ namespace cds { namespace container {
     public:
         /// Constructs the queue of capacity \p nCapacity
         /**
-            For \p cds::opt::v::static_buffer the \p nCapacity parameter is ignored.
+            For \p cds::opt::v::uninitialized_static_buffer the \p nCapacity parameter is ignored.
 
             The buffer capacity must be the power of two.
         */
@@ -279,7 +282,7 @@ namespace cds { namespace container {
                 }
                 else if (dif < 0) {
                     // Queue full?
-                    if ( pos - m_posDequeue.load( memory_model::memory_order_relaxed ) == capacity() )
+                    if ( pos - m_posDequeue.load( memory_model::memory_order_relaxed ) == capacity())
                         return false;   // queue full
                     bkoff();
                     pos = m_posEnqueue.load( memory_model::memory_order_relaxed );
@@ -312,7 +315,7 @@ namespace cds { namespace container {
             return enqueue_with( [&val]( value_type& dest ) { new (&dest) value_type( std::move( val ));});
         }
 
-        /// Synonym for \p enqueue( valuetype const& )
+        /// Synonym for \p enqueue( value_type const& )
         bool push( value_type const& data )
         {
             return enqueue( data );
@@ -337,9 +340,10 @@ namespace cds { namespace container {
         {
 #if (CDS_COMPILER == CDS_COMPILER_GCC) && (CDS_COMPILER_VERSION < 40900)
             //work around unsupported feature in g++ 4.8 for forwarding parameter packs to lambda.
-            return enqueue_with ( std::bind([]( value_type& dest,Args ... args ){ new ( &dest ) value_type( std::forward<Args>(args)... );}, std::placeholders::_1 ,args...));
+            value_type val( std::forward<Args>(args)... );
+            return enqueue_with( [&val]( value_type& dest ){ new ( &dest ) value_type( std::move( val )); });
 #else
-            return enqueue_with( [&args ...]( value_type& dest ){ new ( &dest ) value_type( std::forward<Args>(args)... ); });
+            return enqueue_with( [&args ...]( value_type& dest ){ new ( &dest ) value_type( std::forward<Args>( args )... ); });
 #endif
         }
 
@@ -479,7 +483,7 @@ namespace cds { namespace container {
         void clear()
         {
             value_type v;
-            while ( pop(v) );
+            while ( pop(v));
         }
 
         /// Returns queue's item count
@@ -511,7 +515,6 @@ namespace cds { namespace container {
     //@endcond
 
     /// Vyukov's queue multiple producer - single consumer version
-
     template <typename T, typename Traits = vyukov_queue::traits >
     using VyukovMPSCCycleQueue = VyukovMPMCCycleQueue< T, vyukov_queue::single_consumer_traits<Traits> >;