Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
Implements a task that executes a function periodically. More...
#include <scheduler.h>
Public Member Functions | |
PeriodicTask (const std::chrono::milliseconds &period, const std::function< void()> &f) | |
Construct a new periodic task. | |
Public Member Functions inherited from util::AsyncTask< std::chrono::steady_clock > | |
AsyncTask (const std::optional< std::string > &name=std::nullopt) | |
Construct a new task. | |
AsyncTask (const AsyncTask &)=delete | |
AsyncTask & | operator= (const AsyncTask &)=delete |
virtual void | start () |
Start the task. | |
virtual void | stop () |
Stop the task and wait for it to finish. | |
bool | isRunning () |
Check if the task is running. | |
Protected Member Functions | |
void | task (std::unique_lock< std::mutex > &lock) override |
The long-running task, overridden by client code. | |
void | notify () override |
Not for use by client code. | |
Protected Member Functions inherited from util::AsyncTask< std::chrono::steady_clock > | |
bool | isRunningInternal () |
Version of AsyncTask::isRunning() that does no synchronization. | |
bool | wait_until (std::unique_lock< std::mutex > &lock, const std::chrono::time_point< std::chrono::steady_clock > &tp) |
Wait until the specified time point, or until the task has been stopped. | |
bool | wait_for (std::unique_lock< std::mutex > &lock, const std::chrono::duration< Rep, Period > &dur) |
Wait for a given duration, or until the task has been stopped. | |
void | wait_until_done (std::unique_lock< std::mutex > &lock) |
Wait until the task has been stopped. | |
Friends | |
void | util::impl::notifyScheduler (PeriodicTask &) |
Implements a task that executes a function periodically.
Note that all PeriodicTask instances are run on the same thread, so the task function should not block.
Clock | The clock to use for timing. |
|
inline |
Construct a new periodic task.
period | The period at which to run the task. |
f | The function to execute every period. |
|
inlineoverrideprotectedvirtual |
Not for use by client code.
Reimplemented from util::AsyncTask< std::chrono::steady_clock >.
|
inlineoverrideprotectedvirtual |
The long-running task, overridden by client code.
If a task wants to stop itself, it can just return.
lock | The lock on the private internal state of the AsyncTask. Client code should generally not use this except for the wait_until_xxx methods. |
Implements util::AsyncTask< std::chrono::steady_clock >.