Seastar
High performance C++ framework for concurrent servers
|
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... | |
T | pop () noexcept |
Pop an item. More... | |
T & | front () noexcept |
access the front element in the queue More... | |
template<typename Func > requires std::is_nothrow_move_constructible_v<T> | |
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... | |
|
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.
|
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.
|
inlinenoexcept |
access the front element in the queue
Accessing the front of an empty or aborted queue will result in undefined behaviour.
|
inlinenoexcept |
Check if there is an active consumer.
Returns true if another fiber waits for an item to be pushed into the queue
|
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.
|
inlinenoexcept |
|
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.
|
inlinenoexcept |
Pop an item.
Popping from an empty queue will result in undefined behavior.
|
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.
|
inline |
Push an item.
Returns false if the queue was full and the item was not pushed.
|
inlinenoexcept |
|
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.