mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
HAL: Add support for multiple Notifiers.
This is a poor man's version of the multi-instance Notifier support in the higher level languages. It's intended primarily so that notifiers can be created internal to the HAL. One benefit of this change is that the current FPGA timestamp is passed as the first parameter to the ProcessQueue function (rather than the useless interrupt mask). Caution for other languages wrapping the HAL: this adds a parameter to initializeNotifier(). An atexit hook is used for safe cleanup at program termination. Change-Id: I782b3a74c10215588ae9b7191906fb4186a81028
This commit is contained in:
@@ -15,7 +15,7 @@ Notifier *Notifier::timerQueueHead = nullptr;
|
||||
priority_recursive_mutex Notifier::queueMutex;
|
||||
priority_mutex Notifier::halMutex;
|
||||
void *Notifier::m_notifier = nullptr;
|
||||
std::atomic<int> Notifier::refcount{0};
|
||||
std::atomic<int> Notifier::refcount = ATOMIC_VAR_INIT(0);
|
||||
|
||||
/**
|
||||
* Create a Notifier for timer event notification.
|
||||
@@ -33,7 +33,7 @@ Notifier::Notifier(TimerEventHandler handler, void *param) {
|
||||
{
|
||||
std::lock_guard<priority_mutex> sync(halMutex);
|
||||
if (!m_notifier)
|
||||
m_notifier = initializeNotifier(ProcessQueue, &status);
|
||||
m_notifier = initializeNotifier(ProcessQueue, nullptr, &status);
|
||||
}
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
@@ -105,13 +105,13 @@ void Notifier::UpdateAlarm() {
|
||||
* as its scheduled time is after the current time. Then the item is removed or
|
||||
* rescheduled (repetitive events) in the queue.
|
||||
*/
|
||||
void Notifier::ProcessQueue(uint32_t mask, void *params) {
|
||||
void Notifier::ProcessQueue(uint32_t currentTimeInt, void *params) {
|
||||
Notifier *current;
|
||||
while (true) // keep processing past events until no more
|
||||
{
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
double currentTime = GetClock();
|
||||
double currentTime = currentTimeInt * 1.0e-6;
|
||||
current = timerQueueHead;
|
||||
if (current == nullptr || current->m_expirationTime > currentTime) {
|
||||
break; // no more timer events to process
|
||||
|
||||
Reference in New Issue
Block a user