2004-06-04 Stefan Jones <stefan.jones@multigig.com>
* src/tclspice.c: Cleaned up thread code so can use Tcl_Threads instead on W32
This commit is contained in:
parent
70a5b8dbb5
commit
9ae1f4efe1
|
|
@ -1,5 +1,8 @@
|
||||||
2004-06-04 Stefan Jones <stefan.jones@multigig.com>
|
2004-06-04 Stefan Jones <stefan.jones@multigig.com>
|
||||||
|
|
||||||
|
* src/tclspice.c:
|
||||||
|
Cleaned up thread code so can use Tcl_Threads instead on W32
|
||||||
|
|
||||||
* src/tclspice.c:
|
* src/tclspice.c:
|
||||||
Do not register more than one identical trigger
|
Do not register more than one identical trigger
|
||||||
Return voltage triggered at also
|
Return voltage triggered at also
|
||||||
|
|
|
||||||
210
src/tclspice.c
210
src/tclspice.c
|
|
@ -16,8 +16,38 @@
|
||||||
/* Header files for C functions */
|
/* Header files for C functions */
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
||||||
/* Copied from main.c in ngspice*/
|
|
||||||
#include <ngspice.h>
|
#include <ngspice.h>
|
||||||
|
#include <tcl.h>
|
||||||
|
|
||||||
|
/*Use Tcl threads if on W32 without pthreads*/
|
||||||
|
#ifndef HAVE_LIBPTHREAD
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
|
||||||
|
#define mutex_lock(a) Tcl_MutexLock(a)
|
||||||
|
#define mutex_unlock(a) Tcl_MutexUnlock(a)
|
||||||
|
#define thread_self() Tcl_GetCurrentThread()
|
||||||
|
typedef Tcl_Mutex mutexType;
|
||||||
|
typedef Tcl_ThreadId threadId_t;
|
||||||
|
#define TCL_THREADS
|
||||||
|
#define THREADS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#define mutex_lock(a) pthread_mutex_lock(a)
|
||||||
|
#define mutex_unlock(a) pthread_mutex_unlock(a)
|
||||||
|
#define thread_self() pthread_self()
|
||||||
|
typedef pthread_mutex_t mutexType;
|
||||||
|
typedef pthread_t threadId_t;
|
||||||
|
#define THREADS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Copied from main.c in ngspice*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef HAVE_STRING_H
|
#ifdef HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -26,7 +56,9 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <windef.h>
|
#include <windef.h>
|
||||||
#include <winbase.h> /* Sleep */
|
#include <winbase.h> /* Sleep */
|
||||||
#define srandom(a) srand(a) /* srandom */
|
#ifndef srandom
|
||||||
|
#define srandom(a) srand(a) /* srandom */
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <unistd.h> /* usleep */
|
#include <unistd.h> /* usleep */
|
||||||
#endif /* __MINGW32__ */
|
#endif /* __MINGW32__ */
|
||||||
|
|
@ -61,7 +93,6 @@ extern sigjmp_buf jbuf;
|
||||||
/*Included for the module to access data*/
|
/*Included for the module to access data*/
|
||||||
#include <dvec.h>
|
#include <dvec.h>
|
||||||
#include <plot.h>
|
#include <plot.h>
|
||||||
#include <tcl.h>
|
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
#undef WIN32
|
#undef WIN32
|
||||||
|
|
@ -83,11 +114,6 @@ extern sigjmp_buf jbuf;
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
|
||||||
/* run spicein background */
|
|
||||||
#include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdarg.h> /* for va_copy() */
|
#include <stdarg.h> /* for va_copy() */
|
||||||
|
|
||||||
extern IFfrontEnd nutmeginfo;
|
extern IFfrontEnd nutmeginfo;
|
||||||
|
|
@ -99,8 +125,8 @@ extern int SIMinit(IFfrontEnd *frontEnd, IFsimulator **simulator);
|
||||||
/*For blt spice to use*/
|
/*For blt spice to use*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_t mutex;/*lock for this vector*/
|
mutexType mutex;/*lock for this vector*/
|
||||||
#endif
|
#endif
|
||||||
double *data;/* vector data*/
|
double *data;/* vector data*/
|
||||||
int size;/*data it can store*/
|
int size;/*data it can store*/
|
||||||
|
|
@ -222,8 +248,8 @@ void blt_init(void *run) {
|
||||||
void blt_add(int index,double value){
|
void blt_add(int index,double value){
|
||||||
vector *v;
|
vector *v;
|
||||||
v = &vectors[index];
|
v = &vectors[index];
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&vectors[index].mutex);
|
mutex_lock(&vectors[index].mutex);
|
||||||
#endif
|
#endif
|
||||||
if(!(v->length < v->size)){
|
if(!(v->length < v->size)){
|
||||||
v->size += 100;
|
v->size += 100;
|
||||||
|
|
@ -231,16 +257,16 @@ void blt_add(int index,double value){
|
||||||
}
|
}
|
||||||
v->data[v->length] = value;
|
v->data[v->length] = value;
|
||||||
v->length ++;
|
v->length ++;
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&vectors[index].mutex);
|
mutex_unlock(&vectors[index].mutex);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Locks the vector data to stop conflicts*/
|
/* Locks the vector data to stop conflicts*/
|
||||||
void blt_lockvec(int index){
|
void blt_lockvec(int index){
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&vectors[index].mutex);
|
mutex_lock(&vectors[index].mutex);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -253,8 +279,8 @@ void blt_relink(int index,void *tmp){
|
||||||
vectors[index].data = v->v_realdata;
|
vectors[index].data = v->v_realdata;
|
||||||
vectors[index].length = v->v_length;
|
vectors[index].length = v->v_length;
|
||||||
vectors[index].size = v->v_length;/*silly spice doesn't use v_rlength*/
|
vectors[index].size = v->v_length;/*silly spice doesn't use v_rlength*/
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&vectors[index].mutex);
|
mutex_unlock(&vectors[index].mutex);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -288,12 +314,12 @@ static int lastVector TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0;i < blt_vnum;i++){
|
for(i=0;i < blt_vnum;i++){
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&vectors[i].mutex);
|
mutex_lock(&vectors[i].mutex);
|
||||||
#endif
|
#endif
|
||||||
V[i] = vectors[i].data[vectors[i].length-1];
|
V[i] = vectors[i].data[vectors[i].length-1];
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&vectors[i].mutex);
|
mutex_unlock(&vectors[i].mutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
Blt_ResetVector(vec,V,blt_vnum,
|
Blt_ResetVector(vec,V,blt_vnum,
|
||||||
|
|
@ -327,8 +353,8 @@ static int get_value TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
|
|
||||||
j = atoi(argv[2]);
|
j = atoi(argv[2]);
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&vectors[vindex].mutex);
|
mutex_lock(&vectors[vindex].mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(j < 0 || j >= vectors[vindex].length) {
|
if(j < 0 || j >= vectors[vindex].length) {
|
||||||
|
|
@ -338,8 +364,8 @@ static int get_value TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
val = vectors[vindex].data[j];
|
val = vectors[vindex].data[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&vectors[vindex].mutex);
|
mutex_unlock(&vectors[vindex].mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(i) {
|
if(i) {
|
||||||
|
|
@ -390,8 +416,8 @@ static int spicetoblt TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
if(argc == 5)
|
if(argc == 5)
|
||||||
end = atoi(argv[4]);
|
end = atoi(argv[4]);
|
||||||
if(vectors[j].length) {
|
if(vectors[j].length) {
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&vectors[j].mutex);
|
mutex_lock(&vectors[j].mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
len = vectors[j].length;
|
len = vectors[j].length;
|
||||||
|
|
@ -411,8 +437,8 @@ static int spicetoblt TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
Blt_ResetVector(vec,(vectors[j].data + start),len,
|
Blt_ResetVector(vec,(vectors[j].data + start),len,
|
||||||
len,TCL_VOLATILE);
|
len,TCL_VOLATILE);
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&vectors[j].mutex);
|
mutex_unlock(&vectors[j].mutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
|
|
@ -423,18 +449,19 @@ static int spicetoblt TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
/* Main spice command executions and thread control */
|
/* Main spice command executions and thread control */
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
static pthread_t tid, bgtid=(pthread_t)0;
|
static threadId_t tid, bgtid=(threadId_t)0;
|
||||||
|
|
||||||
static bool fl_running = FALSE;
|
static bool fl_running = FALSE;
|
||||||
static bool fl_exited = TRUE;
|
static bool fl_exited = TRUE;
|
||||||
|
|
||||||
|
|
||||||
static void *_thread_run(void *string){
|
static void *_thread_run(void *string){
|
||||||
fl_exited = FALSE;
|
fl_exited = FALSE;
|
||||||
bgtid = pthread_self();
|
bgtid = thread_self();
|
||||||
cp_evloop((char *)string);
|
cp_evloop((char *)string);
|
||||||
FREE(string);
|
FREE(string);
|
||||||
bgtid = (pthread_t)0;
|
bgtid = (threadId_t)0;
|
||||||
fl_exited = TRUE;
|
fl_exited = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -456,7 +483,11 @@ static int _thread_stop(){
|
||||||
fprintf(stderr,"couldn't stop tclspice\n");
|
fprintf(stderr,"couldn't stop tclspice\n");
|
||||||
return TCL_ERROR;
|
return TCL_ERROR;
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_LIBPTHREAD
|
||||||
pthread_join(tid, NULL);
|
pthread_join(tid, NULL);
|
||||||
|
#else
|
||||||
|
Tcl_JoinThread(tid,NULL);
|
||||||
|
#endif
|
||||||
fl_running = FALSE;
|
fl_running = FALSE;
|
||||||
ft_intrpt = FALSE;
|
ft_intrpt = FALSE;
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
|
|
@ -465,13 +496,13 @@ static int _thread_stop(){
|
||||||
}
|
}
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
#endif /*HAVE_LIBPTHREAD*/
|
#endif /*THREADS*/
|
||||||
|
|
||||||
static int _run(int argc,char **argv){
|
static int _run(int argc,char **argv){
|
||||||
char buf[1024] = "";
|
char buf[1024] = "";
|
||||||
int i;
|
int i;
|
||||||
sighandler oldHandler;
|
sighandler oldHandler;
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
char *string;
|
char *string;
|
||||||
bool fl_bg = FALSE;
|
bool fl_bg = FALSE;
|
||||||
/* run task in background if preceeded by "bg"*/
|
/* run task in background if preceeded by "bg"*/
|
||||||
|
|
@ -495,13 +526,18 @@ static int _run(int argc,char **argv){
|
||||||
strcat(buf," ");
|
strcat(buf," ");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
/* run in the background */
|
/* run in the background */
|
||||||
if(fl_bg){
|
if(fl_bg){
|
||||||
if(fl_running) _thread_stop();
|
if(fl_running) _thread_stop();
|
||||||
fl_running =TRUE;
|
fl_running =TRUE;
|
||||||
string = copy(buf);/*as buf gets freed fairly quickly*/
|
string = copy(buf);/*as buf gets freed fairly quickly*/
|
||||||
|
#ifdef HAVE_LIBPTHREAD
|
||||||
pthread_create(&tid,NULL,_thread_run,(void *)string);
|
pthread_create(&tid,NULL,_thread_run,(void *)string);
|
||||||
|
#else
|
||||||
|
Tcl_CreateThread(&tid,(Tcl_ThreadCreateProc *)_thread_run,string,
|
||||||
|
TCL_THREAD_STACK_DEFAULT,TCL_THREAD_JOINABLE);
|
||||||
|
#endif
|
||||||
} else
|
} else
|
||||||
/* halt (pause) a bg run */
|
/* halt (pause) a bg run */
|
||||||
if(!strcmp(argv[0],"halt")){
|
if(!strcmp(argv[0],"halt")){
|
||||||
|
|
@ -531,7 +567,7 @@ static int _run(int argc,char **argv){
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
cp_evloop(buf);
|
cp_evloop(buf);
|
||||||
#endif /*HAVE_LIBPTHREAD*/
|
#endif /*THREADS*/
|
||||||
signal(SIGINT,oldHandler);
|
signal(SIGINT,oldHandler);
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -554,7 +590,7 @@ static int _spice_dispatch TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
return _run(argc-1,(char **)&argv[1]);
|
return _run(argc-1,(char **)&argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
/*Checks if spice is runnuing in the background */
|
/*Checks if spice is runnuing in the background */
|
||||||
static int running TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
static int running TCL_CMDPROCARGS(clientData,interp,argc,argv) {
|
||||||
Tcl_SetObjResult(interp,Tcl_NewIntObj((long) (fl_running && !fl_exited)));
|
Tcl_SetObjResult(interp,Tcl_NewIntObj((long) (fl_running && !fl_exited)));
|
||||||
|
|
@ -1199,8 +1235,8 @@ struct triggerEvent {
|
||||||
struct triggerEvent *eventQueue;
|
struct triggerEvent *eventQueue;
|
||||||
struct triggerEvent *eventQueueEnd;
|
struct triggerEvent *eventQueueEnd;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_t triggerMutex;
|
mutexType triggerMutex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct watch {
|
struct watch {
|
||||||
|
|
@ -1263,8 +1299,8 @@ int triggerEventHandler(Tcl_Event *evPtr, int flags) {
|
||||||
static char buf[512];
|
static char buf[512];
|
||||||
int rtn=TCL_OK;
|
int rtn=TCL_OK;
|
||||||
Tcl_Preserve((ClientData)spice_interp);
|
Tcl_Preserve((ClientData)spice_interp);
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
while(eventQueue) {
|
while(eventQueue) {
|
||||||
struct triggerEvent *event = eventQueue;
|
struct triggerEvent *event = eventQueue;
|
||||||
|
|
@ -1281,8 +1317,8 @@ int triggerEventHandler(Tcl_Event *evPtr, int flags) {
|
||||||
}
|
}
|
||||||
eventQueueEnd = NULL;
|
eventQueueEnd = NULL;
|
||||||
quit:
|
quit:
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
Tcl_ResetResult(spice_interp);
|
Tcl_ResetResult(spice_interp);
|
||||||
Tcl_Release((ClientData)spice_interp);
|
Tcl_Release((ClientData)spice_interp);
|
||||||
|
|
@ -1302,8 +1338,8 @@ void triggerEventSetup(ClientData clientData,int flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void triggerEventCheck(ClientData clientData,int flags) {
|
void triggerEventCheck(ClientData clientData,int flags) {
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
if(eventQueue) {
|
if(eventQueue) {
|
||||||
Tcl_Event *tclEvent;
|
Tcl_Event *tclEvent;
|
||||||
|
|
@ -1311,8 +1347,8 @@ void triggerEventCheck(ClientData clientData,int flags) {
|
||||||
tclEvent->proc = triggerEventHandler;
|
tclEvent->proc = triggerEventHandler;
|
||||||
Tcl_QueueEvent(tclEvent,TCL_QUEUE_TAIL);
|
Tcl_QueueEvent(tclEvent,TCL_QUEUE_TAIL);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1320,16 +1356,16 @@ int Tcl_ExecutePerLoop() {
|
||||||
|
|
||||||
struct watch *current;
|
struct watch *current;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&vectors[0].mutex);
|
mutex_lock(&vectors[0].mutex);
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(current=watches;current;current = current->next) {
|
for(current=watches;current;current = current->next) {
|
||||||
vector *v;
|
vector *v;
|
||||||
v = &vectors[current->vector];
|
v = &vectors[current->vector];
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&v->mutex);
|
mutex_lock(&v->mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((current->type > 0 && current->state && v->data[v->length-1] > current->Vmax) ||
|
if((current->type > 0 && current->state && v->data[v->length-1] > current->Vmax) ||
|
||||||
|
|
@ -1371,8 +1407,8 @@ int Tcl_ExecutePerLoop() {
|
||||||
current->oT = vectors[0].data[vectors[0].length-1];
|
current->oT = vectors[0].data[vectors[0].length-1];
|
||||||
current->oV = v->data[v->length-1];
|
current->oV = v->data[v->length-1];
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&v->mutex);
|
mutex_unlock(&v->mutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1380,16 +1416,16 @@ int Tcl_ExecutePerLoop() {
|
||||||
stepCallbackPending=1;
|
stepCallbackPending=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
|
|
||||||
pthread_mutex_unlock(&vectors[0].mutex);
|
mutex_unlock(&vectors[0].mutex);
|
||||||
|
|
||||||
if(triggerCallback && eventQueue && bgtid != pthread_self()) {
|
if(triggerCallback && eventQueue && bgtid != thread_self()) {
|
||||||
triggerEventHandler(NULL,0);
|
triggerEventHandler(NULL,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stepCallback && stepCallbackPending && bgtid != pthread_self()) {
|
if(stepCallback && stepCallbackPending && bgtid != thread_self()) {
|
||||||
stepEventHandler(NULL,0);
|
stepEventHandler(NULL,0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
@ -1406,8 +1442,8 @@ int Tcl_ExecutePerLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resetTriggers() {
|
static int resetTriggers() {
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(watches) {
|
while(watches) {
|
||||||
|
|
@ -1424,8 +1460,8 @@ static int resetTriggers() {
|
||||||
|
|
||||||
eventQueueEnd = NULL;
|
eventQueueEnd = NULL;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1552,8 +1588,8 @@ static int registerTrigger TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
Vmax = atof(argv[3]);
|
Vmax = atof(argv[3]);
|
||||||
Vavg = (Vmin + Vmax) / 2 ;
|
Vavg = (Vmin + Vmax) / 2 ;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(tmp = watches;tmp != NULL;tmp=tmp->next) {
|
for(tmp = watches;tmp != NULL;tmp=tmp->next) {
|
||||||
|
|
@ -1597,8 +1633,8 @@ static int registerTrigger TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
|
|
@ -1632,8 +1668,8 @@ static int unregisterTrigger TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
else
|
else
|
||||||
type = 1;
|
type = 1;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cut = &watches;
|
cut = &watches;
|
||||||
|
|
@ -1650,8 +1686,8 @@ static int unregisterTrigger TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(tmp == NULL) {
|
if(tmp == NULL) {
|
||||||
|
|
@ -1677,8 +1713,8 @@ static int popTriggerEvent TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
struct triggerEvent *popedEvent;
|
struct triggerEvent *popedEvent;
|
||||||
Tcl_Obj *list;
|
Tcl_Obj *list;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
popedEvent = eventQueue;
|
popedEvent = eventQueue;
|
||||||
|
|
@ -1705,8 +1741,8 @@ static int popTriggerEvent TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
|
|
||||||
FREE(popedEvent);
|
FREE(popedEvent);
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1724,15 +1760,15 @@ static int listTriggers TCL_CMDPROCARGS(clientData,interp,argc,argv){
|
||||||
|
|
||||||
list = Tcl_NewListObj(0,NULL);
|
list = Tcl_NewListObj(0,NULL);
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_lock(&triggerMutex);
|
mutex_lock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(tmp=watches;tmp;tmp=tmp->next)
|
for(tmp=watches;tmp;tmp=tmp->next)
|
||||||
Tcl_ListObjAppendElement(interp,list,Tcl_NewStringObj(vectors[tmp->vector].name,strlen(vectors[tmp->vector].name)));
|
Tcl_ListObjAppendElement(interp,list,Tcl_NewStringObj(vectors[tmp->vector].name,strlen(vectors[tmp->vector].name)));
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
pthread_mutex_unlock(&triggerMutex);
|
mutex_unlock(&triggerMutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Tcl_SetObjResult(interp,list);
|
Tcl_SetObjResult(interp,list);
|
||||||
|
|
@ -1884,7 +1920,7 @@ bot:
|
||||||
Tcl_CreateCommand(interp, TCLSPICE_prefix "listTriggers", listTriggers, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
Tcl_CreateCommand(interp, TCLSPICE_prefix "listTriggers", listTriggers, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||||
|
|
||||||
Tcl_CreateCommand(interp, TCLSPICE_prefix "registerStepCallback", registerTriggerCallback, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
Tcl_CreateCommand(interp, TCLSPICE_prefix "registerStepCallback", registerTriggerCallback, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
Tcl_CreateCommand(interp, TCLSPICE_prefix "bg", _tcl_dispatch, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
Tcl_CreateCommand(interp, TCLSPICE_prefix "bg", _tcl_dispatch, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||||
Tcl_CreateCommand(interp, TCLSPICE_prefix "halt", _tcl_dispatch, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
Tcl_CreateCommand(interp, TCLSPICE_prefix "halt", _tcl_dispatch, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||||
Tcl_CreateCommand(interp, TCLSPICE_prefix "running", running, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
Tcl_CreateCommand(interp, TCLSPICE_prefix "running", running, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
|
||||||
|
|
@ -1928,8 +1964,8 @@ int tcl_vfprintf(FILE *f, const char *fmt, va_list args_in)
|
||||||
int i, nchars, result, escapes = 0;
|
int i, nchars, result, escapes = 0;
|
||||||
|
|
||||||
if((fileno(f) != STDOUT_FILENO && fileno(f) != STDERR_FILENO)
|
if((fileno(f) != STDOUT_FILENO && fileno(f) != STDERR_FILENO)
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
|| ( fl_running && bgtid == pthread_self())
|
|| ( fl_running && bgtid == thread_self())
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
return vfprintf(f,fmt,args_in);
|
return vfprintf(f,fmt,args_in);
|
||||||
|
|
@ -2028,8 +2064,8 @@ void tcl_stdflush(FILE *f)
|
||||||
static char stdstr[] = "flush stdxxx";
|
static char stdstr[] = "flush stdxxx";
|
||||||
char *stdptr = stdstr + 9;
|
char *stdptr = stdstr + 9;
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
#ifdef THREADS
|
||||||
if ( fl_running && bgtid == pthread_self())
|
if ( fl_running && bgtid == thread_self())
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue