join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs > Class Template Reference

timing wheel. More...

#include <wheel.hpp>

Public Member Functions

template<typename... Args>
 BasicWheel (Args &&... args)
 create instance.
 
 BasicWheel (const BasicWheel &other)=delete
 copy constructor.
 
BasicWheel & operator= (const BasicWheel &other)=delete
 copy assignment operator.
 
 BasicWheel (BasicWheel &&other)=delete
 move constructor.
 
BasicWheel & operator= (BasicWheel &&other)=delete
 move assignment operator.
 
 ~BasicWheel () noexcept
 destroy instance.
 
template<class Rep , class Period , typename Func , typename... Args>
ssize_t setOneShot (std::chrono::duration< Rep, Period > duration, Func &&callback, Args &&... args) noexcept
 arm a one-shot timer.
 
template<class Rep , class Period , typename Func , typename... Args>
ssize_t setInterval (std::chrono::duration< Rep, Period > duration, Func &&callback, Args &&... args) noexcept
 arm a periodic timer.
 
int cancel (ssize_t id, bool sync=false) noexcept
 cancel a timer.
 
bool active (ssize_t id) const noexcept
 check if a timer is armed.
 
std::chrono::nanoseconds remaining (ssize_t id) const noexcept
 get the time left.
 
std::chrono::nanoseconds interval (ssize_t id) const noexcept
 get the interval.
 
bool oneShot (ssize_t id) const noexcept
 check if a timer is one-shot.
 
int mlock () const noexcept
 lock wheel memory in RAM.
 
const RunPolicy & runner () const noexcept
 get the run policy.
 

Static Public Member Functions

static constexpr std::chrono::nanoseconds resolution () noexcept
 get the tick duration.
 
static constexpr size_t capacity () noexcept
 get the capacity.
 

Detailed Description

template<class ClockPolicy, class RunPolicy, size_t Capacity, uint64_t TickNs>
class join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >

timing wheel.

Constructor & Destructor Documentation

◆ BasicWheel() [1/3]

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
template<typename... Args>
join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::BasicWheel ( Args &&... args)
inlineexplicit

create instance.

Parameters
argsarguments forwarded to the run policy.
Exceptions
std::system_erroron failure.
std::runtime_errorif the clock is not invariant.

◆ BasicWheel() [2/3]

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::BasicWheel ( const BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicWheel() [3/3]

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::BasicWheel ( BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs > && other)
delete

move constructor.

Parameters
otherother object to move.

◆ ~BasicWheel()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::~BasicWheel ( )
inlinenoexcept

destroy instance.

Member Function Documentation

◆ active()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
bool join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::active ( ssize_t id) const
inlinenoexcept

check if a timer is armed.

Parameters
idtimer handle.
Returns
true if the timer is armed.

◆ cancel()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
int join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::cancel ( ssize_t id,
bool sync = false )
inlinenoexcept

cancel a timer.

Parameters
idtimer handle.
syncwait until the callback can no longer run.
Returns
0 on success, -1 on failure.

◆ capacity()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
static constexpr size_t join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::capacity ( )
inlinestaticconstexprnoexcept

get the capacity.

Returns
capacity.

◆ interval()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
std::chrono::nanoseconds join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::interval ( ssize_t id) const
inlinenoexcept

get the interval.

Parameters
idtimer handle.
Returns
interval, zero if one-shot or not armed.

◆ mlock()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
int join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::mlock ( ) const
inlinenoexcept

lock wheel memory in RAM.

Returns
0 on success, -1 on failure.

◆ oneShot()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
bool join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::oneShot ( ssize_t id) const
inlinenoexcept

check if a timer is one-shot.

Parameters
idtimer handle.
Returns
true if one-shot.

◆ operator=() [1/2]

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
BasicWheel & join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::operator= ( BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs > && other)
delete

move assignment operator.

Parameters
otherother object to move.
Returns
current object.

◆ operator=() [2/2]

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
BasicWheel & join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::operator= ( const BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs > & other)
delete

copy assignment operator.

Parameters
otherother object to copy.
Returns
current object.

◆ remaining()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
std::chrono::nanoseconds join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::remaining ( ssize_t id) const
inlinenoexcept

get the time left.

Parameters
idtimer handle.
Returns
time left, zero if not armed.

◆ resolution()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
static constexpr std::chrono::nanoseconds join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::resolution ( )
inlinestaticconstexprnoexcept

get the tick duration.

Returns
tick duration.

◆ runner()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
const RunPolicy & join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::runner ( ) const
inlinenoexcept

get the run policy.

Returns
run policy.

◆ setInterval()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
template<class Rep , class Period , typename Func , typename... Args>
ssize_t join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::setInterval ( std::chrono::duration< Rep, Period > duration,
Func && callback,
Args &&... args )
inlinenoexcept

arm a periodic timer.

Parameters
durationinterval, rounded up to a tick.
callbackcallback.
argscallback arguments.
Returns
timer handle on success, -1 on failure.

◆ setOneShot()

template<class ClockPolicy , class RunPolicy , size_t Capacity, uint64_t TickNs>
template<class Rep , class Period , typename Func , typename... Args>
ssize_t join::BasicWheel< ClockPolicy, RunPolicy, Capacity, TickNs >::setOneShot ( std::chrono::duration< Rep, Period > duration,
Func && callback,
Args &&... args )
inlinenoexcept

arm a one-shot timer.

Parameters
durationdelay, rounded up to a tick.
callbackcallback.
argscallback arguments.
Returns
timer handle on success, -1 on failure.

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