Skyward boardcore
|
A task that executes a user-defined function at specific time points, or when signaled. More...
#include <SignaledDeadlineTask.h>
Public Types | |
using | Clock = std::chrono::system_clock |
using | TimePoint = std::chrono::time_point<Clock> |
Public Member Functions | |
SignaledDeadlineTask (unsigned int stackSize=miosix::STACK_DEFAULT_FOR_PTHREAD, miosix::Priority priority=miosix::MAIN_PRIORITY) | |
Constructor. | |
void | signalTask () |
Signals the task to run and go to sleep until the next deadline. | |
virtual TimePoint | nextTaskDeadline ()=0 |
Calculates the next deadline for the task to run. | |
virtual void | task ()=0 |
The user-defined task to run. | |
![]() | |
ActiveObject (unsigned int stacksize=miosix::STACK_DEFAULT_FOR_PTHREAD, miosix::Priority priority=miosix::MAIN_PRIORITY) | |
virtual | ~ActiveObject () |
virtual bool | start () |
Start the thread associated with this active object. | |
virtual void | stop () |
Signals the runner thread to terminate and joins the thread. | |
bool | isRunning () |
Protected Member Functions | |
void | run () override |
![]() | |
bool | shouldStop () |
Tells whether or not the ActiveObject should stop its execution. | |
Additional Inherited Members | |
![]() | |
miosix::Thread * | thread = nullptr |
Gives access to the thread object. | |
std::atomic< bool > | stopFlag {false} |
std::atomic< bool > | running {false} |
A task that executes a user-defined function at specific time points, or when signaled.
This class is designed to be used in situations where a task needs to be executed within specific deadlines, irregularly. The task will wake up at the specified time points and execute the user-defined function. The task can also be signaled to wake up and run immediately, regardless of the time points.
This class essentially emulates an EDF (Earliest Deadline First) scheduler on a single thread. If a high-enough priority value is used, the task will be scheduled as soon as the deadline is reached, this can be useful for hard real-time tasks.
Users must implement the following functions:
Definition at line 58 of file SignaledDeadlineTask.h.
using Boardcore::SignaledDeadlineTask::Clock = std::chrono::system_clock |
The current version of the STL (GCC 9.2.0) has a bug where condition_variable::wait_until is broken with clocks != system clock.
When absolute times big enough are used, the resulting time point will overflow, causing the condvar to return immediately.
TODO: Use steady_clock once we update to a newer Miosix version using a newer GCC version and therefore a newer STL.
Definition at line 71 of file SignaledDeadlineTask.h.
using Boardcore::SignaledDeadlineTask::TimePoint = std::chrono::time_point<Clock> |
Definition at line 72 of file SignaledDeadlineTask.h.
|
inline |
Constructor.
stackSize | The size of the stack for the thread. |
priority | The priority of the thread. |
Definition at line 80 of file SignaledDeadlineTask.h.
|
pure virtual |
Calculates the next deadline for the task to run.
|
inlineoverrideprotectedvirtual |
The thread that will be spawned just calls this function. Override it to implement your logic. Remember to frequently check for shouldStop() to see if you should terminate the execution of the thread.
Implements Boardcore::ActiveObject.
Definition at line 108 of file SignaledDeadlineTask.h.
|
inline |
Signals the task to run and go to sleep until the next deadline.
Definition at line 90 of file SignaledDeadlineTask.h.
|
pure virtual |
The user-defined task to run.