From fcae1791c5d8ab0997db3d2e465e0c81c2329f90 Mon Sep 17 00:00:00 2001 From: stefanjones Date: Wed, 25 Jun 2003 12:28:22 +0000 Subject: [PATCH] ChangeLog tclspice.c: Fix fprintf by the bg thread in tclspice --- src/ChangeLog | 5 +++++ src/tclspice.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 797bb4c7a..98a7da4d6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-06-25 Stefan Jones + + * tclspice.c : + Fix printing while running a background thread, seen eg. in Magic-7.2 + 2001-12-04 Emmanuel Rouat * maths/cmaths/Makefile.am (noinst_PROGRAMS): test programs diff --git a/src/tclspice.c b/src/tclspice.c index 3bc7336ee..08d1415a2 100755 --- a/src/tclspice.c +++ b/src/tclspice.c @@ -326,15 +326,17 @@ static int spicetoblt(ClientData clientData, Tcl_Interp *interp, /* Main spice command executions and thread control */ /*****************************************************************/ -static pthread_t tid; +static pthread_t tid, bgtid=(pthread_t)0; static bool fl_running = FALSE; static bool fl_exited = TRUE; static void *_thread_run(void *string){ fl_exited = FALSE; + bgtid = pthread_self(); cp_evloop((char *)string); FREE(string); + bgtid = (pthread_t)0; fl_exited = TRUE; return 0; } @@ -1360,8 +1362,9 @@ int tcl_vfprintf(FILE *f, const char *fmt, va_list args_in) char *outptr, *bigstr = NULL, *finalstr = NULL; int i, nchars, result, escapes = 0; - if(f != stdout && f != stderr) - vfprintf(f,fmt,args_in); + if((f != stdout && f != stderr) || + ( fl_running && bgtid == pthread_self()) ) + return vfprintf(f,fmt,args_in); strcpy (outstr + 19, (f == stderr) ? "err \"" : "out \""); outptr = outstr; @@ -1457,6 +1460,9 @@ void tcl_stdflush(FILE *f) static char stdstr[] = "flush stdxxx"; char *stdptr = stdstr + 9; + if ( fl_running && bgtid == pthread_self()) + return; + Tcl_SaveResult(spice_interp, &state); strcpy(stdptr, (f == stderr) ? "err" : "out"); Tcl_Eval(spice_interp, stdstr);