Seastar
High performance C++ framework for concurrent servers
Classes | Public Types | Public Member Functions | List of all members
seastar::expiring_fifo< T, OnExpiry, Clock > Class Template Reference

Detailed Description

template<typename T, typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
class seastar::expiring_fifo< T, OnExpiry, Clock >

Container for elements with support for expiration of entries.

OnExpiry is a functor which will be called with a reference to T right before it expires. T is removed and destroyed from the container immediately after OnExpiry returns. OnExpiry callback must not modify the container, it can only modify its argument.

The container can only be moved before any elements are pushed.

#include <seastar/core/expiring_fifo.hh>

Public Types

using clock = Clock
 
using time_point = typename Clock::time_point
 

Public Member Functions

 expiring_fifo (OnExpiry on_expiry) noexcept(std::is_nothrow_move_constructible_v< OnExpiry >)
 
 expiring_fifo (expiring_fifo &&o) noexcept
 
expiring_fifooperator= (expiring_fifo &&o) noexcept
 
bool empty () const noexcept
 
 operator bool () const noexcept
 Equivalent to !empty()
 
T & front () noexcept
 
const T & front () const noexcept
 
size_t size () const noexcept
 
void reserve (size_t size)
 
void push_back (const T &payload)
 
void push_back (T &&payload)
 
void push_back (T &&payload, time_point timeout)
 
void pop_front () noexcept
 

Member Function Documentation

◆ empty()

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
bool seastar::expiring_fifo< T, OnExpiry, Clock >::empty ( ) const
inlinenoexcept

Checks if container contains any elements

Note
Inside OnExpiry callback, the expired element is still contained.
Returns
true if and only if there are any elements contained.

◆ front() [1/2]

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
const T& seastar::expiring_fifo< T, OnExpiry, Clock >::front ( ) const
inlinenoexcept

Returns a reference to the element in the front. Valid only when !empty().

◆ front() [2/2]

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
T& seastar::expiring_fifo< T, OnExpiry, Clock >::front ( )
inlinenoexcept

Returns a reference to the element in the front. Valid only when !empty().

◆ pop_front()

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
void seastar::expiring_fifo< T, OnExpiry, Clock >::pop_front ( )
inlinenoexcept

Removes the element at the front. Can be called only if !empty().

◆ push_back() [1/3]

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
void seastar::expiring_fifo< T, OnExpiry, Clock >::push_back ( const T &  payload)
inline

Adds element to the back of the queue. The element will never expire.

◆ push_back() [2/3]

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
void seastar::expiring_fifo< T, OnExpiry, Clock >::push_back ( T &&  payload)
inline

Adds element to the back of the queue. The element will never expire.

◆ push_back() [3/3]

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
void seastar::expiring_fifo< T, OnExpiry, Clock >::push_back ( T &&  payload,
time_point  timeout 
)
inline

Adds element to the back of the queue. The element will expire when timeout is reached, unless it is time_point::max(), in which case it never expires.

◆ reserve()

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
void seastar::expiring_fifo< T, OnExpiry, Clock >::reserve ( size_t  size)
inline

Reserves storage in the container for at least 'size' elements. Note that expired elements may also take space when they are not in the front of the queue.

Doesn't give any guarantees about exception safety of subsequent push_back().

◆ size()

template<typename T , typename OnExpiry = dummy_expiry<T>, typename Clock = lowres_clock>
size_t seastar::expiring_fifo< T, OnExpiry, Clock >::size ( ) const
inlinenoexcept

Returns the number of elements contained.

Note
Expired elements are not contained. Expiring element is still contained when OnExpiry is called.

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