Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::lockfree::spsc_queue< T, A0, A1 > Class Template Reference

The spsc_queue class provides a single-writer/single-reader fifo queue, pushing and popping is wait-free. More...

#include <spsc_queue.hpp>

Inheritance diagram for boost::lockfree::spsc_queue< T, A0, A1 >:
Collaboration diagram for boost::lockfree::spsc_queue< T, A0, A1 >:

Public Types

typedef T value_type
 
typedef
implementation_defined::allocator 
allocator
 
typedef
implementation_defined::size_type 
size_type
 
typedef T type
 

Public Member Functions

bool push (T const &t)
 Pushes object t to the ringbuffer. More...
 
bool pop ()
 Pops one object from ringbuffer. More...
 
template<typename U >
boost::enable_if< typename
is_convertible< T, U >::type,
bool >::type 
pop (U &ret)
 Pops one object from ringbuffer. More...
 
size_type push (T const *t, size_type size)
 Pushes as many objects from the array t as there is space. More...
 
template<size_type size>
size_type push (T const (&t)[size])
 Pushes as many objects from the array t as there is space available. More...
 
template<typename ConstIterator >
ConstIterator push (ConstIterator begin, ConstIterator end)
 Pushes as many objects from the range [begin, end) as there is space . More...
 
size_type pop (T *ret, size_type size)
 Pops a maximum of size objects from ringbuffer. More...
 
template<size_type size>
size_type pop (T(&ret)[size])
 Pops a maximum of size objects from spsc_queue. More...
 
template<typename OutputIterator >
boost::disable_if< typename
is_convertible< T,
OutputIterator >::type,
size_type >::type 
pop (OutputIterator it)
 Pops objects to the output iterator it. More...
 
template<typename Functor >
bool consume_one (Functor &f)
 consumes one element via a functor More...
 
template<typename Functor >
bool consume_one (Functor const &f)
 consumes one element via a functor More...
 
template<typename Functor >
size_type consume_all (Functor &f)
 consumes all elements via a functor More...
 
template<typename Functor >
size_type consume_all (Functor const &f)
 consumes all elements via a functor More...
 
size_type read_available () const
 get number of elements that are available for read More...
 
size_type write_available () const
 get write space to write elements More...
 
const Tfront () const
 get reference to element in the front of the queue More...
 
Tfront ()
 get reference to element in the front of the queue More...
 
 spsc_queue (void)
 Constructs a spsc_queue. More...
 
template<typename U >
 spsc_queue (typename allocator::template rebind< U >::other const &alloc)
 Constructs a spsc_queue. More...
 
 spsc_queue (allocator const &alloc)
 Constructs a spsc_queue. More...
 
 spsc_queue (size_type element_count)
 Constructs a spsc_queue for element_count elements. More...
 
template<typename U >
 spsc_queue (size_type element_count, typename allocator::template rebind< U >::other const &alloc)
 Constructs a spsc_queue for element_count elements. More...
 
 spsc_queue (size_type element_count, allocator_arg const &alloc)
 Constructs a spsc_queue for element_count elements. More...
 

Detailed Description

template<typename T, class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
class boost::lockfree::spsc_queue< T, A0, A1 >

The spsc_queue class provides a single-writer/single-reader fifo queue, pushing and popping is wait-free.

Policies:

  • boost::lockfree::capacity<>, optional
    If this template argument is passed to the options, the size of the ringbuffer is set at compile-time.
  • boost::lockfree::allocator<>, defaults to boost::lockfree::allocator<std::allocator<T>>
    Specifies the allocator that is used to allocate the ringbuffer. This option is only valid, if the ringbuffer is configured to be sized at run-time

Requirements:

  • T must have a default constructor
  • T must be copyable

Member Typedef Documentation

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
typedef implementation_defined::allocator boost::lockfree::spsc_queue< T, A0, A1 >::allocator
template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
typedef implementation_defined::size_type boost::lockfree::spsc_queue< T, A0, A1 >::size_type
typedef T boost::mpl::identity< BOOST_MPL_AUX_NA_PARAM >::type
inherited
template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
typedef T boost::lockfree::spsc_queue< T, A0, A1 >::value_type

Constructor & Destructor Documentation

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
boost::lockfree::spsc_queue< T, A0, A1 >::spsc_queue ( void  )
inline

Constructs a spsc_queue.

Precondition
spsc_queue must be configured to be sized at compile-time

References BOOST_ASSERT.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename U >
boost::lockfree::spsc_queue< T, A0, A1 >::spsc_queue ( typename allocator::template rebind< U >::other const &  alloc)
inlineexplicit

Constructs a spsc_queue.

Precondition
spsc_queue must be configured to be sized at compile-time

References boost::BOOST_STATIC_ASSERT().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
boost::lockfree::spsc_queue< T, A0, A1 >::spsc_queue ( allocator const &  alloc)
inlineexplicit

Constructs a spsc_queue.

Precondition
spsc_queue must be configured to be sized at compile-time

References BOOST_ASSERT.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
boost::lockfree::spsc_queue< T, A0, A1 >::spsc_queue ( size_type  element_count)
inlineexplicit

Constructs a spsc_queue for element_count elements.

Precondition
spsc_queue must be configured to be sized at run-time

References BOOST_ASSERT.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename U >
boost::lockfree::spsc_queue< T, A0, A1 >::spsc_queue ( size_type  element_count,
typename allocator::template rebind< U >::other const &  alloc 
)
inline

Constructs a spsc_queue for element_count elements.

Precondition
spsc_queue must be configured to be sized at run-time

References boost::BOOST_STATIC_ASSERT().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
boost::lockfree::spsc_queue< T, A0, A1 >::spsc_queue ( size_type  element_count,
allocator_arg const &  alloc 
)
inline

Constructs a spsc_queue for element_count elements.

Precondition
spsc_queue must be configured to be sized at run-time

References BOOST_ASSERT.

Member Function Documentation

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename Functor >
size_type boost::lockfree::spsc_queue< T, A0, A1 >::consume_all ( Functor &  f)
inline

consumes all elements via a functor

sequentially pops all elements from the queue and applies the functor on each object

Returns
number of elements that are consumed
Note
Thread-safe and non-blocking, if functor is thread-safe and non-blocking
template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename Functor >
size_type boost::lockfree::spsc_queue< T, A0, A1 >::consume_all ( Functor const &  f)
inline

consumes all elements via a functor

sequentially pops all elements from the queue and applies the functor on each object

Returns
number of elements that are consumed
Note
Thread-safe and non-blocking, if functor is thread-safe and non-blocking
template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename Functor >
bool boost::lockfree::spsc_queue< T, A0, A1 >::consume_one ( Functor &  f)
inline

consumes one element via a functor

pops one element from the queue and applies the functor on this object

Returns
true, if one element was consumed
Note
Thread-safe and non-blocking, if functor is thread-safe and non-blocking

Referenced by boost::lockfree::spsc_queue< T, A0, A1 >::pop().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename Functor >
bool boost::lockfree::spsc_queue< T, A0, A1 >::consume_one ( Functor const &  f)
inline

consumes one element via a functor

pops one element from the queue and applies the functor on this object

Returns
true, if one element was consumed
Note
Thread-safe and non-blocking, if functor is thread-safe and non-blocking
template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
const T& boost::lockfree::spsc_queue< T, A0, A1 >::front ( void  ) const
inline

get reference to element in the front of the queue

Availability of front element can be checked using read_available().

Precondition
only one thread is allowed to check front element
read_available() > 0. If ringbuffer is empty, it's undefined behaviour to invoke this method.
Returns
reference to the first element in the queue
Note
Thread-safe and wait-free

References BOOST_ASSERT, boost::xpressive::front, and boost::lockfree::spsc_queue< T, A0, A1 >::read_available().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
T& boost::lockfree::spsc_queue< T, A0, A1 >::front ( void  )
inline

get reference to element in the front of the queue

Availability of front element can be checked using read_available().

Precondition
only one thread is allowed to check front element
read_available() > 0. If ringbuffer is empty, it's undefined behaviour to invoke this method.
Returns
reference to the first element in the queue
Note
Thread-safe and wait-free

References BOOST_ASSERT, boost::xpressive::front, and boost::lockfree::spsc_queue< T, A0, A1 >::read_available().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
bool boost::lockfree::spsc_queue< T, A0, A1 >::pop ( void  )
inline

Pops one object from ringbuffer.

