roo_scheduler
API Documentation for roo_scheduler
Loading...
Searching...
No Matches
roo_scheduler::Scheduler Class Reference

Schedules and dispatches delayed task executions. More...

#include <roo_scheduler.h>

Public Member Functions

 Scheduler ()
 Creates an empty scheduler.
 
ExecutionID scheduleOn (roo_time::Uptime when, Executable &task, Priority priority=Priority::kNormal)
 Schedules execution no earlier than when.
 
ExecutionID scheduleOn (roo_time::Uptime when, std::unique_ptr< Executable > task, Priority priority=Priority::kNormal)
 Schedules execution no earlier than when.
 
ExecutionID scheduleOn (roo_time::Uptime when, std::function< void()> task, Priority priority=Priority::kNormal)
 Schedules callable execution no earlier than when.
 
ExecutionID scheduleOn (Executable *task, roo_time::Uptime when, Priority priority=Priority::kNormal)
 
ExecutionID scheduleAfter (roo_time::Duration delay, Executable &task, Priority priority=Priority::kNormal)
 Schedules execution after delay elapses.
 
ExecutionID scheduleAfter (roo_time::Duration delay, std::unique_ptr< Executable > task, Priority priority=Priority::kNormal)
 Schedules execution after delay elapses.
 
ExecutionID scheduleAfter (roo_time::Duration delay, std::function< void()> task, Priority priority=Priority::kNormal)
 Schedules callable execution after delay elapses.
 
ExecutionID scheduleAfter (Executable *task, roo_time::Duration delay, Priority priority=Priority::kNormal)
 
ExecutionID scheduleNow (Executable &task, Priority priority=Priority::kNormal)
 Schedules execution as soon as possible.
 
ExecutionID scheduleNow (std::unique_ptr< Executable > task, Priority priority=Priority::kNormal)
 Schedules execution as soon as possible.
 
ExecutionID scheduleNow (std::function< void()> task, Priority priority=Priority::kNormal)
 Schedules callable execution as soon as possible.
 
bool executeEligibleTasksUpToNow (Priority min_priority=Priority::kMinimum, int max_count=-1)
 Executes up to max_count eligible tasks due no later than now.
 
bool executeEligibleTasksUpTo (roo_time::Uptime deadline, Priority min_priority=Priority::kMinimum, int max_count=-1)
 Executes up to max_count eligible tasks due no later than deadline.
 
bool executeEligibleTasks (Priority min_priority, int max_count=-1)
 Executes up to max_count eligible tasks with at least min_priority.
 
bool executeEligibleTasks (int max_count=-1)
 Executes up to max_count eligible tasks.
 
roo_time::Uptime getNearestExecutionTime () const
 Returns due time of the nearest upcoming execution.
 
roo_time::Duration getNearestExecutionDelay () const
 Returns delay to the nearest upcoming execution.
 
void cancel (ExecutionID)
 Marks execution identified by id as canceled.
 
void pruneCanceled ()
 Removes canceled executions from the queue.
 
bool empty () const
 Returns true iff no pending (non-canceled) executions exist.
 
void delay (roo_time::Duration delay, Priority min_priority=Priority::kNormal)
 Delays for at least delay while executing scheduled work.
 
void delayUntil (roo_time::Uptime deadline, Priority min_priority=Priority::kNormal)
 Delays until deadline while executing scheduled work.
 
void run ()
 Runs scheduler event loop forever.
 

Detailed Description

Schedules and dispatches delayed task executions.

Scheduler does not execute eligible work automatically; caller must invoke one of executeEligibleTasks*() methods.

Definition at line 107 of file roo_scheduler.h.

Constructor & Destructor Documentation

◆ Scheduler()

roo_scheduler::Scheduler::Scheduler ( )

Creates an empty scheduler.

Definition at line 7 of file roo_scheduler.cpp.

Member Function Documentation

◆ cancel()

◆ delay()

void roo_scheduler::Scheduler::delay ( roo_time::Duration  delay,
Priority  min_priority = Priority::kNormal 
)

Delays for at least delay while executing scheduled work.

Tasks due by the requested return time (now + delay) with priority >= min_priority are guaranteed to execute before return. Lower-priority overdue tasks may remain pending.

