mirror of https://github.com/FOME-Tech/fome-fw.git
auto-sync
This commit is contained in:
parent
eb8fea9bcd
commit
a2965453d8
|
@ -43,7 +43,8 @@ void Executor::unlock(void) {
|
||||||
unlockAnyContext();
|
unlockAnyContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Executor::schedule2(const char *prefix, scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param) {
|
void Executor::schedule2(const char *prefix, scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback,
|
||||||
|
void *param) {
|
||||||
// if (delayUs < 0) {
|
// if (delayUs < 0) {
|
||||||
// firmwareError("Negative delayUs %s: %d", prefix, delayUs);
|
// firmwareError("Negative delayUs %s: %d", prefix, delayUs);
|
||||||
// return;
|
// return;
|
||||||
|
@ -63,8 +64,8 @@ void Executor::schedule2(const char *prefix, scheduling_s *scheduling, uint64_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Executor::schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback,
|
||||||
void Executor::schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param) {
|
void *param) {
|
||||||
schedule2(prefix, scheduling, nowUs + delayUs, callback, param);
|
schedule2(prefix, scheduling, nowUs + delayUs, callback, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,15 +85,24 @@ void Executor::doExecute() {
|
||||||
* further invocations
|
* further invocations
|
||||||
*/
|
*/
|
||||||
reentrantLock = TRUE;
|
reentrantLock = TRUE;
|
||||||
|
bool shouldExecute = true;
|
||||||
|
/**
|
||||||
|
* in real life it could be that while we executing listeners time passes and it's already time to execute
|
||||||
|
* next listeners.
|
||||||
|
* TODO: add a counter & figure out a limit of iterations?
|
||||||
|
*/
|
||||||
|
while (shouldExecute) {
|
||||||
/**
|
/**
|
||||||
* It's worth noting that that the actions might be adding new actions into the queue
|
* It's worth noting that that the actions might be adding new actions into the queue
|
||||||
*/
|
*/
|
||||||
uint64_t nowUs = getTimeNowUs();
|
uint64_t nowUs = getTimeNowUs();
|
||||||
queue.executeAll(nowUs);
|
shouldExecute = queue.executeAll(nowUs);
|
||||||
|
}
|
||||||
if (!isLocked()) {
|
if (!isLocked()) {
|
||||||
firmwareError("Someone has stolen my lock");
|
firmwareError("Someone has stolen my lock");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
uint64_t nowUs = getTimeNowUs();
|
||||||
reentrantLock = false;
|
reentrantLock = false;
|
||||||
/**
|
/**
|
||||||
* 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value?
|
* 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value?
|
||||||
|
@ -124,7 +134,6 @@ void scheduleTask2(const char *prefix, scheduling_s *scheduling, uint64_t time,
|
||||||
instance.schedule2(prefix, scheduling, time, callback, param);
|
instance.schedule2(prefix, scheduling, time, callback, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initSignalExecutorImpl(void) {
|
void initSignalExecutorImpl(void) {
|
||||||
globalTimerCallback = executorCallback;
|
globalTimerCallback = executorCallback;
|
||||||
#if EFI_PROD_CODE
|
#if EFI_PROD_CODE
|
||||||
|
|
|
@ -61,7 +61,7 @@ uint64_t EventQueue::getNextEventTime(uint64_t nowUs) {
|
||||||
* looks like we end up here after 'writeconfig' (which freezes the firmware) - we are late
|
* looks like we end up here after 'writeconfig' (which freezes the firmware) - we are late
|
||||||
* for the next scheduled event
|
* for the next scheduled event
|
||||||
*/
|
*/
|
||||||
uint64_t mock = nowUs + MS2US(10);
|
uint64_t mock = nowUs + 100;
|
||||||
if (mock < result)
|
if (mock < result)
|
||||||
result = mock;
|
result = mock;
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,8 +74,9 @@ uint64_t EventQueue::getNextEventTime(uint64_t nowUs) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke all pending actions prior to specified timestamp
|
* Invoke all pending actions prior to specified timestamp
|
||||||
|
* @return true if at least one action was executed
|
||||||
*/
|
*/
|
||||||
void EventQueue::executeAll(uint64_t now) {
|
bool EventQueue::executeAll(uint64_t now) {
|
||||||
scheduling_s * current, *tmp;
|
scheduling_s * current, *tmp;
|
||||||
|
|
||||||
scheduling_s * executionList = NULL;
|
scheduling_s * executionList = NULL;
|
||||||
|
@ -87,7 +88,7 @@ void EventQueue::executeAll(uint64_t now) {
|
||||||
{
|
{
|
||||||
if (++counter > QUEUE_LENGTH_LIMIT) {
|
if (++counter > QUEUE_LENGTH_LIMIT) {
|
||||||
firmwareError("Is this list looped?");
|
firmwareError("Is this list looped?");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (current->momentUs <= now) {
|
if (current->momentUs <= now) {
|
||||||
LL_DELETE(head, current);
|
LL_DELETE(head, current);
|
||||||
|
@ -99,9 +100,13 @@ void EventQueue::executeAll(uint64_t now) {
|
||||||
* we need safe iteration here because 'callback' might change change 'current->next'
|
* we need safe iteration here because 'callback' might change change 'current->next'
|
||||||
* while re-inserting it into the queue from within the callback
|
* while re-inserting it into the queue from within the callback
|
||||||
*/
|
*/
|
||||||
|
bool result = (executionList != NULL);
|
||||||
LL_FOREACH_SAFE(executionList, current, tmp)
|
LL_FOREACH_SAFE(executionList, current, tmp)
|
||||||
|
{
|
||||||
current->callback(current->param);
|
current->callback(current->param);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int EventQueue::size(void) {
|
int EventQueue::size(void) {
|
||||||
scheduling_s *tmp;
|
scheduling_s *tmp;
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
|
|
||||||
void insertTask(scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param);
|
void insertTask(scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param);
|
||||||
|
|
||||||
void executeAll(uint64_t now);
|
bool executeAll(uint64_t now);
|
||||||
|
|
||||||
uint64_t getNextEventTime(uint64_t nowUs);
|
uint64_t getNextEventTime(uint64_t nowUs);
|
||||||
void clear(void);
|
void clear(void);
|
||||||
|
|
Loading…
Reference in New Issue