On dev: SkipList: remove node state
[libcds.git] / cds / container / vyukov_mpmc_cycle_queue.h
index 354af99563b7c6e580070ed613b95051925a52b6..d9365949bc9916a7fe6a15027ebca16c48b79ecd 100644 (file)
@@ -5,7 +5,7 @@
 
     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,17 +49,21 @@ 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
             */
@@ -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,8 +98,8 @@ 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.
@@ -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 );
@@ -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> >;