Note: because scheduled callbacks execute on the caller's stack, this mode can increase stack usage compared with explicit event-loop dispatch.

Definition at line 252 of file roo_scheduler.cpp.

References delay(), and delayUntil().

Referenced by delay(), run(), scheduleAfter(), scheduleAfter(), scheduleAfter(), and scheduleAfter().

◆ delayUntil()

void roo_scheduler::Scheduler::delayUntil ( roo_time::Uptime  deadline,
Priority  min_priority = Priority::kNormal 
)

Delays until deadline while executing scheduled work.

Tasks due by deadline with priority >= min_priority are guaranteed to execute before return. Lower-priority overdue tasks may remain pending.

Definition at line 256 of file roo_scheduler.cpp.

References executeEligibleTasks(), and executeEligibleTasksUpTo().

Referenced by delay().

◆ empty()

bool roo_scheduler::Scheduler::empty ( ) const
inline

Returns true iff no pending (non-canceled) executions exist.

Definition at line 240 of file roo_scheduler.h.

◆ executeEligibleTasks() [1/2]

bool roo_scheduler::Scheduler::executeEligibleTasks ( int  max_count = -1)
inline

Executes up to max_count eligible tasks.

Returns
true if no eligible executions remain in queue; false otherwise.

Definition at line 219 of file roo_scheduler.h.

References executeEligibleTasks(), and roo_scheduler::kMinimum.

◆ executeEligibleTasks() [2/2]

bool roo_scheduler::Scheduler::executeEligibleTasks ( Priority  min_priority,
int  max_count = -1 
)

Executes up to max_count eligible tasks with at least min_priority.

Returns
true if no eligible executions remain in queue; false otherwise.

Definition at line 93 of file roo_scheduler.cpp.

Referenced by delayUntil(), executeEligibleTasks(), and run().

◆ executeEligibleTasksUpTo()

bool roo_scheduler::Scheduler::executeEligibleTasksUpTo ( roo_time::Uptime  deadline,
Priority  min_priority = Priority::kMinimum,
int  max_count = -1 
)

Executes up to max_count eligible tasks due no later than deadline.

Tasks below min_priority are ignored (not executed).

Returns
true if no eligible executions remain in queue; false otherwise.

Definition at line 85 of file roo_scheduler.cpp.

Referenced by delayUntil(), and executeEligibleTasksUpToNow().

◆ executeEligibleTasksUpToNow()

bool roo_scheduler::Scheduler::executeEligibleTasksUpToNow ( Priority  min_priority = Priority::kMinimum,
int  max_count = -1 
)
inline

Executes up to max_count eligible tasks due no later than now.

Tasks below min_priority are ignored (not executed).

Returns
true if no eligible executions remain in queue; false otherwise.

Definition at line 196 of file roo_scheduler.h.

References executeEligibleTasksUpTo().

◆ getNearestExecutionDelay()

roo_time::Duration roo_scheduler::Scheduler::getNearestExecutionDelay ( ) const

Returns delay to the nearest upcoming execution.

Definition at line 118 of file roo_scheduler.cpp.

◆ getNearestExecutionTime()

roo_time::Uptime roo_scheduler::Scheduler::getNearestExecutionTime ( ) const

Returns due time of the nearest upcoming execution.

Definition at line 101 of file roo_scheduler.cpp.

◆ pruneCanceled()

void roo_scheduler::Scheduler::pruneCanceled ( )

Removes canceled executions from the queue.

This is linear-time and should be used sparingly.

Definition at line 229 of file roo_scheduler.cpp.

◆ run()

void roo_scheduler::Scheduler::run ( )

Runs scheduler event loop forever.

Definition at line 271 of file roo_scheduler.cpp.

References delay(), and executeEligibleTasks().

◆ scheduleAfter() [1/4]

ExecutionID roo_scheduler::Scheduler::scheduleAfter ( Executable task,
roo_time::Duration  delay,
Priority  priority = Priority::kNormal 
)
inline
Deprecated:
Use scheduleAfter(delay, task, priority).

Definition at line 161 of file roo_scheduler.h.

References delay(), and scheduleAfter().

◆ scheduleAfter() [2/4]