Precondition
only one thread is allowed to pop data to the spsc_queue
Postcondition
if ringbuffer is not empty, object will be discarded.
Returns
true, if the pop operation is successful, false if ringbuffer was empty.
Note
Thread-safe and wait-free

References boost::lockfree::spsc_queue< T, A0, A1 >::consume_one().

Referenced by boost::lockfree::spsc_queue< T, A0, A1 >::pop().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename U >
boost::enable_if<typename is_convertible<T, U>::type, bool>::type boost::lockfree::spsc_queue< T, A0, A1 >::pop ( U &  ret)
inline

Pops one object from ringbuffer.

Precondition
only one thread is allowed to pop data to the spsc_queue
Postcondition
if ringbuffer is not empty, object will be copied to ret.
Returns
true, if the pop operation is successful, false if ringbuffer was empty.
Note
Thread-safe and wait-free

References boost::lockfree::spsc_queue< T, A0, A1 >::consume_one().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
size_type boost::lockfree::spsc_queue< T, A0, A1 >::pop ( T ret,
size_type  size 
)
inline

Pops a maximum of size objects from ringbuffer.

Precondition
only one thread is allowed to pop data to the spsc_queue
Returns
number of popped items
Note
Thread-safe and wait-free

References boost::xpressive::pop.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<size_type size>
size_type boost::lockfree::spsc_queue< T, A0, A1 >::pop ( T(&)  ret[size])
inline

Pops a maximum of size objects from spsc_queue.

Precondition
only one thread is allowed to pop data to the spsc_queue
Returns
number of popped items
Note
Thread-safe and wait-free

References boost::lockfree::spsc_queue< T, A0, A1 >::pop().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename OutputIterator >
boost::disable_if<typename is_convertible<T, OutputIterator>::type, size_type>::type boost::lockfree::spsc_queue< T, A0, A1 >::pop ( OutputIterator  it)
inline

Pops objects to the output iterator it.

Precondition
only one thread is allowed to pop data to the spsc_queue
Returns
number of popped items
Note
Thread-safe and wait-free
template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
bool boost::lockfree::spsc_queue< T, A0, A1 >::push ( T const &  t)
inline

Pushes object t to the ringbuffer.

Precondition
only one thread is allowed to push data to the spsc_queue
Postcondition
object will be pushed to the spsc_queue, unless it is full.
Returns
true, if the push operation is successful.
Note
Thread-safe and wait-free

References boost::xpressive::push.

Referenced by boost::lockfree::spsc_queue< T, A0, A1 >::push().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
size_type boost::lockfree::spsc_queue< T, A0, A1 >::push ( T const *  t,
size_type  size 
)
inline

Pushes as many objects from the array t as there is space.

Precondition
only one thread is allowed to push data to the spsc_queue
Returns
number of pushed items
Note
Thread-safe and wait-free

References boost::xpressive::push.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<size_type size>
size_type boost::lockfree::spsc_queue< T, A0, A1 >::push ( T const (&)  t[size])
inline

Pushes as many objects from the array t as there is space available.

Precondition
only one thread is allowed to push data to the spsc_queue
Returns
number of pushed items
Note
Thread-safe and wait-free

References boost::lockfree::spsc_queue< T, A0, A1 >::push(), and boost::flyweights::t.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
template<typename ConstIterator >
ConstIterator boost::lockfree::spsc_queue< T, A0, A1 >::push ( ConstIterator  begin,
ConstIterator  end 
)
inline

Pushes as many objects from the range [begin, end) as there is space .

Precondition
only one thread is allowed to push data to the spsc_queue
Returns
iterator to the first element, which has not been pushed
Note
Thread-safe and wait-free

References boost::xpressive::push.

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
size_type boost::lockfree::spsc_queue< T, A0, A1 >::read_available ( ) const
inline

get number of elements that are available for read

Returns
number of available elements that can be popped from the spsc_queue
Note
Thread-safe and wait-free, should only be called from the producer thread

Referenced by boost::lockfree::spsc_queue< T, A0, A1 >::front().

template<typename T , class A0 = boost::parameter::void_, class A1 = boost::parameter::void_>
size_type boost::lockfree::spsc_queue< T, A0, A1 >::write_available ( ) const
inline

get write space to write elements

Returns
number of elements that can be pushed to the spsc_queue
Note
Thread-safe and wait-free, should only be called from the consumer thread

The documentation for this class was generated from the following file: