Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
An abstract class that can be overridden to run long-running tasks and encapsulate task-related data. More...
#include <scheduler.h>
Public Member Functions | |
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 | |
virtual void | task (std::unique_lock< std::mutex > &lock)=0 |
The long-running task, overridden by client code. | |
bool | isRunningInternal () |
Version of AsyncTask::isRunning() that does no synchronization. | |
bool | wait_until (std::unique_lock< std::mutex > &lock, const std::chrono::time_point< Clock > &tp) |
Wait until the specified time point, or until the task has been stopped. | |
template<typename Rep, typename Period> | |
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. | |
void | notify () override |
Not for use by client code. | |
Friends | |
void | util::impl::notifyScheduler (AsyncTask &) |
An abstract class that can be overridden to run long-running tasks and encapsulate task-related data.
Client code should use this class by deriving from it and overriding AsyncTask::task.
For simpler tasks that just require a function to be run periodically, consider PeriodicTask.
Clock | The clock to use for timing. |
|
inline |
Construct a new task.
name | The name of this task, for logging purposes. |
|
inline |
Check if the task is running.
|
inlineprotected |
Version of AsyncTask::isRunning() that does no synchronization.
This is useful if called from AsyncTask::task(), to prevent deadlocks.
|
inlineoverrideprotectedvirtual |
Not for use by client code.
Implements util::impl::Notifiable.
Reimplemented in util::PeriodicTask< Clock >.
|
inlinevirtual |
Start the task.
If the task is already running, do nothing.
Reimplemented in net::mc::tasks::PowerRepeatTask.
|
inlinevirtual |
Stop the task and wait for it to finish.
If the task is not running, do nothing.
Reimplemented in net::mc::tasks::PowerRepeatTask.
|
protectedpure virtual |
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. |
Implemented in net::mc::tasks::CameraStreamTask, and util::PeriodicTask< Clock >.
|
inlineprotected |
Wait for a given duration, or until the task has been stopped.
lock | The lock passed to AsyncTask::task. |
tp | The duration of time to wait for. |
|
inlineprotected |
Wait until the specified time point, or until the task has been stopped.
lock | The lock passed to AsyncTask::task. |
tp | The time point to wait until. |
|
inlineprotected |
Wait until the task has been stopped.
lock | The lock passed to AsyncTask::task. |