add cancel to scheduler (#3201)

* fw

* for tests

* simulator

* sim

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-08-27 01:30:06 -07:00 committed by GitHub
parent 6c7b48b319
commit 0c6297e926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 0 deletions

View File

@ -67,4 +67,5 @@ struct ExecutorInterface {
virtual void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) = 0;
virtual void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action) = 0;
virtual void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) = 0;
virtual void cancel(scheduling_s* scheduling) = 0;
};

View File

@ -91,4 +91,12 @@ void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, acti
doScheduleForLater(scheduling, delayUs, action);
}
void SleepExecutor::cancel(scheduling_s* s) {
if (chVTIsArmedI(&s->timer)) {
chVTResetI(&s->timer);
}
s->action = {};
}
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */

View File

@ -14,4 +14,5 @@ public:
void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override;
void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action) override;
void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override;
void cancel(scheduling_s* s) override;
};

View File

@ -90,6 +90,13 @@ void SingleTimerExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* s
}
}
void SingleTimerExecutor::cancel(scheduling_s* scheduling) {
// Lock for queue removal - we may already be locked, but that's ok
chibios_rt::CriticalSectionLocker csl;
queue.remove(scheduling);
}
void SingleTimerExecutor::onTimerCallback() {
timerCallbackCounter++;

View File

@ -16,6 +16,8 @@ public:
void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override;
void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitime_t timeNt, action_s action) override;
void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override;
void cancel(scheduling_s* scheduling) override;
void onTimerCallback();
int timerCallbackCounter = 0;
int scheduleCounter = 0;

View File

@ -70,6 +70,15 @@ void TestExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* scheduli
scheduleByTimestamp("test", scheduling, NT2US(timeNt), action);
}
void TestExecutor::cancel(scheduling_s* s) {
if (m_mockExecutor) {
m_mockExecutor->cancel(s);
return;
}
schedulingQueue.remove(s);
}
void TestExecutor::setMockExecutor(ExecutorInterface* exec) {
m_mockExecutor = exec;
}

View File

@ -17,6 +17,8 @@ public:
void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override;
void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action) override;
void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override;
void cancel(scheduling_s* scheduling) override;
void clear();
int executeAll(efitime_t now);
int size();

View File

@ -58,6 +58,7 @@ public:
MOCK_METHOD(void, scheduleByTimestamp, (const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action), (override));
MOCK_METHOD(void, scheduleByTimestampNt, (const char *msg, scheduling_s *scheduling, efitime_t timeUs, action_s action), (override));
MOCK_METHOD(void, scheduleForLater, (scheduling_s *scheduling, int delayUs, action_s action), (override));
MOCK_METHOD(void, cancel, (scheduling_s*), (override));
};
class MockAirmass : public AirmassVeModelBase {