ExecutionID roo_scheduler::Scheduler::scheduleAfter ( roo_time::Duration  delay,
Executable task,
Priority  priority = Priority::kNormal 
)

Schedules execution after delay elapses.

Caller retains ownership and must keep task alive until execution or cancellation.

Definition at line 32 of file roo_scheduler.cpp.

References delay().

Referenced by roo_scheduler::RepetitiveTask::execute(), roo_scheduler::IteratingTask::execute(), scheduleAfter(), roo_scheduler::SingletonTask::scheduleAfter(), and roo_scheduler::RepetitiveTask::start().

◆ scheduleAfter() [3/4]

ExecutionID roo_scheduler::Scheduler::scheduleAfter ( roo_time::Duration  delay,
std::function< void()>  task,
Priority  priority = Priority::kNormal 
)

Schedules callable execution after delay elapses.

Definition at line 47 of file roo_scheduler.cpp.

References delay().

◆ scheduleAfter() [4/4]

ExecutionID roo_scheduler::Scheduler::scheduleAfter ( roo_time::Duration  delay,
std::unique_ptr< Executable task,
Priority  priority = Priority::kNormal 
)

Schedules execution after delay elapses.

Scheduler takes ownership of task and destroys it after execution or cancellation.

Definition at line 39 of file roo_scheduler.cpp.

References delay().

◆ scheduleNow() [1/3]

ExecutionID roo_scheduler::Scheduler::scheduleNow ( Executable task,
Priority  priority = Priority::kNormal 
)
inline

Schedules execution as soon as possible.

Caller retains ownership and must keep task alive until execution or cancellation.

Definition at line 171 of file roo_scheduler.h.

References scheduleOn().

Referenced by roo_scheduler::SingletonTask::scheduleNow().

◆ scheduleNow() [2/3]

ExecutionID roo_scheduler::Scheduler::scheduleNow ( std::function< void()>  task,
Priority  priority = Priority::kNormal 
)
inline

Schedules callable execution as soon as possible.

Definition at line 186 of file roo_scheduler.h.

References scheduleOn().

◆ scheduleNow() [3/3]

ExecutionID roo_scheduler::Scheduler::scheduleNow ( std::unique_ptr< Executable task,
Priority  priority = Priority::kNormal 
)
inline

Schedules execution as soon as possible.

Scheduler takes ownership of task and destroys it after execution or cancellation.

Definition at line 180 of file roo_scheduler.h.

References scheduleOn().

◆ scheduleOn() [1/4]

ExecutionID roo_scheduler::Scheduler::scheduleOn ( Executable task,
roo_time::Uptime  when,
Priority  priority = Priority::kNormal 
)
inline
Deprecated:
Use scheduleOn(when, task, priority).

Definition at line 133 of file roo_scheduler.h.

References scheduleOn().

◆ scheduleOn() [2/4]

ExecutionID roo_scheduler::Scheduler::scheduleOn ( roo_time::Uptime  when,
Executable task,
Priority  priority = Priority::kNormal 
)

Schedules execution no earlier than when.

Caller retains ownership and must keep task alive until execution or cancellation.

Definition at line 9 of file roo_scheduler.cpp.

Referenced by roo_scheduler::PeriodicTask::execute(), scheduleNow(), scheduleNow(), scheduleNow(), scheduleOn(), roo_scheduler::SingletonTask::scheduleOn(), roo_scheduler::PeriodicTask::start(), and roo_scheduler::IteratingTask::start().

◆ scheduleOn() [3/4]

ExecutionID roo_scheduler::Scheduler::scheduleOn ( roo_time::Uptime  when,
std::function< void()>  task,
Priority  priority = Priority::kNormal 
)

Schedules callable execution no earlier than when.

Definition at line 24 of file roo_scheduler.cpp.

◆ scheduleOn() [4/4]

ExecutionID roo_scheduler::Scheduler::scheduleOn ( roo_time::Uptime  when,
std::unique_ptr< Executable task,
Priority  priority = Priority::kNormal 
)

Schedules execution no earlier than when.

Scheduler takes ownership of task and destroys it after execution or cancellation.

Definition at line 16 of file roo_scheduler.cpp.


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