The Big Refactoring of 2019: scheduler should not be global #655

This commit is contained in:
rusefi 2019-01-09 09:37:16 -05:00
parent 9f63ea4130
commit 5c1098c93b
7 changed files with 18 additions and 40 deletions

View File

@ -67,7 +67,14 @@ void SingleTimerExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs
}
/**
* @brief Schedule an event at specific delay after now
*
* Invokes event callback after the specified amount of time.
* callback would be executed either on ISR thread or current thread if we would need to execute right away
*
* @param [in, out] scheduling Data structure to keep this event in the collection.
* @param [in] delayUs the number of microseconds before the output signal immediate output if delay is zero.
* @param [in] dwell the number of ticks of output duration.
*/
void SingleTimerExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback,
void *param) {
@ -149,19 +156,6 @@ void SingleTimerExecutor::scheduleTimerCallback() {
hwSetTimerDuration = GET_TIMESTAMP() - beforeHwSetTimer;
}
/**
* @brief Schedule an event at specific delay after now
*
* Invokes event callback after the specified amount of time.
*
* @param [in, out] scheduling Data structure to keep this event in the collection.
* @param [in] delayUs the number of microseconds before the output signal immediate output if delay is zero.
* @param [in] dwell the number of ticks of output duration.
*/
void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
_engine.executor.scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
}
/**
* @brief Schedule an event at specified timestamp
*

View File

@ -226,9 +226,9 @@ static void timerCallback(PwmConfig *state) {
// if (state->executor == NULL) {
// firmwareError(CUSTOM_ERR_6695, "exec on %s", state->name);
// return;
// }
}
scheduleByTimestamp(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state);
state->executor->scheduleByTimestamp(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state);
state->dbgNestingLevel--;
}

View File

@ -26,15 +26,11 @@ public:
bool isScheduled;
};
class ExecutorInterface {
public:
/**
* see also scheduleByAngle
*/
// Deprecated see https://github.com/rusefi/rusefi/issues/655
void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
// Deprecated see https://github.com/rusefi/rusefi/issues/655
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param);
class ExecutorInterface {
virtual void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) = 0;
virtual void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) = 0;
};

View File

@ -34,10 +34,6 @@
#if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__)
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) {
scheduleForLater(scheduling, timeUs - getTimeNowUs(), callback, param);
}
void SleepExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) {
scheduleForLater(scheduling, timeUs - getTimeNowUs(), callback, param);
}
@ -56,7 +52,7 @@ static void timerCallback(scheduling_s *scheduling) {
}
void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
static void doScheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
int delaySt = MY_US2ST(delayUs);
if (delaySt <= 0) {
/**
@ -92,7 +88,7 @@ void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback,
}
void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
::scheduleForLater(scheduling, delayUs, callback, param);
doScheduleForLater(scheduling, delayUs, callback, param);
}
void initSignalExecutorImpl(void) {

View File

@ -375,12 +375,12 @@ void initRpmCalculator(Logging *sharedLogger, Engine *engine) {
* it takes the crankshaft to rotate to the specified angle.
*/
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle,
schfunc_t callback, void *param, RpmCalculator *calc) {
schfunc_t callback, void *param, RpmCalculator *calc DECLARE_ENGINE_PARAMETER_SUFFIX) {
efiAssertVoid(CUSTOM_ANGLE_NAN, !cisnan(angle), "NaN angle?");
efiAssertVoid(CUSTOM_ERR_6634, isValidRpm(rpm), "RPM check expected");
float delayUs = calc->oneDegreeUs * angle;
efiAssertVoid(CUSTOM_ERR_6635, !cisnan(delayUs), "NaN delay?");
scheduleForLater(timer, (int) delayUs, callback, param);
engine->executor.scheduleForLater(timer, (int) delayUs, callback, param);
}
#endif

View File

@ -182,6 +182,6 @@ int getRevolutionCounter(void);
#define addEngineSnifferEvent(n, msg) {}
#endif /* EFI_ENGINE_SNIFFER */
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param, RpmCalculator *calc);
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param, RpmCalculator *calc DECLARE_ENGINE_PARAMETER_SUFFIX);
#endif /* RPM_REPORTER_H_ */

View File

@ -14,14 +14,6 @@ EventQueue schedulingQueue;
bool_t debugSignalExecutor = false;
void scheduleForLater(scheduling_s *scheduling, int delayUs,
schfunc_t callback, void *param) {
if (debugSignalExecutor) {
printf("scheduleTask %d\r\n", delayUs);
}
scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
}
void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
if (debugSignalExecutor) {
printf("scheduleTask %d\r\n", delayUs);