From 5c388d85cf71eae66160caac113168a48114ae59 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Mon, 1 Apr 2013 16:08:31 +0200 Subject: [PATCH] sharedspice.c: update stopping printsend thread --- src/sharedspice.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/sharedspice.c b/src/sharedspice.c index 941db8386..e95c8ec96 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -244,7 +244,6 @@ mutexType fputsMutex; static bool is_initialized = FALSE; static char* no_init = "Error: ngspice is not initialized!\n Run ngSpice_Init first"; -static bool printstopp = FALSE; /*helper function*//* static struct plot * @@ -293,6 +292,9 @@ static threadId_t tid, printtid, bgtid = (threadId_t) 0; static bool fl_running = FALSE; static bool fl_exited = TRUE; +static bool printstopp = FALSE; +static bool ps_exited = TRUE; + #if defined(__MINGW32__) || defined(_MSC_VER) #define EXPORT_FLAVOR WINAPI #else @@ -381,6 +383,7 @@ runc(char* command) char buf[1024] = ""; sighandler oldHandler; #ifdef THREADS + int timeout = 0; char *string; bool fl_bg = FALSE; command_id = threadid_self(); @@ -392,12 +395,26 @@ runc(char* command) #ifndef low_latency /* stop the printf thread 'printsend()' */ else if (cieq("bg_pstop", command)) { - printstopp = TRUE; + while (!ps_exited && timeout < 100) { + printstopp = TRUE; + #if defined(__MINGW32__) || defined(_MSC_VER) - Sleep(100); // va: windows native + Sleep(100); // va: windows native #else - usleep(10000); + usleep(10000); #endif + timeout++; + } + if (!ps_exited) { + fprintf(stderr, "Error: Couldn't stop printsend thread\n"); + return EXIT_BAD; + } + else + fprintf(stdout, "Printsend thread stopped with timeout = %d\n", timeout); +#ifdef HAVE_LIBPTHREAD + pthread_join(printtid, NULL); +#endif + printstopp = FALSE; return 2; } #endif @@ -408,7 +425,7 @@ runc(char* command) #endif /* Catch Ctrl-C to break simulations */ -#if !defined(_MSC_VER) /*&& !defined(__MINGW32__) */ +#if 1 //!defined(_MSC_VER) /*&& !defined(__MINGW32__) */ oldHandler = signal(SIGINT, (SIGNAL_FUNCTION) ft_sigintr); if (SETJMP(jbuf, 1) != 0) { signal(SIGINT, oldHandler); @@ -627,7 +644,14 @@ bot: } #endif - com_version(NULL); +// com_version(NULL); + fprintf(cp_out, + "******\n" + "** %s-%s\n", + ft_sim->simulator, ft_sim->version); + if (Spice_Build_Date != NULL && *Spice_Build_Date != 0) + fprintf(cp_out, "** Creation Date: %s\n", Spice_Build_Date); + fprintf(cp_out, "******\n"); is_initialized = TRUE; @@ -722,6 +746,7 @@ int ngSpice_Circ(char** circa){ if ( ! setjmp(errbufm) ) { intermj = 0; + immediate = FALSE; /* count the entries */ while (circa[entries]) { entries++; @@ -1187,6 +1212,8 @@ static char *outsend = NULL; static void printsend(void) { + ps_exited = FALSE; + printstopp = FALSE; for (;;) { #if defined(__MINGW32__) || defined(_MSC_VER) Sleep(50); // loop delay @@ -1198,6 +1225,7 @@ printsend(void) mutex_lock(&fputsMutex); outsend = outstorage(NULL, FALSE); mutex_unlock(&fputsMutex); + break; } mutex_lock(&fputsMutex); @@ -1210,6 +1238,7 @@ printsend(void) tfree(outsend); } } + ps_exited = TRUE; } /* remove the first entry of a wordlist, but keep wl->wl_word */