summaryrefslogtreecommitdiffstats
path: root/generic/tclAsync.c
diff options
context:
space:
mode:
authorstanton <stanton>1999-04-16 00:46:29 (GMT)
committerstanton <stanton>1999-04-16 00:46:29 (GMT)
commit97464e6cba8eb0008cf2727c15718671992b913f (patch)
treece9959f2747257d98d52ec8d18bf3b0de99b9535 /generic/tclAsync.c
parenta8c96ddb94d1483a9de5e340b740cb74ef6cafa7 (diff)
downloadtcl-97464e6cba8eb0008cf2727c15718671992b913f.zip
tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.gz
tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.bz2
merged tcl 8.1 branch back into the main trunk
Diffstat (limited to 'generic/tclAsync.c')
-rw-r--r--generic/tclAsync.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/generic/tclAsync.c b/generic/tclAsync.c
index 18af186..fc80385 100644
--- a/generic/tclAsync.c
+++ b/generic/tclAsync.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclAsync.c,v 1.3 1999/03/11 00:19:23 stanton Exp $
+ * RCS: @(#) $Id: tclAsync.c,v 1.4 1999/04/16 00:46:42 stanton Exp $
*/
#include "tclInt.h"
@@ -43,6 +43,8 @@ static AsyncHandler *firstHandler; /* First handler defined for process,
* or NULL if none. */
static AsyncHandler *lastHandler; /* Last handler or NULL. */
+TCL_DECLARE_MUTEX(asyncMutex) /* Process-wide async handler lock */
+
/*
* The variable below is set to 1 whenever a handler becomes ready and
* it is cleared to zero whenever Tcl_AsyncInvoke is called. It can be
@@ -92,12 +94,14 @@ Tcl_AsyncCreate(proc, clientData)
asyncPtr->nextPtr = NULL;
asyncPtr->proc = proc;
asyncPtr->clientData = clientData;
+ Tcl_MutexLock(&asyncMutex);
if (firstHandler == NULL) {
firstHandler = asyncPtr;
} else {
lastHandler->nextPtr = asyncPtr;
}
lastHandler = asyncPtr;
+ Tcl_MutexUnlock(&asyncMutex);
return (Tcl_AsyncHandler) asyncPtr;
}
@@ -124,11 +128,13 @@ void
Tcl_AsyncMark(async)
Tcl_AsyncHandler async; /* Token for handler. */
{
+ Tcl_MutexLock(&asyncMutex);
((AsyncHandler *) async)->ready = 1;
if (!asyncActive) {
- TclpAsyncMark(async);
asyncReady = 1;
+ TclpAsyncMark(async);
}
+ Tcl_MutexUnlock(&asyncMutex);
}
/*
@@ -161,8 +167,10 @@ Tcl_AsyncInvoke(interp, code)
* just completed. */
{
AsyncHandler *asyncPtr;
+ Tcl_MutexLock(&asyncMutex);
if (asyncReady == 0) {
+ Tcl_MutexUnlock(&asyncMutex);
return code;
}
asyncReady = 0;
@@ -193,9 +201,12 @@ Tcl_AsyncInvoke(interp, code)
break;
}
asyncPtr->ready = 0;
+ Tcl_MutexUnlock(&asyncMutex);
code = (*asyncPtr->proc)(asyncPtr->clientData, interp, code);
+ Tcl_MutexLock(&asyncMutex);
}
asyncActive = 0;
+ Tcl_MutexUnlock(&asyncMutex);
return code;
}
@@ -223,6 +234,7 @@ Tcl_AsyncDelete(async)
AsyncHandler *asyncPtr = (AsyncHandler *) async;
AsyncHandler *prevPtr;
+ Tcl_MutexLock(&asyncMutex);
if (firstHandler == asyncPtr) {
firstHandler = asyncPtr->nextPtr;
if (firstHandler == NULL) {
@@ -238,6 +250,7 @@ Tcl_AsyncDelete(async)
lastHandler = prevPtr;
}
}
+ Tcl_MutexUnlock(&asyncMutex);
ckfree((char *) asyncPtr);
}