Seastar
High performance C++ framework for concurrent servers
Public Member Functions | List of all members
seastar::queue< T > Class Template Reference

Detailed Description

template<typename T>
class seastar::queue< T >

Asynchronous single-producer single-consumer queue with limited capacity. There can be at most one producer-side and at most one consumer-side operation active at any time. Operations returning a future are considered to be active until the future resolves.

Note: queue requires the data type T to be nothrow move constructible as it's returned as future<T> by pop_eventually and seastar futurized data type are required to be nothrow move-constructible.

#include <seastar/core/queue.hh>

Public Member Functions

 queue (size_t size)
 
bool push (T &&a)
 Push an item. More...
 
pop () noexcept
 Pop an item. More...
 
T & front () noexcept
 access the front element in the queue More...
 
template<typename Func >
bool consume (Func &&func)
 
bool empty () const noexcept
 Returns true when the queue is empty.
 
bool full () const noexcept
 Returns true when the queue is full.
 
future not_empty () noexcept
 
future not_full () noexcept
 
future< T > pop_eventually () noexcept
 
future push_eventually (T &&data) noexcept
 
size_t size () const noexcept
 Returns the number of items currently in the queue.
 
size_t max_size () const noexcept
 
void set_max_size (size_t max) noexcept
 
void abort (std::exception_ptr ex) noexcept
 
bool has_blocked_consumer () const noexcept
 Check if there is an active consumer. More...
 

Member Function Documentation

◆ abort()

template<typename T >
void seastar::queue< T >::abort ( std::exception_ptr  ex)
inlinenoexcept

Destroy any items in the queue, and pass the provided exception to any waiting readers or writers - or to any later read or write attempts.

◆ consume()

template<typename T >
template<typename Func >
bool seastar::queue< T >::consume ( Func &&  func)
inline

Consumes items from the queue, passing them to func, until func returns false or the queue it empty

Returns false if func returned false.

◆ front()

template<typename T >
T & seastar::queue< T >::front
inlinenoexcept

access the front element in the queue

Accessing the front of an empty or aborted queue will result in undefined behaviour.

◆ has_blocked_consumer()

template<typename T >
bool seastar::queue< T >::has_blocked_consumer ( ) const
inlinenoexcept

Check if there is an active consumer.

Returns true if another fiber waits for an item to be pushed into the queue

◆ max_size()

template<typename T >
size_t seastar::queue< T >::max_size ( ) const
inlinenoexcept

Returns the size limit imposed on the queue during its construction or by a call to set_max_size(). If the queue contains max_size() items (or more), further items cannot be pushed until some are popped.

◆ not_empty()

template<typename T >
future seastar::queue< T >::not_empty
inlinenoexcept

Returns a future<> that becomes available when pop() or consume() can be called. A consumer-side operation. Cannot be called concurrently with other consumer-side operations.

◆ not_full()

template<typename T >
future seastar::queue< T >::not_full
inlinenoexcept

Returns a future<> that becomes available when push() can be called. A producer-side operation. Cannot be called concurrently with other producer-side operations.

◆ pop()

template<typename T >
T seastar::queue< T >::pop
inlinenoexcept

Pop an item.

Popping from an empty queue will result in undefined behavior.

◆ pop_eventually()

template<typename T >
future< T > seastar::queue< T >::pop_eventually
inlinenoexcept

Pops element now or when there is some. Returns a future that becomes available when some element is available. If the queue is, or already was, abort()ed, the future resolves with the exception provided to abort(). A consumer-side operation. Cannot be called concurrently with other consumer-side operations.

◆ push()

template<typename T >
bool seastar::queue< T >::push ( T &&  a)
inline

Push an item.

Returns false if the queue was full and the item was not pushed.

◆ push_eventually()

template<typename T >
future seastar::queue< T >::push_eventually ( T &&  data)
inlinenoexcept

Pushes the element now or when there is room. Returns a future<> which resolves when data was pushed. If the queue is, or already was, abort()ed, the future resolves with the exception provided to abort(). A producer-side operation. Cannot be called concurrently with other producer-side operations.

◆ set_max_size()

template<typename T >
void seastar::queue< T >::set_max_size ( size_t  max)
inlinenoexcept

Set the maximum size to a new value. If the queue's max size is reduced, items already in the queue will not be expunged and the queue will be temporarily bigger than its max_size.


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