eeschema: Add sync functions to SPICE_SIMULATOR

SPICE simulator can be called also during IBIS model determination,
and in the future in ERC. Therefore a necessity arises to implement
exclusive access.
This commit is contained in:
Sylwester Kocjan 2022-02-19 17:58:48 +01:00 committed by Mikolaj Wielgus
parent cf611f1742
commit 2fed8aa4b8
2 changed files with 37 additions and 9 deletions

View File

@ -476,10 +476,17 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand )
return; return;
} }
m_simulator->LoadNetlist( formatter.GetString() ); std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
updateTuners();
applyTuners(); if( simulatorLock.owns_lock() )
m_simulator->Run(); {
m_simulator->LoadNetlist( formatter.GetString() );
updateTuners();
applyTuners();
m_simulator->Run();
}
else
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
} }
@ -1808,12 +1815,20 @@ void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
} }
else else
{ {
// Incremental update std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
m_simConsole->Clear();
// Do not export netlist, it is already stored in the simulator if( simulatorLock.owns_lock() )
applyTuners(); {
m_simulator->Run(); // Incremental update
m_simConsole->Clear();
// Do not export netlist, it is already stored in the simulator
applyTuners();
m_simulator->Run();
}
else
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
} }
} }

View File

@ -30,6 +30,7 @@
#include "sim_types.h" #include "sim_types.h"
#include "spice_settings.h" #include "spice_settings.h"
#include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
#include <complex> #include <complex>
@ -63,6 +64,14 @@ public:
*/ */
virtual void Init( const SPICE_SIMULATOR_SETTINGS* aSettings = nullptr ) = 0; virtual void Init( const SPICE_SIMULATOR_SETTINGS* aSettings = nullptr ) = 0;
/*
* @return mutex for exclusive access to the simulator.
*/
std::mutex& GetMutex()
{
return m_mutex;
}
/** /**
* Load a netlist for the simulation. * Load a netlist for the simulation.
* *
@ -204,6 +213,10 @@ protected:
///< We don't own this. We are just borrowing it from the #SCHEMATIC_SETTINGS. ///< We don't own this. We are just borrowing it from the #SCHEMATIC_SETTINGS.
std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings; std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings;
private:
///< For interprocess synchronisation.
std::mutex m_mutex;
}; };
#endif /* SPICE_SIMULATOR_H */ #endif /* SPICE_SIMULATOR_H */