Browse Source

sharedspice.c: improved comments

pre-master-46
h_vogt 13 years ago
committed by rlar
parent
commit
b54605c225
  1. 55
      src/sharedspice.c

55
src/sharedspice.c

@ -16,8 +16,10 @@
#define STDERR_FILENO 2 #define STDERR_FILENO 2
#endif #endif
/* The Delphi Interface has high latency times during printing,
therefore undef the following line */
/* If a calling function has high latency times during printing,
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
/**********************************************************************/ /**********************************************************************/
@ -280,6 +282,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)
{ {
@ -305,7 +308,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)
{ {
@ -356,6 +359,7 @@ sighandler_sharedspice(int num)
#endif /*THREADS*/ #endif /*THREADS*/
/* run a ngspice command */
static int static int
runc(char* command) runc(char* command)
{ {
@ -463,7 +467,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)
@ -473,7 +477,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,
@ -656,7 +660,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;
@ -665,12 +668,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,
in case of controlled_exit from tid2 thread, caller is asked
to detach dll via fcn ngexit() */
/* main thread prepares immediate detaching of dll */
immediate = TRUE; immediate = TRUE;
return 0; return 0;
} }
@ -807,8 +807,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
un-commenting some lines */
/* handling of escape characters (extra \ added) only, if
'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)
@ -887,7 +887,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 */
@ -901,9 +901,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, ...)
@ -919,9 +920,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, ...)
@ -975,8 +977,8 @@ 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
has to fast enough (low latency) */
/* The strings issued by printf etc. are sent directly to the caller.
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)
{ {
@ -1064,7 +1066,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)
{ {
@ -1254,7 +1257,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 */
@ -1326,8 +1329,8 @@ void SetAnalyse(
tfree(s); tfree(s);
} }
/* a dll or shared library should never exit, but ask for graceful shutdown
(e.g. being detached) via a callback function*/
/* a dll or shared library should never exit, if loaded dynamically,
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),

Loading…
Cancel
Save