mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Notifier: simplify ack API (#8457)
Adding an ack parameter to both set and cancel is cleaner than adding all the set alarm parameters to the ack function. It also provides an ack-and-cancel method.
This commit is contained in:
@@ -39,10 +39,6 @@ class NotifierThread : public wpi::util::SafeThread {
|
||||
public:
|
||||
void Main() override;
|
||||
|
||||
void SetAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::shared_ptr<Notifier>& notifier, uint64_t alarmTime,
|
||||
uint64_t intervalTime, bool absolute, int32_t* status);
|
||||
|
||||
void ProcessAlarms();
|
||||
|
||||
UnlimitedHandleResource<HAL_NotifierHandle, Notifier,
|
||||
@@ -101,30 +97,6 @@ void NotifierThread::Main() {
|
||||
}
|
||||
}
|
||||
|
||||
void NotifierThread::SetAlarm(HAL_NotifierHandle notifierHandle,
|
||||
std::shared_ptr<Notifier>& notifier,
|
||||
uint64_t alarmTime, uint64_t intervalTime,
|
||||
bool absolute, int32_t* status) {
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
if (!m_alarmQueue.empty()) {
|
||||
prevWakeup = m_alarmQueue.top().notifier->alarmTime;
|
||||
m_alarmQueue.remove({notifierHandle, notifier});
|
||||
}
|
||||
notifier->alarmTime = alarmTime;
|
||||
notifier->intervalTime = intervalTime;
|
||||
notifier->overrunCount = 0;
|
||||
m_alarmQueue.push({notifierHandle, notifier});
|
||||
|
||||
// wake up notifier thread if needed
|
||||
if (alarmTime < prevWakeup) {
|
||||
m_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifierThread::ProcessAlarms() {
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
@@ -204,17 +176,38 @@ void HAL_DestroyNotifier(HAL_NotifierHandle notifierHandle) {
|
||||
|
||||
void HAL_SetNotifierAlarm(HAL_NotifierHandle notifierHandle, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status) {
|
||||
HAL_Bool ack, int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
if (!notifier) {
|
||||
return;
|
||||
}
|
||||
thr->SetAlarm(notifierHandle, notifier, alarmTime, intervalTime, absolute,
|
||||
status);
|
||||
|
||||
if (ack) {
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
if (!absolute) {
|
||||
alarmTime += HAL_GetFPGATime(status);
|
||||
}
|
||||
|
||||
uint64_t prevWakeup = UINT64_MAX;
|
||||
if (!thr->m_alarmQueue.empty()) {
|
||||
prevWakeup = thr->m_alarmQueue.top().notifier->alarmTime;
|
||||
thr->m_alarmQueue.remove({notifierHandle, notifier});
|
||||
}
|
||||
notifier->alarmTime = alarmTime;
|
||||
notifier->intervalTime = intervalTime;
|
||||
notifier->overrunCount = 0;
|
||||
thr->m_alarmQueue.push({notifierHandle, notifier});
|
||||
|
||||
// wake up notifier thread if needed
|
||||
if (alarmTime < prevWakeup) {
|
||||
thr->m_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle, HAL_Bool ack,
|
||||
int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
@@ -222,14 +215,15 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
return;
|
||||
}
|
||||
|
||||
if (ack) {
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
thr->m_alarmQueue.remove({notifierHandle, notifier});
|
||||
notifier->alarmTime = UINT64_MAX;
|
||||
notifier->handlerSignaled.clear();
|
||||
}
|
||||
|
||||
void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
HAL_Bool setAlarm, uint64_t alarmTime,
|
||||
uint64_t intervalTime, HAL_Bool absolute,
|
||||
int32_t* status) {
|
||||
auto thr = notifierInstance->owner.GetThread();
|
||||
auto notifier = thr->m_handles.Get(notifierHandle);
|
||||
@@ -237,10 +231,6 @@ void HAL_AcknowledgeNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
return;
|
||||
}
|
||||
notifier->handlerSignaled.clear();
|
||||
if (setAlarm) {
|
||||
thr->SetAlarm(notifierHandle, notifier, alarmTime, intervalTime, absolute,
|
||||
status);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t HAL_GetNotifierOverrun(HAL_NotifierHandle notifierHandle,
|
||||
|
||||
Reference in New Issue
Block a user