sharedspice.c: thread handling updated
This commit is contained in:
parent
1509cfd9ee
commit
58c9911f27
|
|
@ -16,6 +16,8 @@
|
||||||
#define STDERR_FILENO 2
|
#define STDERR_FILENO 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//#define low_latency
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Header files for C functions */
|
/* Header files for C functions */
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
@ -203,7 +205,7 @@ void wl_delete_first(wordlist **wlstart, wordlist **wlend);
|
||||||
|
|
||||||
#if !defined(low_latency)
|
#if !defined(low_latency)
|
||||||
static char* outstorage(char*, bool);
|
static char* outstorage(char*, bool);
|
||||||
static void* printsend(void);
|
static void printsend(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ngspice/sharedspice.h"
|
#include "ngspice/sharedspice.h"
|
||||||
|
|
@ -335,7 +337,7 @@ _thread_stop(void)
|
||||||
ft_intrpt = TRUE;
|
ft_intrpt = TRUE;
|
||||||
timeout++;
|
timeout++;
|
||||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||||
Sleep(50); // va: windows native
|
Sleep(100); // va: windows native
|
||||||
#else
|
#else
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -960,7 +962,8 @@ static char* outstringerr = NULL;
|
||||||
static char* outstringout = NULL;
|
static char* outstringout = NULL;
|
||||||
|
|
||||||
#ifdef low_latency
|
#ifdef low_latency
|
||||||
|
/* using the strings by the caller sent directly to the caller
|
||||||
|
has to fast enough (low latency) */
|
||||||
int
|
int
|
||||||
sh_fputsll(const char *input, FILE* outf)
|
sh_fputsll(const char *input, FILE* outf)
|
||||||
{
|
{
|
||||||
|
|
@ -990,10 +993,7 @@ sh_fputsll(const char *input, FILE* outf)
|
||||||
strcat(prstring, "stderr ");
|
strcat(prstring, "stderr ");
|
||||||
strcat(prstring, newstring);
|
strcat(prstring, newstring);
|
||||||
|
|
||||||
printtid = (HANDLE)_beginthreadex(NULL, 0, (unsigned int (__stdcall *)(void *))printing,
|
result = pfcn(prstring, userptr);
|
||||||
(void*)prstring, 0, NULL);
|
|
||||||
|
|
||||||
// result = pfcn(prstring, userptr);
|
|
||||||
tfree(newstring);
|
tfree(newstring);
|
||||||
tfree(prstring);
|
tfree(prstring);
|
||||||
}
|
}
|
||||||
|
|
@ -1051,7 +1051,7 @@ sh_fputsll(const char *input, FILE* outf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allow a lock around printing function */
|
/* provide a lock around printing function */
|
||||||
int
|
int
|
||||||
sh_fputs(const char *input, FILE* outf)
|
sh_fputs(const char *input, FILE* outf)
|
||||||
{
|
{
|
||||||
|
|
@ -1070,7 +1070,7 @@ sh_fputs(const char *input, FILE* outf)
|
||||||
again fcn outstoraghe(), top entry is deleted and string is
|
again fcn outstoraghe(), top entry is deleted and string is
|
||||||
sent to caller in an endless loop by fcn printsend() */
|
sent to caller in an endless loop by fcn printsend() */
|
||||||
static wordlist *wlstart = NULL, *wlend = NULL;
|
static wordlist *wlstart = NULL, *wlend = NULL;
|
||||||
|
static bool printstopp = FALSE;
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -1167,18 +1167,25 @@ sh_fputs(const char *input, FILE* outf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Endless lop in its own thread for reading data from FIFO and sending to caller */
|
static char *outsend = NULL;
|
||||||
static void *
|
|
||||||
|
/* Endless loop in its own thread for reading data from FIFO and sending to caller */
|
||||||
|
static void
|
||||||
printsend(void)
|
printsend(void)
|
||||||
{
|
{
|
||||||
char *outsend = NULL;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||||
Sleep(100);
|
Sleep(50); // loop delay
|
||||||
#else
|
#else
|
||||||
usleep(100000);
|
usleep(50000);
|
||||||
#endif
|
#endif
|
||||||
|
if (printstopp) {// issued by shared_exit()
|
||||||
|
// catch the final error message
|
||||||
|
mutex_lock(&fputsMutex);
|
||||||
|
outsend = outstorage(NULL, FALSE);
|
||||||
|
mutex_unlock(&fputsMutex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
mutex_lock(&fputsMutex);
|
mutex_lock(&fputsMutex);
|
||||||
outsend = outstorage(NULL, FALSE);
|
outsend = outstorage(NULL, FALSE);
|
||||||
mutex_unlock(&fputsMutex);
|
mutex_unlock(&fputsMutex);
|
||||||
|
|
@ -1326,7 +1333,26 @@ void shared_exit(int status)
|
||||||
coquit = FALSE;
|
coquit = FALSE;
|
||||||
fprintf(stderr, "Error: ngspice.dll cannot recover and awaits to be detached\n");
|
fprintf(stderr, "Error: ngspice.dll cannot recover and awaits to be detached\n");
|
||||||
}
|
}
|
||||||
|
#ifndef low_latency
|
||||||
|
// set flag to stop the printsend thread
|
||||||
|
printstopp = TRUE;
|
||||||
|
// leave this thread for 100ms to stop the printsend thread
|
||||||
|
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||||
|
Sleep(100);
|
||||||
|
#else
|
||||||
|
usleep(100000);
|
||||||
|
#endif
|
||||||
|
// send the final error message already caught in printsend()
|
||||||
|
if (outsend) {
|
||||||
|
/* requires outsend to be copied by the caller,
|
||||||
|
because it is freed immediately */
|
||||||
|
pfcn(outsend, userptr);
|
||||||
|
tfree(outsend);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// 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
|
||||||
if (!intermj)
|
if (!intermj)
|
||||||
longjmp(errbufm,1); /* jump back to ngSpice_Circ() */
|
longjmp(errbufm,1); /* jump back to ngSpice_Circ() */
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue