Added move semantics push(), doc fixed
authorkhizmax <libcds.dev@gmail.com>
Sat, 23 Jan 2016 14:33:47 +0000 (17:33 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 23 Jan 2016 14:33:47 +0000 (17:33 +0300)
cds/algo/atomic.h
cds/container/segmented_queue.h
cds/container/tsigas_cycle_queue.h
cds/container/vyukov_mpmc_cycle_queue.h
cds/opt/options.h

index c2306e860d3d6fbbfcc6bf73ebaa990274d1b4b4..a30737aa1a3758fddc5b944ae78d9d638d36fd66 100644 (file)
@@ -189,12 +189,11 @@ namespace cds {
             {
                 m_counter.store( 0, atomics::memory_order_release );
             }
-
         };
 
         /// Atomic item counter
         /**
-            This class is simplified interface around <tt>std::atomic_size_t</tt>.
+            This class is simplified interface around \p std::atomic_size_t.
             The class supports getting of current value of the counter and increment/decrement its value.
         */
         class item_counter
index fa981e2636b7d1a5ec4cc4b400ecacd511c9eac7..886a9de62e031a7e20b1adb62f688150b7ddf26b 100644 (file)
@@ -281,6 +281,17 @@ namespace cds { namespace container {
             return false;
         }
 
+        /// Inserts a new element at last segment of 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.
@@ -304,12 +315,18 @@ namespace cds { namespace container {
         }
 
 
-        /// Synonym for \p enqueue() member function
+        /// Synonym for \p enqueue( value_type const& ) member function
         bool push( value_type const& val )
         {
             return enqueue( val );
         }
 
+        /// Synonym for \p enqueue( value_type&& ) member function
+        bool push( value_type&& val )
+        {
+            return enqueue( std::move( val ));
+        }
+
         /// Synonym for \p enqueue_with() member function
         template <typename Func>
         bool push_with( Func f )
@@ -390,7 +407,7 @@ namespace cds { namespace container {
 
         /// Clear the queue
         /**
-            The function repeatedly calls \ref dequeue until it returns \p nullptr.
+            The function repeatedly calls \p dequeue() until it returns \p nullptr.
             The disposer specified in \p Traits template argument is called for each removed item.
         */
         void clear()
index f87da37c74a2a5729107de574d6f6b329f112f00..4893e180edbdb776d710fd457d0f624a74fbc7ae 100644 (file)
@@ -284,6 +284,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 +329,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 <typename Func>
         bool push_with( Func f )
index 783a912c81a582867e599743c38514a4f9881dc4..41dd96ad24d3f1fc7e39f49c9fce6ace2274e3e6 100644 (file)
@@ -306,12 +306,24 @@ namespace cds { namespace container {
             return enqueue_with( [&val]( value_type& dest ){ new ( &dest ) value_type( val ); });
         }
 
-        /// Synonym for \p enqueue()
+        /// Enqueues \p val value into the queue, move semantics
+        bool enqueue( value_type&& val )
+        {
+            return enqueue_with( [&val]( value_type& dest ) { new (&dest) value_type( std::move( val ));});
+        }
+
+        /// Synonym for \p enqueue( valuetype 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()
         template <typename Func>
         bool push_with( Func f )
@@ -384,7 +396,7 @@ namespace cds { namespace container {
             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 dequeue(value_type& dest )
         {
             return dequeue_with( [&dest]( value_type& src ){ dest = std::move( src );});
         }
index 2b1c3ec6d5299b7d5d6b6134003bb50acba54219..a23aea04be33a486cf68886dc4c981bdfb9155fe 100644 (file)
@@ -302,17 +302,17 @@ namespace opt {
         This option allows to set up appropriate item counting policy for that data structure.
 
         Predefined option \p Type:
-        - atomicity::empty_item_counter - no item counting performed. It is default policy for many
+        - \p atomicity::empty_item_counter - no item counting performed. It is default policy for many
             containers
-        - atomicity::item_counter - the class that provides atomically item counting
-        - opt::v::sequential_item_counter - simple non-atomic item counter. This item counter is not intended for
+        - \p atomicity::item_counter - the class that provides atomically item counting
+        - \p opt::v::sequential_item_counter - simple non-atomic item counter. This item counter is not intended for
             concurrent containers and may be used only if it is explicitly noted.
 
-        You may provide other implementation of atomicity::item_counter interface for your needs.
+        You may provide other implementation of \p atomicity::item_counter interface for your needs.
 
         Note, the item counting in lock-free containers cannot be exact; for example, if
         item counter for a container returns zero it is not mean that the container is empty.
-        Thus, item counter may be used for statistical purposes only.
+        Thus, the item counter may be used for statistical purposes only.
     */
     template <typename Type>
     struct item_counter {