Initialize ngspice only once

This commit is contained in:
Maciej Suminski 2016-08-18 18:10:00 +02:00
parent ad3c2ac4ea
commit cac571c056
2 changed files with 13 additions and 8 deletions

View File

@ -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<NGSPICE*>( user );
sim->m_error = true;
//NGSPICE* sim = reinterpret_cast<NGSPICE*>( 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;

View File

@ -74,8 +74,6 @@ public:
std::vector<double> 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 */