Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
Uses a single thread to periodically invoke callbacks at a given frequency. More...
#include <scheduler.h>
Public Types | |
using | eventid_t = uint64_t |
The type of event ids. | |
Public Member Functions | |
PeriodicScheduler (const std::optional< std::string > &name=std::nullopt) | |
Create a new PeriodicScheduler. | |
PeriodicScheduler (const PeriodicScheduler &)=delete | |
~PeriodicScheduler () | |
Join the thread and destruct. | |
PeriodicScheduler & | operator= (const PeriodicScheduler &)=delete |
void | clear () |
Clears all currently scheduled recurring events. | |
void | removeEvent (eventid_t id) |
Remove an event from the schedule. | |
eventid_t | scheduleEvent (std::chrono::milliseconds period, const std::function< void()> &fn) |
Schedule a new event to be executed periodically. | |
Friends | |
void | util::impl::notifyScheduler (PeriodicScheduler &) |
Uses a single thread to periodically invoke callbacks at a given frequency.
The underlying thread is initialized upon construction, so do not create PeriodicSchedulers that will not be used.
Clock | The clock to use for scheduling. |
|
inlineexplicit |
Create a new PeriodicScheduler.
name | The name of this scheduler, for logging purposes. |
|
inline |
Clears all currently scheduled recurring events.
This invalidates all previously returned event ids.
|
inline |
Remove an event from the schedule.
It is undefined behavior to remove events that are not scheduled, e.g. have already been removed.
id | The id of the event. |
|
inline |
Schedule a new event to be executed periodically.
The first execution will be scheduled to happen one period from now. It is undefined behavior to schedule more than 2^64 events.
period | The period in between executions of the event. |
fn | The function to call when the event is executed. This should not block. |