sharedspice.c: improved comments

This commit is contained in:
h_vogt 2013-04-12 23:59:27 +02:00
parent d58e204cda
commit e95632f3f0
1 changed files with 29 additions and 27 deletions

View File

@ -17,8 +17,10 @@
#endif #endif
/* The Delphi Interface has high latency times during printing, /* If a calling function has high latency times during printing,
therefore undef the following line */ causing memory access errors, you may undef the following line.
Printing messages are assembled in a wordlist, and sent to the caller
via a new thread. Delays may occur. */
#define low_latency #define low_latency
/**********************************************************************/ /**********************************************************************/
@ -304,6 +306,7 @@ static bool ps_exited = TRUE;
#define EXPORT_FLAVOR #define EXPORT_FLAVOR
#endif #endif
/* starts a background thread, e.g. from command bg_run */
static void * EXPORT_FLAVOR static void * EXPORT_FLAVOR
_thread_run(void *string) _thread_run(void *string)
{ {
@ -329,7 +332,7 @@ _thread_run(void *string)
} }
/*Stops a running thread, hopefully */ /*Stops a running background thread, hopefully */
static int EXPORT_FLAVOR static int EXPORT_FLAVOR
_thread_stop(void) _thread_stop(void)
{ {
@ -379,7 +382,7 @@ sighandler_sharedspice(int num)
#endif /*THREADS*/ #endif /*THREADS*/
/* run a ngspice command */
static int static int
runc(char* command) runc(char* command)
{ {
@ -487,7 +490,7 @@ runc(char* command)
#ifdef THREADS #ifdef THREADS
/* Checks if spice is running in the background */ /* Checks if ngspice is running in the background */
IMPEXP IMPEXP
bool bool
ngSpice_running (void) ngSpice_running (void)
@ -497,7 +500,7 @@ ngSpice_running (void)
#endif #endif
/* Initialise spice and setup native methods */ /* Initialise ngspice and setup native methods */
IMPEXP IMPEXP
int int
ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexit, ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexit,
@ -681,7 +684,6 @@ IMPEXP
int ngSpice_Command(char* comexec) int ngSpice_Command(char* comexec)
{ {
if ( ! setjmp(errbufc) ) { if ( ! setjmp(errbufc) ) {
// HANDLE tid2;
immediate = FALSE; immediate = FALSE;
intermj = 1; intermj = 1;
@ -690,12 +692,9 @@ int ngSpice_Command(char* comexec)
fprintf(stderr, no_init); fprintf(stderr, no_init);
return 1; return 1;
} }
// tid2 = (HANDLE)_beginthreadex(NULL, 0, (PTHREAD_START_ROUTINE)runc, (void*)comexec,
// 0, NULL);
runc(comexec); runc(comexec);
/* main thread prepares immediate detaching of dll, /* main thread prepares immediate detaching of dll */
in case of controlled_exit from tid2 thread, caller is asked
to detach dll via fcn ngexit() */
immediate = TRUE; immediate = TRUE;
return 0; return 0;
} }
@ -832,8 +831,8 @@ char** ngSpice_AllVecs(char* plotname)
/* Redefine the vfprintf() functions for callback */ /* Redefine the vfprintf() functions for callback */
/*------------------------------------------------------*/ /*------------------------------------------------------*/
/* handling of escape characters (extra \ added) is removed, may be added by /* handling of escape characters (extra \ added) only, if
un-commenting some lines */ 'set addescape' is given in .spiceinit */
int int
sh_vfprintf(FILE *f, const char *fmt, va_list args) sh_vfprintf(FILE *f, const char *fmt, va_list args)
@ -912,7 +911,7 @@ sh_vfprintf(FILE *f, const char *fmt, va_list args)
} }
} }
/* use sharedspice implementation of fputs (sh_fputs) /* use sharedspice.c implementation of fputs (sh_fputs)
to assess callback function derived from address printfcn received via to assess callback function derived from address printfcn received via
Spice_Init() from caller of ngspice.dll */ Spice_Init() from caller of ngspice.dll */
@ -926,9 +925,10 @@ sh_vfprintf(FILE *f, const char *fmt, va_list args)
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------
/* Reimplement fprintf() as a call to callback function pfcn */ Reimplement fprintf() as a call to callback function pfcn
/*----------------------------------------------------------------------*/ via sh_vfprintf, sh_fputs, and sh_fputsll
----------------------------------------------------------------------*/
int int
sh_fprintf(FILE *f, const char *format, ...) sh_fprintf(FILE *f, const char *format, ...)
@ -944,9 +944,10 @@ sh_fprintf(FILE *f, const char *format, ...)
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------
/* Reimplement printf() as a call to callback function pfcn */ Reimplement printf() as a call to callback function pfcn
/*----------------------------------------------------------------------*/ via sh_vfprintf, sh_fputs, and sh_fputsll
----------------------------------------------------------------------*/
int int
sh_printf(const char *format, ...) sh_printf(const char *format, ...)
@ -999,8 +1000,8 @@ static char* outstringerr = NULL;
static char* outstringout = NULL; static char* outstringout = NULL;
#if defined (low_latency) || !defined(THREADS) #if defined (low_latency) || !defined(THREADS)
/* using the strings by the caller sent directly to the caller /* The strings issued by printf etc. are sent directly to the caller.
has to fast enough (low latency) */ The callback has to be fast enough (low latency). */
int int
sh_fputsll(const char *input, FILE* outf) sh_fputsll(const char *input, FILE* outf)
{ {
@ -1088,7 +1089,8 @@ sh_fputsll(const char *input, FILE* outf)
return 0; return 0;
} }
/* provide a lock around printing function */ /* provide a lock around printing function.
May become critical if latency of callback is too high.*/
int int
sh_fputs(const char *input, FILE* outf) sh_fputs(const char *input, FILE* outf)
{ {
@ -1278,7 +1280,7 @@ char* outstorage(char* wordin, bool write)
/* New progress report to statfcn(). /* New progress report to statfcn().
Update only every DELTATIME milliseconds */ An update occurs only every DELTATIME milliseconds. */
#define DELTATIME 150 #define DELTATIME 150
void SetAnalyse( void SetAnalyse(
char * Analyse, /*in: analysis type */ char * Analyse, /*in: analysis type */
@ -1350,8 +1352,8 @@ void SetAnalyse(
tfree(s); tfree(s);
} }
/* a dll or shared library should never exit, but ask for graceful shutdown /* a dll or shared library should never exit, if loaded dynamically,
(e.g. being detached) via a callback function*/ but ask for graceful shutdown (e.g. being detached) via a callback function*/
void shared_exit(int status) void shared_exit(int status)
{ {
/* alert caller to detach dll (if we are in the main thread), /* alert caller to detach dll (if we are in the main thread),