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;
}
std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
if( simulatorLock.owns_lock() )
{
m_simulator->LoadNetlist( formatter.GetString() );
updateTuners();
applyTuners();
m_simulator->Run();
}
else
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
}
@ -1807,14 +1814,22 @@ void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
StartSimulation();
}
else
{
std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
if( simulatorLock.owns_lock() )
{
// 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 "spice_settings.h"
#include <mutex>
#include <string>
#include <vector>
#include <complex>
@ -63,6 +64,14 @@ public:
*/
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.
*
@ -204,6 +213,10 @@ protected:
///< We don't own this. We are just borrowing it from the #SCHEMATIC_SETTINGS.
std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings;
private:
///< For interprocess synchronisation.
std::mutex m_mutex;
};
#endif /* SPICE_SIMULATOR_H */