25#include <seastar/core/future.hh>
26#include <seastar/core/chunked_fifo.hh>
30#include <seastar/core/lowres_clock.hh>
31#include <seastar/core/timed_out_error.hh>
32#include <seastar/util/modules.hh>
39 void operator()(T&)
noexcept {};
42template<
typename... T>
58template <
typename T,
typename OnExpiry = dummy_expiry<T>,
typename Clock = lowres_clock>
62 using time_point =
typename Clock::time_point;
65 std::optional<T> payload;
67 entry(T&& payload_) : payload(std::move(payload_)) {}
68 entry(
const T& payload_) : payload(payload_) {}
70 : payload(std::move(payload_))
72 ef._on_expiry(*payload);
73 payload = std::nullopt;
75 ef.drop_expired_front();
80 entry(entry&& x) =
delete;
81 entry(
const entry& x) =
delete;
88 std::unique_ptr<entry> _front;
96 void drop_expired_front()
noexcept {
97 while (!_list.empty() && !_list.front().payload) {
100 if (_front && !_front->payload) {
106 expiring_fifo(OnExpiry on_expiry)
noexcept(std::is_nothrow_move_constructible_v<OnExpiry>) : _on_expiry(std::move(on_expiry)) {}
111 assert(o._size == 0);
132 explicit operator bool() const noexcept {
140 return *_front->payload;
142 return *_list.front().payload;
149 return *_front->payload;
151 return *_list.front().payload;
166 return _list.reserve(
size);
173 _front = std::make_unique<entry>(payload);
175 _list.emplace_back(payload);
184 _front = std::make_unique<entry>(std::move(payload));
186 _list.emplace_back(std::move(payload));
195 if (timeout == time_point::max()) {
200 _front = std::make_unique<entry>(std::move(payload), *
this, timeout);
202 _list.emplace_back(std::move(payload), *
this, timeout);
216 drop_expired_front();
Definition: expiring_fifo.hh:59
bool empty() const noexcept
Definition: expiring_fifo.hh:127
size_t size() const noexcept
Definition: expiring_fifo.hh:157
void pop_front() noexcept
Definition: expiring_fifo.hh:209
void push_back(const T &payload)
Definition: expiring_fifo.hh:171
const T & front() const noexcept
Definition: expiring_fifo.hh:147
void reserve(size_t size)
Definition: expiring_fifo.hh:165
T & front() noexcept
Definition: expiring_fifo.hh:138
void push_back(T &&payload)
Definition: expiring_fifo.hh:182
void push_back(T &&payload, time_point timeout)
Definition: expiring_fifo.hh:194
void set_exception(std::exception_ptr &&ex) noexcept
Marks the promise as failed.
Definition: future.hh:998
Definition: timed_out_error.hh:34
void arm(time_point until, std::optional< duration > period={}) noexcept
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: expiring_fifo.hh:38
Definition: expiring_fifo.hh:43