![]() |
Home | Libraries | People | FAQ | More |
boost::lockfree::spsc_queue
// In header: <boost/lockfree/spsc_queue.hpp> template<typename T, Options> class spsc_queue { public: // types typedef ; typedef ; typedef ; // construct/copy/destruct (); template<typename U> (); (); (); template<typename U> (, ); (, ); // public member functions (); (); template<typename U> (); (, ); template< size> (); template<typename ConstIterator> (, ); (, ); template< size> (); template<typename OutputIterator> (); template<typename Functor> (); template<typename Functor> (); template<typename Functor> (); template<typename Functor> (); () ; () ; () ; (); (); };
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
spsc_queue
public
construct/copy/destruct();
Constructs a spsc_queue
Requires: |
spsc_queue must be configured to be sized at compile-time |
template<typename U> ();
Constructs a spsc_queue
with a custom allocator
![]() |
Note |
---|---|
This is just for API compatibility: an allocator isn't actually needed |
Requires: |
spsc_queue must be configured to be sized at compile-time |
();
Constructs a spsc_queue
with a custom allocator
![]() |
Note |
---|---|
This is just for API compatibility: an allocator isn't actually needed |
Requires: |
spsc_queue must be configured to be sized at compile-time |
( element_count);
Constructs a spsc_queue
for element_count elements
Requires: |
spsc_queue must be configured to be sized at run-time |
template<typename U> ( element_count, alloc);
Constructs a spsc_queue
for element_count elements with a custom allocator
Requires: |
spsc_queue must be configured to be sized at run-time |
( element_count, alloc);
Constructs a spsc_queue
for element_count elements with a custom allocator
Requires: |
spsc_queue must be configured to be sized at run-time |
spsc_queue
public member functions( t);
Pushes object t to the ringbuffer.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to push data to the spsc_queue |
Postconditions: |
object will be pushed to the spsc_queue, unless it is full. |
Returns: |
true, if the push operation is successful. |
();
Pops one object from ringbuffer.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to pop data to the spsc_queue |
Postconditions: |
if ringbuffer is not empty, object will be discarded. |
Returns: |
true, if the pop operation is successful, false if ringbuffer was empty. |
template<typename U> ( ret);
Pops one object from ringbuffer.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to pop data to the spsc_queue |
Postconditions: |
if ringbuffer is not empty, object will be copied to ret. |
Returns: |
true, if the pop operation is successful, false if ringbuffer was empty. |
( t, size);
Pushes as many objects from the array t as there is space.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to push data to the spsc_queue |
Returns: |
number of pushed items |
template< size> ( t);
Pushes as many objects from the array t as there is space available.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to push data to the spsc_queue |
Returns: |
number of pushed items |
template<typename ConstIterator> ( begin, end);
Pushes as many objects from the range [begin, end) as there is space .
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to push data to the spsc_queue |
Returns: |
iterator to the first element, which has not been pushed |
( ret, size);
Pops a maximum of size objects from ringbuffer.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to pop data to the spsc_queue |
Returns: |
number of popped items |
template< size> ( ret);
Pops a maximum of size objects from spsc_queue
.
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to pop data to the spsc_queue |
Returns: |
number of popped items |
template<typename OutputIterator> ( it);
Pops objects to the output iterator it
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only one thread is allowed to pop data to the spsc_queue |
Returns: |
number of popped items |
template<typename Functor> ( f);
consumes one element via a functor
pops one element from the queue and applies the functor on this object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
true, if one element was consumed |
template<typename Functor> ( f);
consumes one element via a functor
pops one element from the queue and applies the functor on this object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
true, if one element was consumed |
template<typename Functor> ( f);
consumes all elements via a functor
sequentially pops all elements from the queue and applies the functor on each object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
number of elements that are consumed |
template<typename Functor> ( f);
consumes all elements via a functor
sequentially pops all elements from the queue and applies the functor on each object
![]() |
Note |
---|---|
Thread-safe and non-blocking, if functor is thread-safe and non-blocking |
Returns: |
number of elements that are consumed |
() ;
get number of elements that are available for read
![]() |
Note |
---|---|
Thread-safe and wait-free, should only be called from the consumer thread |
Returns: |
number of available elements that can be popped from the spsc_queue |
() ;
get write space to write elements
![]() |
Note |
---|---|
Thread-safe and wait-free, should only be called from the producer thread |
Returns: |
number of elements that can be pushed to the spsc_queue |
() ;
get reference to element in the front of the queue
Availability of front element can be checked using read_available().
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only a consuming thread is allowed to check front element |
Requires: |
read_available() > 0. If ringbuffer is empty, it's undefined behaviour to invoke this method. |
Returns: |
reference to the first element in the queue |
();
get reference to element in the front of the queue
Availability of front element can be checked using read_available().
![]() |
Note |
---|---|
Thread-safe and wait-free |
Requires: |
only a consuming thread is allowed to check front element |
Requires: |
read_available() > 0. If ringbuffer is empty, it's undefined behaviour to invoke this method. |
Returns: |
reference to the first element in the queue |
();
reset the ringbuffer
![]() |
Note |
---|---|
Not thread-safe |