Seastar
High performance C++ framework for concurrent servers
Public Types | Public Member Functions | List of all members
seastar::timer_set< Timer, link > Class Template Reference

Detailed Description

template<typename Timer, boost::intrusive::list_member_hook<> Timer::* link>
class seastar::timer_set< Timer, link >

A data structure designed for holding and expiring timers. It's optimized for timer non-delivery by deferring sorting cost until expiry time. The optimization is based on the observation that in many workloads timers are cancelled or rescheduled before they expire. That's especially the case for TCP timers.

The template type "Timer" should have a method named get_timeout() which returns Timer::time_point which denotes timer's expiration.

#include <seastar/core/timer-set.hh>

Public Types

using time_point = typename Timer::time_point
 
using timer_list_t = boost::intrusive::list< Timer, boost::intrusive::member_hook< Timer, boost::intrusive::list_member_hook<>, link > >
 

Public Member Functions

bool insert (Timer &timer)
 
void remove (Timer &timer) noexcept
 
timer_list_t expire (time_point now)
 
time_point get_next_timeout () const
 
void clear ()
 
size_t size () const
 
bool empty () const
 
time_point now ()
 

Member Function Documentation

◆ clear()

template<typename Timer , boost::intrusive::list_member_hook<> Timer::* link>
void seastar::timer_set< Timer, link >::clear ( )
inline

Clears both active and expired timer sets.

◆ empty()

template<typename Timer , boost::intrusive::list_member_hook<> Timer::* link>
bool seastar::timer_set< Timer, link >::empty ( ) const
inline

Returns true if and only if there are no timers in the active set.

◆ expire()

template<typename Timer , boost::intrusive::list_member_hook<> Timer::* link>
timer_list_t seastar::timer_set< Timer, link >::expire ( time_point  now)
inline

Expires active timers.

The time points passed to this function must be monotonically increasing. Use get_next_timeout() to query for the next time point.

Preconditions:

  • the time_point passed to this function must not be lesser than the previous one passed to this function.

Postconditons:

  • all timers from the active set with Timer::get_timeout() <= now are moved to the expired set.

◆ get_next_timeout()

template<typename Timer , boost::intrusive::list_member_hook<> Timer::* link>
time_point seastar::timer_set< Timer, link >::get_next_timeout ( ) const
inline

Returns a time point at which expire() should be called in order to ensure timers are expired in a timely manner.

Returned values are monotonically increasing.

◆ insert()

template<typename Timer , boost::intrusive::list_member_hook<> Timer::* link>
bool seastar::timer_set< Timer, link >::insert ( Timer &  timer)
inline

Adds timer to the active set.

The value returned by timer.get_timeout() is used as timer's expiry. The result of timer.get_timeout() must not change while the timer is in the active set.

Preconditions:

  • this timer must not be currently in the active set or in the expired set.

Postconditions:

  • this timer will be added to the active set until it is expired by a call to expire() or removed by a call to remove().

Returns true if and only if this timer's timeout is less than get_next_timeout(). When this function returns true the caller should reschedule expire() to be called at timer.get_timeout() to ensure timers are expired in a timely manner.

◆ remove()

template<typename Timer , boost::intrusive::list_member_hook<> Timer::* link>
void seastar::timer_set< Timer, link >::remove ( Timer &  timer)
inlinenoexcept

Removes timer from the active set.

Preconditions:

  • timer must be currently in the active set. Note: it must not be in the expired set.

Postconditions:

  • timer is no longer in the active set.
  • this object will no longer hold any references to this timer.

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