refactoring: ChibiOS now offers native 'lockAnyContext' pattern

This commit is contained in:
rusefi 2019-08-11 15:23:15 -04:00
parent 0625b91404
commit 9d32f2c40a
4 changed files with 20 additions and 16 deletions

View File

@ -179,7 +179,8 @@ efitimeus_t getTimeNowUs(void) {
//todo: macro to save method invocation //todo: macro to save method invocation
efitick_t getTimeNowNt(void) { efitick_t getTimeNowNt(void) {
#if EFI_PROD_CODE #if EFI_PROD_CODE
bool alreadyLocked = lockAnyContext(); /* Entering a reentrant critical zone.*/
syssts_t sts = chSysGetStatusAndLockX();
efitime_t localH = halTime.state.highBits; efitime_t localH = halTime.state.highBits;
uint32_t localLow = halTime.state.lowBits; uint32_t localLow = halTime.state.lowBits;
@ -192,9 +193,8 @@ efitick_t getTimeNowNt(void) {
efitime_t result = localH + value; efitime_t result = localH + value;
if (!alreadyLocked) { /* Leaving the critical zone.*/
unlockAnyContext(); chSysRestoreStatusX(sts);
}
return result; return result;
#else /* EFI_PROD_CODE */ #else /* EFI_PROD_CODE */
// todo: why is this implementation not used? // todo: why is this implementation not used?
@ -299,11 +299,11 @@ static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
/** /**
* We need to push current value into the 64 bit counter often enough so that we do not miss an overflow * We need to push current value into the 64 bit counter often enough so that we do not miss an overflow
*/ */
bool alreadyLocked = lockAnyContext(); /* Entering a reentrant critical zone.*/
syssts_t sts = chSysGetStatusAndLockX();
updateAndSet(&halTime.state, getTimeNowLowerNt()); updateAndSet(&halTime.state, getTimeNowLowerNt());
if (!alreadyLocked) { /* Leaving the critical zone.*/
unlockAnyContext(); chSysRestoreStatusX(sts);
}
int timeSeconds = getTimeNowSeconds(); int timeSeconds = getTimeNowSeconds();
if (previousSecond != timeSeconds) { if (previousSecond != timeSeconds) {
previousSecond = timeSeconds; previousSecond = timeSeconds;
@ -812,6 +812,6 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0) if (initBootloader() != 0)
return 123; return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */ #endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20190809; return 20190810;
} }
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */

View File

@ -263,7 +263,8 @@ static int tle8888_wake_driver(struct tle8888_priv *chip)
{ {
(void)chip; (void)chip;
int wasLocked = lockAnyContext(); /* Entering a reentrant critical zone.*/
syssts_t sts = chSysGetStatusAndLockX();
if (isIsrContext()) { if (isIsrContext()) {
// this is for normal runtime // this is for normal runtime
chSemSignalI(&tle8888_wake); chSemSignalI(&tle8888_wake);
@ -271,9 +272,8 @@ static int tle8888_wake_driver(struct tle8888_priv *chip)
// this is for start-up to not hang up // this is for start-up to not hang up
chSemSignalS(&tle8888_wake); chSemSignalS(&tle8888_wake);
} }
if (!wasLocked) { /* Leaving the critical zone.*/
unlockAnyContext(); chSysRestoreStatusX(sts);
}
return 0; return 0;
} }

View File

@ -1,12 +1,12 @@
// This file was generated by Version2Header // This file was generated by Version2Header
// Thu Aug 08 00:19:27 EDT 2019 // Sun Aug 11 15:18:31 EDT 2019
#ifndef GIT_HASH #ifndef GIT_HASH
#define GIT_HASH "51110b33ad6a0867421728746311e7a5019b5f11" #define GIT_HASH "0625b9140462581910d166e08180450e85b56476"
#endif #endif
#ifndef VCS_VERSION #ifndef VCS_VERSION
#define VCS_VERSION "19679" #define VCS_VERSION "19704"
#endif #endif

View File

@ -44,6 +44,7 @@ void chVTSetAny(virtual_timer_t *vtp, systime_t time, vtfunc_t vtfunc, void *par
/** /**
* @return TRUE if already in locked context * @return TRUE if already in locked context
* TODO: refactor to new 'syssts_t sts = chSysGetStatusAndLockX();' pattern
*/ */
bool lockAnyContext(void) { bool lockAnyContext(void) {
int alreadyLocked = isLocked(); int alreadyLocked = isLocked();
@ -63,6 +64,9 @@ bool lockAnyContext(void) {
return false; return false;
} }
/**
* TODO: refactor to new 'chSysRestoreStatusX(sts);' pattern
*/
void unlockAnyContext(void) { void unlockAnyContext(void) {
#if USE_PORT_LOCK #if USE_PORT_LOCK
port_unlock(); port_unlock();