Browse Source

sharedspice.c: preliminary fixes: ftime() usage, prevent crash if controlled_exit from worker thread

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

29
src/sharedspice.c

@ -135,11 +135,9 @@ typedef pthread_t threadId_t;
#include <frontend/com_measure2.h> #include <frontend/com_measure2.h>
#include <frontend/misccoms.h> #include <frontend/misccoms.h>
#ifndef HAVE_GETRUSAGE
#ifdef HAVE_FTIME #ifdef HAVE_FTIME
#include <sys/timeb.h> #include <sys/timeb.h>
#endif #endif
#endif
/* To interupt a spice run */ /* To interupt a spice run */
#include <signal.h> #include <signal.h>
@ -1266,6 +1264,7 @@ void SetAnalyse(
int DecaPercent /*in: 10 times the progress [%]*/ int DecaPercent /*in: 10 times the progress [%]*/
/*HWND hwAnalyse, in: global handle to analysis window */ /*HWND hwAnalyse, in: global handle to analysis window */
) { ) {
#ifdef HAVE_FTIME
static int OldPercent = -2; /* Previous progress value */ static int OldPercent = -2; /* Previous progress value */
static char OldAn[128]; /* Previous analysis type */ static char OldAn[128]; /* Previous analysis type */
char* s; /* outputs to callback function */ char* s; /* outputs to callback function */
@ -1329,6 +1328,17 @@ void SetAnalyse(
result = statfcn(s, userptr); result = statfcn(s, userptr);
} }
tfree(s); tfree(s);
#else
char* s;
int result;
static bool havesent = FALSE;
if (!havesent) {
s = copy("No usage info available");
result = statfcn(s, userptr);
tfree(s);
havesent = TRUE;
}
#endif
} }
/* a dll or shared library should never exit, if loaded dynamically, /* a dll or shared library should never exit, if loaded dynamically,
@ -1372,8 +1382,23 @@ void shared_exit(int status)
tfree(outsend); tfree(outsend);
} }
#endif #endif
// if we are in a worker thread, we exit it here
// detaching then has to be done explicitely by the caller
if (fl_running && !fl_exited) {
fl_exited = TRUE;
bgtr(fl_exited, userptr);
// set a flag that ngspice wants to be detached
ngexit(status, FALSE, coquit, userptr);
// finish and exit the worker thread
#ifdef HAVE_LIBPTHREAD
pthread_exit(1);
#elif defined _MSC_VER || defined __MINGW32__
_endthreadex(1);
#endif
}
// set a flag in caller to detach ngspice.dll // set a flag in caller to detach ngspice.dll
ngexit(status, immediate, coquit, userptr); ngexit(status, immediate, coquit, userptr);
// jump back to finish the calling function // jump back to finish the calling function
if (!intermj) if (!intermj)
longjmp(errbufm,1); /* jump back to ngSpice_Circ() */ longjmp(errbufm,1); /* jump back to ngSpice_Circ() */

Loading…
Cancel
Save