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(nbVvtIndex);
if (changed) {
// refreshTriggerShape(logger PASS_ENGINE_PARAMETER_SUFFIX);
refreshTriggerShape(logger PASS_ENGINE_PARAMETER_SUFFIX);
}
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
*/
bool checkIfTriggerConfigChanged(void) {
#if EFI_PROD_CODE || EFI_SIMULATOR || defined(__DOXYGEN__)
return triggerVersion.isOld() && isTriggerConfigChanged;
#else
return triggerVersion.isOld();
#endif /* EFI_PROD_CODE */
}
void initTriggerCentral(Logging *sharedLogger) {

View File

@ -42,6 +42,7 @@
#include "trigger_central.h"
#include "trigger_simulator.h"
#include "trigger_universal.h"
#include "rfiutil.h"
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
#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) {
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__)
efiAssertVoid(getRemainingStack(chThdGetSelfX()) > 256, "init t");
scheduleMsg(logger, "initializeTriggerShape(%s/%d)", getTrigger_type_e(triggerConfig->type), (int) triggerConfig->type);
@ -565,15 +571,23 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET
default:
shapeDefinitionError = true;
warning(CUSTOM_ERR_NO_SHAPE, "initializeTriggerShape() not implemented: %d", triggerConfig->type);
return;
}
wave.checkSwitchTimes(getSize());
/**
* this instance is used only to initialize 'this' TriggerShape instance
* #192 BUG real hardware trigger events could be coming even while we are initializing trigger
*/
initState.reset();
calculateTriggerSynchPoint(&initState PASS_ENGINE_PARAMETER_SUFFIX);
if (!shapeDefinitionError) {
wave.checkSwitchTimes(getSize());
/**
* this instance is used only to initialize 'this' TriggerShape instance
* #192 BUG real hardware trigger events could be coming even while we are initializing trigger
*/
initState.reset();
calculateTriggerSynchPoint(&initState PASS_ENGINE_PARAMETER_SUFFIX);
}
version++;
#if !EFI_UNIT_TEST
if (!alreadyLocked) {
unlockAnyContext();
}
#endif
}
static void onFindIndex(TriggerState *state) {

View File

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

View File

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