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

This commit is contained in:
rusefi 2019-01-09 01:07:50 -05:00
parent 8bfb0925e1
commit 7e7d8ef75c
3 changed files with 19 additions and 19 deletions

View File

@ -24,6 +24,7 @@
#include "SingleTimerExecutor.h"
#endif /* EFI_SIGNAL_EXECUTOR_ONE_TIMER */
#if EFI_SIGNAL_EXECUTOR_SLEEP
#include "signal_executor_sleep.h"
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
#if EFI_UNIT_TEST
#include "global_execution_queue.h"
@ -329,9 +330,10 @@ public:
// 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;
SingleTimerExecutor executor;
#endif
#if EFI_SIGNAL_EXECUTOR_SLEEP
SleepExecutor executor;
#endif
#if EFI_UNIT_TEST
TestExecutor executor;

View File

@ -26,7 +26,8 @@
#include "tunerstudio_configuration.h"
#include "rfiutil.h"
static Executor instance;
#include "engine.h"
EXTERN_ENGINE;
extern schfunc_t globalTimerCallback;
@ -49,10 +50,10 @@ static void executorCallback(void *arg) {
// timerIsLate++;
// }
instance.onTimerCallback();
_engine.executor.onTimerCallback();
}
Executor::Executor() {
SingleTimerExecutor::SingleTimerExecutor() {
reentrantFlag = false;
doExecuteCounter = scheduleCounter = timerCallbackCounter = 0;
/**
@ -64,7 +65,7 @@ Executor::Executor() {
/**
* callback would be executed either on ISR thread or current thread if we would need to execute right away
*/
void Executor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback,
void SingleTimerExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback,
void *param) {
scheduleCounter++;
bool alreadyLocked = true;
@ -83,7 +84,7 @@ void Executor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs,
}
}
void Executor::onTimerCallback() {
void SingleTimerExecutor::onTimerCallback() {
timerCallbackCounter++;
bool alreadyLocked = lockAnyContext();
doExecute();
@ -95,7 +96,7 @@ void Executor::onTimerCallback() {
/*
* this private method is executed under lock
*/
void Executor::doExecute() {
void SingleTimerExecutor::doExecute() {
doExecuteCounter++;
/**
* Let's execute actions we should execute at this point.
@ -129,7 +130,7 @@ void Executor::doExecute() {
/**
* This method is always invoked under a lock
*/
void Executor::scheduleTimerCallback() {
void SingleTimerExecutor::scheduleTimerCallback() {
/**
* Let's grab fresh time value
*/
@ -154,7 +155,7 @@ void Executor::scheduleTimerCallback() {
* @param [in] dwell the number of ticks of output duration.
*/
void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
instance.scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
_engine.executor.scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
}
/**
@ -163,7 +164,7 @@ void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback,
* @param [in] timeUs absolute time of the event, since ECU boot
*/
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) {
instance.scheduleByTimestamp(scheduling, time, callback, param);
_engine.executor.scheduleByTimestamp(scheduling, time, callback, param);
}
void initSignalExecutorImpl(void) {
@ -174,16 +175,13 @@ void initSignalExecutorImpl(void) {
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
extern TunerStudioOutputChannels tsOutputChannels;
#endif /* EFI_TUNER_STUDIO */
#include "engine.h"
EXTERN_ENGINE;
void executorStatistics() {
if (engineConfiguration->debugMode == DBG_EXECUTOR) {
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
tsOutputChannels.debugIntField1 = instance.timerCallbackCounter;
tsOutputChannels.debugIntField2 = instance.doExecuteCounter;
tsOutputChannels.debugIntField3 = instance.scheduleCounter;
#if (EFI_TUNER_STUDIO && EFI_SIGNAL_EXECUTOR_ONE_TIMER) || defined(__DOXYGEN__)
tsOutputChannels.debugIntField1 = _engine.executor.timerCallbackCounter;
tsOutputChannels.debugIntField2 = _engine.executor.doExecuteCounter;
tsOutputChannels.debugIntField3 = _engine.executor.scheduleCounter;
#endif /* EFI_TUNER_STUDIO */
}
}

View File

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