Fix lockAnyContext

This commit is contained in:
Andrei 2017-05-25 21:51:21 +03:00
parent b2203e22cb
commit f1096c91f3
3 changed files with 15 additions and 10 deletions

View File

@ -99,7 +99,7 @@ static void startAveraging(void *arg) {
mapMeasurementsCounter = 0; mapMeasurementsCounter = 0;
isAveraging = true; isAveraging = true;
if (!wasLocked) if (!wasLocked)
chSysUnlockFromISR() unlockAnyContext();
; ;
mapAveragingPin.setHigh(); mapAveragingPin.setHigh();
} }
@ -144,13 +144,14 @@ void mapAveragingCallback(adcsample_t adcValue) {
readIndex = writeIndex; readIndex = writeIndex;
// todo: migrate to the lock-free implementation // todo: migrate to the lock-free implementation
chSysLockFromISR() bool alreadyLocked = lockAnyContext();
; ;
// with locking we would have a consistent state // with locking we would have a consistent state
mapAccumulator += adcValue; mapAccumulator += adcValue;
mapMeasurementsCounter++; mapMeasurementsCounter++;
chSysUnlockFromISR() if (!alreadyLocked)
unlockAnyContext();
; ;
} }
#endif #endif
@ -165,7 +166,7 @@ static void endAveraging(void *arg) {
mapAccumulator / mapMeasurementsCounter); mapAccumulator / mapMeasurementsCounter);
#endif #endif
if (!wasLocked) if (!wasLocked)
chSysUnlockFromISR() unlockAnyContext();
; ;
mapAveragingPin.setLow(); mapAveragingPin.setLow();
} }

View File

@ -68,9 +68,10 @@ void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schf
// callback(param); // callback(param);
// return; // return;
// } // }
bool alreadyLocked = true;
if (!reentrantFlag) { if (!reentrantFlag) {
// this would guard the queue and disable interrupts // this would guard the queue and disable interrupts
lockAnyContext(); alreadyLocked = lockAnyContext();
} }
bool needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), callback, param); bool needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), callback, param);
if (!reentrantFlag) { if (!reentrantFlag) {
@ -78,15 +79,17 @@ void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schf
if (needToResetTimer) { if (needToResetTimer) {
scheduleTimerCallback(); scheduleTimerCallback();
} }
unlockAnyContext(); if (!alreadyLocked)
unlockAnyContext();
} }
} }
void Executor::onTimerCallback() { void Executor::onTimerCallback() {
lockAnyContext(); bool alreadyLocked = lockAnyContext();
doExecute(); doExecute();
scheduleTimerCallback(); scheduleTimerCallback();
unlockAnyContext(); if (!alreadyLocked)
unlockAnyContext();
} }
/* /*

View File

@ -62,7 +62,7 @@ void scheduleTask(scheduling_s *scheduling, int delayUs, schfunc_t callback, voi
return; return;
} }
lockAnyContext(); bool alreadyLocked = lockAnyContext();
scheduling->callback = callback; scheduling->callback = callback;
scheduling->param = param; scheduling->param = param;
int isArmed = chVTIsArmedI(&scheduling->timer); int isArmed = chVTIsArmedI(&scheduling->timer);
@ -82,7 +82,8 @@ void scheduleTask(scheduling_s *scheduling, int delayUs, schfunc_t callback, voi
#endif /* EFI_SIMULATOR */ #endif /* EFI_SIMULATOR */
chVTSetI(&scheduling->timer, delaySt, (vtfunc_t)timerCallback, scheduling); chVTSetI(&scheduling->timer, delaySt, (vtfunc_t)timerCallback, scheduling);
unlockAnyContext(); if (!alreadyLocked)
unlockAnyContext();
} }
void initSignalExecutorImpl(void) { void initSignalExecutorImpl(void) {