The Big Refactoring of 2019: scheduler should not be global #655
This commit is contained in:
parent
2f01f8759c
commit
dbac37c59d
|
@ -24,6 +24,7 @@
|
||||||
#include "SingleTimerExecutor.h"
|
#include "SingleTimerExecutor.h"
|
||||||
#endif /* EFI_SIGNAL_EXECUTOR_ONE_TIMER */
|
#endif /* EFI_SIGNAL_EXECUTOR_ONE_TIMER */
|
||||||
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
||||||
|
#include "signal_executor_sleep.h"
|
||||||
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
|
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
|
||||||
#if EFI_UNIT_TEST
|
#if EFI_UNIT_TEST
|
||||||
#include "global_execution_queue.h"
|
#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
|
// 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
|
// cost to resolve pointer, we use instances as a micro optimization
|
||||||
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
|
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
|
||||||
Executor executor;
|
SingleTimerExecutor executor;
|
||||||
#endif
|
#endif
|
||||||
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
||||||
|
SleepExecutor executor;
|
||||||
#endif
|
#endif
|
||||||
#if EFI_UNIT_TEST
|
#if EFI_UNIT_TEST
|
||||||
TestExecutor executor;
|
TestExecutor executor;
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#include "tunerstudio_configuration.h"
|
#include "tunerstudio_configuration.h"
|
||||||
#include "rfiutil.h"
|
#include "rfiutil.h"
|
||||||
|
|
||||||
static Executor instance;
|
#include "engine.h"
|
||||||
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
extern schfunc_t globalTimerCallback;
|
extern schfunc_t globalTimerCallback;
|
||||||
|
|
||||||
|
@ -49,10 +50,10 @@ static void executorCallback(void *arg) {
|
||||||
// timerIsLate++;
|
// timerIsLate++;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
instance.onTimerCallback();
|
_engine.executor.onTimerCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
Executor::Executor() {
|
SingleTimerExecutor::SingleTimerExecutor() {
|
||||||
reentrantFlag = false;
|
reentrantFlag = false;
|
||||||
doExecuteCounter = scheduleCounter = timerCallbackCounter = 0;
|
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
|
* 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) {
|
void *param) {
|
||||||
scheduleCounter++;
|
scheduleCounter++;
|
||||||
bool alreadyLocked = true;
|
bool alreadyLocked = true;
|
||||||
|
@ -83,7 +84,7 @@ void Executor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Executor::onTimerCallback() {
|
void SingleTimerExecutor::onTimerCallback() {
|
||||||
timerCallbackCounter++;
|
timerCallbackCounter++;
|
||||||
bool alreadyLocked = lockAnyContext();
|
bool alreadyLocked = lockAnyContext();
|
||||||
doExecute();
|
doExecute();
|
||||||
|
@ -95,7 +96,7 @@ void Executor::onTimerCallback() {
|
||||||
/*
|
/*
|
||||||
* this private method is executed under lock
|
* this private method is executed under lock
|
||||||
*/
|
*/
|
||||||
void Executor::doExecute() {
|
void SingleTimerExecutor::doExecute() {
|
||||||
doExecuteCounter++;
|
doExecuteCounter++;
|
||||||
/**
|
/**
|
||||||
* Let's execute actions we should execute at this point.
|
* 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
|
* This method is always invoked under a lock
|
||||||
*/
|
*/
|
||||||
void Executor::scheduleTimerCallback() {
|
void SingleTimerExecutor::scheduleTimerCallback() {
|
||||||
/**
|
/**
|
||||||
* Let's grab fresh time value
|
* Let's grab fresh time value
|
||||||
*/
|
*/
|
||||||
|
@ -154,7 +155,7 @@ void Executor::scheduleTimerCallback() {
|
||||||
* @param [in] dwell the number of ticks of output duration.
|
* @param [in] dwell the number of ticks of output duration.
|
||||||
*/
|
*/
|
||||||
void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
|
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
|
* @param [in] timeUs absolute time of the event, since ECU boot
|
||||||
*/
|
*/
|
||||||
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) {
|
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) {
|
void initSignalExecutorImpl(void) {
|
||||||
|
@ -174,16 +175,13 @@ void initSignalExecutorImpl(void) {
|
||||||
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
||||||
extern TunerStudioOutputChannels tsOutputChannels;
|
extern TunerStudioOutputChannels tsOutputChannels;
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
#include "engine.h"
|
|
||||||
EXTERN_ENGINE;
|
|
||||||
|
|
||||||
|
|
||||||
void executorStatistics() {
|
void executorStatistics() {
|
||||||
if (engineConfiguration->debugMode == DBG_EXECUTOR) {
|
if (engineConfiguration->debugMode == DBG_EXECUTOR) {
|
||||||
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
#if (EFI_TUNER_STUDIO && EFI_SIGNAL_EXECUTOR_ONE_TIMER) || defined(__DOXYGEN__)
|
||||||
tsOutputChannels.debugIntField1 = instance.timerCallbackCounter;
|
tsOutputChannels.debugIntField1 = _engine.executor.timerCallbackCounter;
|
||||||
tsOutputChannels.debugIntField2 = instance.doExecuteCounter;
|
tsOutputChannels.debugIntField2 = _engine.executor.doExecuteCounter;
|
||||||
tsOutputChannels.debugIntField3 = instance.scheduleCounter;
|
tsOutputChannels.debugIntField3 = _engine.executor.scheduleCounter;
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "event_queue.h"
|
#include "event_queue.h"
|
||||||
|
|
||||||
class Executor : public ExecutorInterface {
|
class SingleTimerExecutor : public ExecutorInterface {
|
||||||
public:
|
public:
|
||||||
Executor();
|
SingleTimerExecutor();
|
||||||
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param);
|
void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param);
|
||||||
void onTimerCallback();
|
void onTimerCallback();
|
||||||
int timerCallbackCounter;
|
int timerCallbackCounter;
|
||||||
|
|
Loading…
Reference in New Issue