{
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
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.
}
- /// 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 )
/// 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()
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.
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 )
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 )
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 );});
}
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 {