From cac571c0569e0d8b4a01d44336c42302d2e26c5c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 18 Aug 2016 18:10:00 +0200 Subject: [PATCH] Initialize ngspice only once --- eeschema/sim/ngspice.cpp | 16 ++++++++++------ eeschema/sim/ngspice.h | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index f122f144f7..5e69af85fe 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -45,9 +45,7 @@ NGSPICE::~NGSPICE() void NGSPICE::Init() { - if( m_error ) - init(); - + init(); Command( "reset" ); } @@ -270,13 +268,16 @@ string NGSPICE::GetXAxis( SIM_TYPE aType ) const void NGSPICE::init() { - m_error = false; + if( m_initialized ) + return; LOCALE_IO c_locale; // ngspice works correctly only with C locale ngSpice_Init( &cbSendChar, &cbSendStat, &cbControlledExit, NULL, NULL, &cbBGThreadRunning, this ); // Workaround to avoid hang ups on certain errors Command( "unset interactive" ); + + m_initialized = true; } @@ -323,9 +324,12 @@ int NGSPICE::cbBGThreadRunning( bool is_running, int id, void* user ) int NGSPICE::cbControlledExit( int status, bool immediate, bool exit_upon_quit, int id, void* user ) { // Something went wrong, reload the dll - NGSPICE* sim = reinterpret_cast( user ); - sim->m_error = true; + //NGSPICE* sim = reinterpret_cast( user ); + //sim->m_initialized = false; //printf("stat %d immed %d quit %d\n", status, !!immediate, !!exit_upon_quit); return 0; } + + +bool NGSPICE::m_initialized = false; diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index c62fab6947..fdba05ded9 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -74,8 +74,6 @@ public: std::vector GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) override; private: - bool m_error; - void init(); // Callback functions @@ -85,6 +83,9 @@ private: static int cbControlledExit( int status, bool immediate, bool exit_upon_quit, int id, void* user ); void dump(); + + ///> NGspice should be initialized only once + static bool m_initialized; }; #endif /* NGSPICE_H */