Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy > Class Template Reference

Zero-heap Min-Heap Timer Scheduler for delayed and periodic events. Provides O(1) earliest-due timer checks and O(log N) insertion and rescheduling. Supports single-shot delayed events and recurring periodic events with compile-time clock policy. More...

#include <TimerScheduler.hpp>

+ Inheritance diagram for corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >:
+ Collaboration diagram for corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >:

Classes

struct  TimerComparator
 
struct  TimerEntry
 

Public Types

using Clock = ClockPolicy
 
using duration = typename ClockPolicy::duration
 
using time_point = typename ClockPolicy::time_point
 

Public Member Functions

size_t activeCount () const noexcept
 Get current number of active timers.
 
bool cancelTimer (TimerId id) noexcept
 Cancel an active timer by its TimerId handle.
 
constexpr size_t capacity () const noexcept
 Get maximum timer capacity.
 
template<typename EventSink >
std::size_t processDueTimers (EventSink &sink, time_point now=ClockPolicy::now())
 Process all due timers and post their events into target event bus or sink. Uses O(1) early exit when the earliest timer is not yet due.
 
template<typename Rep , typename Period >
TimerId scheduleDelayed (EventVariant event, const std::chrono::duration< Rep, Period > &delay, EventPriority priority=EventPriority::Normal)
 Schedule a single-shot delayed event with std::chrono duration.
 
TimerId scheduleDelayed (EventVariant event, duration delay, EventPriority priority=EventPriority::Normal)
 Schedule a single-shot delayed event with native clock duration.
 
template<typename Rep , typename Period >
TimerId schedulePeriodic (EventVariant event, const std::chrono::duration< Rep, Period > &interval, EventPriority priority=EventPriority::Normal)
 Schedule a recurring periodic event with std::chrono duration.
 
TimerId schedulePeriodic (EventVariant event, duration interval, EventPriority priority=EventPriority::Normal)
 Schedule a recurring periodic event with native clock duration.
 
 TimerScheduler ()=default
 

Detailed Description

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
class corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >

Zero-heap Min-Heap Timer Scheduler for delayed and periodic events. Provides O(1) earliest-due timer checks and O(log N) insertion and rescheduling. Supports single-shot delayed events and recurring periodic events with compile-time clock policy.

Template Parameters
EventVariantSupported event variant list type.
MaxTimersMaximum number of concurrent active timers (static min-heap capacity).
ClockPolicyPolicy governing time acquisition and arithmetic (ChronoClockPolicy default).

Member Typedef Documentation

◆ Clock

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
using corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::Clock = ClockPolicy

◆ duration

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
using corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::duration = typename ClockPolicy::duration

◆ time_point

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
using corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::time_point = typename ClockPolicy::time_point

Constructor & Destructor Documentation

◆ TimerScheduler()

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::TimerScheduler ( )
default

Member Function Documentation

◆ activeCount()

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
size_t corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::activeCount ( ) const
inlinenoexcept

Get current number of active timers.

◆ cancelTimer()

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
bool corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::cancelTimer ( TimerId  id)
inlinenoexcept

Cancel an active timer by its TimerId handle.

Parameters
idHandle of the timer to cancel.
Returns
true if timer was found and cancelled; false if handle was invalid/inactive.
+ Here is the caller graph for this function:

◆ capacity()

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
constexpr size_t corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::capacity ( ) const
inlineconstexprnoexcept

Get maximum timer capacity.

◆ processDueTimers()

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
template<typename EventSink >
std::size_t corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::processDueTimers ( EventSink sink,
time_point  now = ClockPolicy::now() 
)
inline

Process all due timers and post their events into target event bus or sink. Uses O(1) early exit when the earliest timer is not yet due.

Template Parameters
TargetEventSinkTarget event sink type (e.g. BasicEventBus or EventSink).
Parameters
sinkTarget sink receiving due timer events.
nowCurrent time point (defaults to ClockPolicy::now()).
Returns
Number of events posted during this check.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scheduleDelayed() [1/2]

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
template<typename Rep , typename Period >
TimerId corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::scheduleDelayed ( EventVariant  event,
const std::chrono::duration< Rep, Period > &  delay,
EventPriority  priority = EventPriority::Normal 
)
inline

Schedule a single-shot delayed event with std::chrono duration.

+ Here is the caller graph for this function:

◆ scheduleDelayed() [2/2]

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
TimerId corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::scheduleDelayed ( EventVariant  event,
duration  delay,
EventPriority  priority = EventPriority::Normal 
)
inline

Schedule a single-shot delayed event with native clock duration.

◆ schedulePeriodic() [1/2]

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
template<typename Rep , typename Period >
TimerId corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::schedulePeriodic ( EventVariant  event,
const std::chrono::duration< Rep, Period > &  interval,
EventPriority  priority = EventPriority::Normal 
)
inline

Schedule a recurring periodic event with std::chrono duration.

+ Here is the caller graph for this function:

◆ schedulePeriodic() [2/2]

template<typename EventVariant = DefaultEvents, size_t MaxTimers = 64, typename ClockPolicy = ChronoClockPolicy>
TimerId corium::TimerScheduler< EventVariant, MaxTimers, ClockPolicy >::schedulePeriodic ( EventVariant  event,
duration  interval,
EventPriority  priority = EventPriority::Normal 
)
inline

Schedule a recurring periodic event with native clock duration.


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