A priority queue for scheduling periodic callbacks based on their next execution time.
More...
#include <wpi/internal/PeriodicPriorityQueue.hpp>
|
| void | Add (std::function< void()> func, std::chrono::microseconds startTime, std::chrono::microseconds period) |
| | Adds a periodic callback to the queue.
|
| void | Add (std::function< void()> func, std::chrono::microseconds startTime, std::chrono::microseconds period, std::chrono::microseconds offset) |
| | Adds a periodic callback to the queue.
|
| void | Add (std::function< void()> func, std::chrono::microseconds startTime, wpi::units::second_t period) |
| | Adds a periodic callback to the queue.
|
| void | Add (std::function< void()> func, std::chrono::microseconds startTime, wpi::units::second_t period, wpi::units::second_t offset) |
| | Adds a periodic callback to the queue.
|
| void | Add (Callback callback) |
| | Adds a pre-constructed callback to the queue.
|
| bool | Remove (const Callback &callback) |
| | Removes a specific callback from the queue.
|
| void | Clear () |
| | Removes all callbacks from the queue.
|
| bool | RunCallbacks (HAL_NotifierHandle notifier) |
| | Executes all callbacks that are due, then waits for the next callback's scheduled time.
|
| wpi::util::priority_queue< Callback, std::vector< Callback >, std::greater<> > & | GetQueue () |
| | Returns the underlying priority queue.
|
| wpi::units::microsecond_t | GetLoopStartTime () const |
| | Return the system clock time in microseconds for the start of the current periodic loop.
|
A priority queue for scheduling periodic callbacks based on their next execution time.
This class manages a collection of periodic callbacks that execute at specified intervals. Callbacks are scheduled using FPGA timestamps and automatically rescheduled after execution to maintain their periodic behavior. The queue uses a priority heap to efficiently determine the next callback to execute.
This is an internal scheduling primitive used by robot frameworks like TimedRobot.
◆ Add() [1/5]
| void wpi::internal::PeriodicPriorityQueue::Add |
( |
Callback | callback | ) |
|
Adds a pre-constructed callback to the queue.
- Parameters
-
| callback | The callback to add. |
◆ Add() [2/5]
| void wpi::internal::PeriodicPriorityQueue::Add |
( |
std::function< void()> | func, |
|
|
std::chrono::microseconds | startTime, |
|
|
std::chrono::microseconds | period ) |
Adds a periodic callback to the queue.
- Parameters
-
| func | The callback to run. |
| startTime | The common starting point for all callback scheduling. |
| period | The period at which to run the callback. |
◆ Add() [3/5]
| void wpi::internal::PeriodicPriorityQueue::Add |
( |
std::function< void()> | func, |
|
|
std::chrono::microseconds | startTime, |
|
|
std::chrono::microseconds | period, |
|
|
std::chrono::microseconds | offset ) |
Adds a periodic callback to the queue.
- Parameters
-
| func | The callback to run. |
| startTime | The common starting point for all callback scheduling. |
| period | The period at which to run the callback. |
| offset | The offset from the common starting time. |
◆ Add() [4/5]
| void wpi::internal::PeriodicPriorityQueue::Add |
( |
std::function< void()> | func, |
|
|
std::chrono::microseconds | startTime, |
|
|
wpi::units::second_t | period ) |
Adds a periodic callback to the queue.
- Parameters
-
| func | The callback to run. |
| startTime | The common starting point for all callback scheduling in FPGA timestamp microseconds. |
| period | The period at which to run the callback. |
◆ Add() [5/5]
| void wpi::internal::PeriodicPriorityQueue::Add |
( |
std::function< void()> | func, |
|
|
std::chrono::microseconds | startTime, |
|
|
wpi::units::second_t | period, |
|
|
wpi::units::second_t | offset ) |
Adds a periodic callback to the queue.
- Parameters
-
| func | The callback to run. |
| startTime | The common starting point for all callback scheduling in FPGA timestamp microseconds. |
| period | The period at which to run the callback. |
| offset | The offset from the common starting time. |
◆ Clear()
| void wpi::internal::PeriodicPriorityQueue::Clear |
( |
| ) |
|
Removes all callbacks from the queue.
◆ GetLoopStartTime()
| wpi::units::microsecond_t wpi::internal::PeriodicPriorityQueue::GetLoopStartTime |
( |
| ) |
const |
|
inline |
Return the system clock time in microseconds for the start of the current periodic loop.
This is in the same time base as Timer.getMonotonicTimeStamp(), but is stable through a loop. It is updated at the beginning of every periodic callback (including the normal periodic loop).
- Returns
- Robot running time in microseconds, as of the start of the current periodic function.
◆ GetQueue()
Returns the underlying priority queue.
◆ Remove()
| bool wpi::internal::PeriodicPriorityQueue::Remove |
( |
const Callback & | callback | ) |
|
Removes a specific callback from the queue.
- Parameters
-
| callback | The callback to remove. |
- Returns
- true if the callback was found and removed, false otherwise.
◆ RunCallbacks()
Executes all callbacks that are due, then waits for the next callback's scheduled time.
This method performs the following steps:
- Retrieves the callback with the earliest expiration time from the queue
- Sets a hardware notifier alarm to wait until that callback's expiration time
- Blocks until the notifier signals or is interrupted
- Executes the callback and reschedules it for its next period
- Processes any additional callbacks that have become due during execution
When rescheduling callbacks, this method automatically compensates for execution delays by advancing the expiration time by the number of full periods that have elapsed, ensuring callbacks maintain their scheduled phase over time.
- Parameters
-
| notifier | The HAL notifier handle to use for timing. |
- Returns
- false if the notifier was destroyed (loop should exit), true otherwise.
The documentation for this class was generated from the following file: