new attempt: with thread-safery

This commit is contained in:
rusefi 2018-02-03 16:06:34 -05:00
parent 517ef4c011
commit 5c076ed215
4 changed files with 30 additions and 13 deletions

View File

@ -573,7 +573,7 @@ void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfig
COMPARE_CONFIG_PARAMS(bc.nb2ratioTo) || COMPARE_CONFIG_PARAMS(bc.nb2ratioTo) ||
COMPARE_CONFIG_PARAMS(nbVvtIndex); COMPARE_CONFIG_PARAMS(nbVvtIndex);
if (changed) { if (changed) {
// refreshTriggerShape(logger PASS_ENGINE_PARAMETER_SUFFIX); refreshTriggerShape(logger PASS_ENGINE_PARAMETER_SUFFIX);
} }
isTriggerConfigChanged = isTriggerConfigChanged || changed; isTriggerConfigChanged = isTriggerConfigChanged || changed;
} }
@ -582,11 +582,7 @@ void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfig
* @returns true if configuration just changed, and if that change has affected trigger * @returns true if configuration just changed, and if that change has affected trigger
*/ */
bool checkIfTriggerConfigChanged(void) { bool checkIfTriggerConfigChanged(void) {
#if EFI_PROD_CODE || EFI_SIMULATOR || defined(__DOXYGEN__)
return triggerVersion.isOld() && isTriggerConfigChanged; return triggerVersion.isOld() && isTriggerConfigChanged;
#else
return triggerVersion.isOld();
#endif /* EFI_PROD_CODE */
} }
void initTriggerCentral(Logging *sharedLogger) { void initTriggerCentral(Logging *sharedLogger) {

View File

@ -42,6 +42,7 @@
#include "trigger_central.h" #include "trigger_central.h"
#include "trigger_simulator.h" #include "trigger_simulator.h"
#include "trigger_universal.h" #include "trigger_universal.h"
#include "rfiutil.h"
#if EFI_SENSOR_CHART || defined(__DOXYGEN__) #if EFI_SENSOR_CHART || defined(__DOXYGEN__)
#include "sensor_chart.h" #include "sensor_chart.h"
@ -395,6 +396,11 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
*/ */
void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) { void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
const trigger_config_s *triggerConfig = &engineConfiguration->trigger; const trigger_config_s *triggerConfig = &engineConfiguration->trigger;
#if !EFI_UNIT_TEST
// we have a confusing threading model so some synchronization would not hurt
bool alreadyLocked = lockAnyContext();
#endif /* EFI_UNIT_TEST */
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "init t"); efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "init t");
scheduleMsg(logger, "initializeTriggerShape(%s/%d)", getTrigger_type_e(triggerConfig->type), (int) triggerConfig->type); scheduleMsg(logger, "initializeTriggerShape(%s/%d)", getTrigger_type_e(triggerConfig->type), (int) triggerConfig->type);
@ -565,8 +571,8 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET
default: default:
shapeDefinitionError = true; shapeDefinitionError = true;
warning(CUSTOM_ERR_NO_SHAPE, "initializeTriggerShape() not implemented: %d", triggerConfig->type); warning(CUSTOM_ERR_NO_SHAPE, "initializeTriggerShape() not implemented: %d", triggerConfig->type);
return;
} }
if (!shapeDefinitionError) {
wave.checkSwitchTimes(getSize()); wave.checkSwitchTimes(getSize());
/** /**
* this instance is used only to initialize 'this' TriggerShape instance * this instance is used only to initialize 'this' TriggerShape instance
@ -574,6 +580,14 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET
*/ */
initState.reset(); initState.reset();
calculateTriggerSynchPoint(&initState PASS_ENGINE_PARAMETER_SUFFIX); calculateTriggerSynchPoint(&initState PASS_ENGINE_PARAMETER_SUFFIX);
}
version++;
#if !EFI_UNIT_TEST
if (!alreadyLocked) {
unlockAnyContext();
}
#endif
} }
static void onFindIndex(TriggerState *state) { static void onFindIndex(TriggerState *state) {

View File

@ -39,6 +39,7 @@ trigger_shape_helper::trigger_shape_helper() {
TriggerShape::TriggerShape() : TriggerShape::TriggerShape() :
wave(switchTimesBuffer, NULL) { wave(switchTimesBuffer, NULL) {
version = 0;
initialize(OM_NONE, false); initialize(OM_NONE, false);
wave.waves = h.waves; wave.waves = h.waves;

View File

@ -59,6 +59,12 @@ public:
bool needSecondTriggerInput; bool needSecondTriggerInput;
bool shapeDefinitionError; bool shapeDefinitionError;
/**
* this variable is incremented after each trigger shape redefinition
* See also
*/
int version;
/** /**
* duty cycle for each individual trigger channel * duty cycle for each individual trigger channel
*/ */