|
roo_scheduler
API Documentation for roo_scheduler
|
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. | |
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.
| roo_scheduler::Scheduler::Scheduler | ( | ) |
Creates an empty scheduler.
Definition at line 7 of file roo_scheduler.cpp.
| void roo_scheduler::Scheduler::cancel | ( | ExecutionID | id | ) |
Marks execution identified by id as canceled.
Canceled entries may remain in queue until pruned, but will not run.
Definition at line 212 of file roo_scheduler.cpp.
Referenced by roo_scheduler::SingletonTask::scheduleAfter(), roo_scheduler::SingletonTask::scheduleNow(), roo_scheduler::SingletonTask::scheduleOn(), roo_scheduler::RepetitiveTask::start(), roo_scheduler::PeriodicTask::start(), roo_scheduler::IteratingTask::~IteratingTask(), roo_scheduler::PeriodicTask::~PeriodicTask(), roo_scheduler::RepetitiveTask::~RepetitiveTask(), and roo_scheduler::SingletonTask::~SingletonTask().
| 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().
| 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().
|
inline |
Returns true iff no pending (non-canceled) executions exist.
Definition at line 240 of file roo_scheduler.h.
|
inline |
Executes up to max_count eligible tasks.
Definition at line 219 of file roo_scheduler.h.
References executeEligibleTasks(), and roo_scheduler::kMinimum.
| bool roo_scheduler::Scheduler::executeEligibleTasks | ( | Priority | min_priority, |
| int | max_count = -1 |
||
| ) |
Executes up to max_count eligible tasks with at least min_priority.
Definition at line 93 of file roo_scheduler.cpp.
Referenced by delayUntil(), executeEligibleTasks(), and run().
| 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).
Definition at line 85 of file roo_scheduler.cpp.
Referenced by delayUntil(), and executeEligibleTasksUpToNow().
|
inline |
Executes up to max_count eligible tasks due no later than now.
Tasks below min_priority are ignored (not executed).
Definition at line 196 of file roo_scheduler.h.
References executeEligibleTasksUpTo().
| roo_time::Duration roo_scheduler::Scheduler::getNearestExecutionDelay | ( | ) | const |
Returns delay to the nearest upcoming execution.
Definition at line 118 of file roo_scheduler.cpp.
| 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.
| 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.
| void roo_scheduler::Scheduler::run | ( | ) |
Runs scheduler event loop forever.
Definition at line 271 of file roo_scheduler.cpp.
References delay(), and executeEligibleTasks().
|
inline |
scheduleAfter(delay, task, priority). Definition at line 161 of file roo_scheduler.h.
References delay(), and scheduleAfter().
| 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().
| 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().
| 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().
|
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().
|
inline |
Schedules callable execution as soon as possible.
Definition at line 186 of file roo_scheduler.h.
References scheduleOn().
|
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().
|
inline |
scheduleOn(when, task, priority). Definition at line 133 of file roo_scheduler.h.
References scheduleOn().
| 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().
| 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.
| 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.