Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
util::PeriodicTask< Clock > Class Template Reference

Implements a task that executes a function periodically. More...

#include <scheduler.h>

Inheritance diagram for util::PeriodicTask< Clock >:
Collaboration diagram for util::PeriodicTask< Clock >:

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
 
AsyncTaskoperator= (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 &)
 

Detailed Description

template<typename Clock = std::chrono::steady_clock>
class util::PeriodicTask< Clock >

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.

Template Parameters
ClockThe clock to use for timing.

Constructor & Destructor Documentation

◆ PeriodicTask()

template<typename Clock = std::chrono::steady_clock>
util::PeriodicTask< Clock >::PeriodicTask ( const std::chrono::milliseconds & period,
const std::function< void()> & f )
inline

Construct a new periodic task.

Parameters
periodThe period at which to run the task.
fThe function to execute every period.

Member Function Documentation

◆ notify()

template<typename Clock = std::chrono::steady_clock>
void util::PeriodicTask< Clock >::notify ( )
inlineoverrideprotectedvirtual

Not for use by client code.

Reimplemented from util::AsyncTask< std::chrono::steady_clock >.

◆ task()

template<typename Clock = std::chrono::steady_clock>
void util::PeriodicTask< Clock >::task ( std::unique_lock< std::mutex > & lock)
inlineoverrideprotectedvirtual

The long-running task, overridden by client code.

If a task wants to stop itself, it can just return.

Parameters
lockThe 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 >.


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