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

This commit is contained in:
rusefi 2019-01-09 00:53:54 -05:00
parent ba1e1f3275
commit 2f01f8759c
8 changed files with 70 additions and 7 deletions

View File

@ -2,7 +2,7 @@
* @file engine.h
*
* @date May 21, 2014
* @author Andrey Belomutskiy, (c) 2012-2017
* @author Andrey Belomutskiy, (c) 2012-2019
*/
#ifndef H_ENGINE_H_
#define H_ENGINE_H_
@ -19,6 +19,16 @@
#include "accel_enrichment.h"
#include "trigger_central.h"
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
// PROD real firmware uses this implementation
#include "SingleTimerExecutor.h"
#endif /* EFI_SIGNAL_EXECUTOR_ONE_TIMER */
#if EFI_SIGNAL_EXECUTOR_SLEEP
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
#if EFI_UNIT_TEST
#include "global_execution_queue.h"
#endif /* EFI_UNIT_TEST */
#define MOCK_ADC_SIZE 16
class MockAdcState {
@ -316,6 +326,16 @@ public:
InjectionSignalPair fuelActuators[INJECTION_PIN_COUNT];
IgnitionEventList ignitionEvents;
// a pointer with interface type would make this code nicer but would carry extra runtime
// cost to resolve pointer, we use instances as a micro optimization
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
Executor executor;
#endif
#if EFI_SIGNAL_EXECUTOR_SLEEP
#endif
#if EFI_UNIT_TEST
TestExecutor executor;
#endif
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
FuelSchedule injectionEvents;

View File

@ -11,7 +11,7 @@
#include "scheduler.h"
#include "event_queue.h"
class Executor {
class Executor : public ExecutorInterface {
public:
Executor();
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param);

View File

@ -29,7 +29,13 @@ 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;
};
#endif /* SCHEDULER_H_ */

View File

@ -34,8 +34,12 @@
#if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__)
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) {
scheduleForLater(scheduling, time - getTimeNowUs(), callback, param);
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);
}
static void timerCallback(scheduling_s *scheduling) {

View File

@ -8,4 +8,11 @@
#ifndef SIGNAL_EXECUTOR_SLEEP_H_
#define SIGNAL_EXECUTOR_SLEEP_H_
#include "scheduler.h"
class SleepExecutor : public ExecutorInterface {
public:
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param);
};
#endif /* SIGNAL_EXECUTOR_SLEEP_H_ */

View File

@ -198,7 +198,7 @@ void seTurnPinLow(InjectionSignalPair *pair) {
ENGINE(injectionEvents.addFuelEventsForCylinder(pair->event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX));
}
static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionSignalPair *pair) {
static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionSignalPair *pair DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
InjectorOutputPin *param = pair->outputs[0];
// scheduleMsg(&sharedLogger, "schX %s %x %d", prefix, scheduling, time);
@ -341,10 +341,10 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
printf("please cancel %s %d %d\r\n", output->name, (int)getTimeNowUs(), output->overlappingCounter);
#endif /* EFI_UNIT_TEST || EFI_SIMULATOR */
} else {
sescheduleByTimestamp(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, pair);
sescheduleByTimestamp(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, pair PASS_ENGINE_PARAMETER_SUFFIX);
}
efitimeus_t turnOffTime = nowUs + (int) (injectionStartDelayUs + durationUs);
sescheduleByTimestamp(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, pair);
sescheduleByTimestamp(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, pair PASS_ENGINE_PARAMETER_SUFFIX);
}
}

View File

@ -7,6 +7,7 @@
#include "signal_executor.h"
#include "event_queue.h"
#include "global_execution_queue.h"
// this global instance is used by integration tests via 'scheduleByTimestamp' global methods below
EventQueue schedulingQueue;
@ -21,6 +22,13 @@ void scheduleForLater(scheduling_s *scheduling, int delayUs,
scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
}
void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) {
if (debugSignalExecutor) {
printf("scheduleByTime %d\r\n", time);
}
schedulingQueue.insertTask(scheduling, time, callback, param);
}
void scheduleByTimestamp(scheduling_s *scheduling,
efitimeus_t time, schfunc_t callback, void *param) {
if (debugSignalExecutor) {

View File

@ -0,0 +1,18 @@
/*
* global_execution_queue.h
*
* Created on: Jan 9, 2019
* @author Andrey Belomutskiy, (c) 2012-2019
*/
#ifndef GLOBAL_EXECUTION_QUEUE_H_
#define GLOBAL_EXECUTION_QUEUE_H_
#include "scheduler.h"
class TestExecutor : public ExecutorInterface {
public:
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param);
};
#endif /* GLOBAL_EXECUTION_QUEUE_H_ */