diff options
author | vasiljevic <vasiljevic@noemail.net> | 2006-07-11 13:18:09 (GMT) |
---|---|---|
committer | vasiljevic <vasiljevic@noemail.net> | 2006-07-11 13:18:09 (GMT) |
commit | ee3ad1b013979b1e500241eb0611097117bf30fb (patch) | |
tree | 6611a81931711753b47223fc8421f578b5df517e /generic/tclAsync.c | |
parent | 9d82680bd646b03bd026b9fae2ddb708df1325e2 (diff) | |
download | tcl-ee3ad1b013979b1e500241eb0611097117bf30fb.zip tcl-ee3ad1b013979b1e500241eb0611097117bf30fb.tar.gz tcl-ee3ad1b013979b1e500241eb0611097117bf30fb.tar.bz2 |
Made Tcl_AsyncDelete() more tolerant when called after all thread TSD
has been garbage-collected.
FossilOrigin-Name: 9cd2581375dd5d702ea66913927d0b49c4184894
Diffstat (limited to 'generic/tclAsync.c')
-rw-r--r-- | generic/tclAsync.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/generic/tclAsync.c b/generic/tclAsync.c index 76e3e28..c99cea9 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.6 2001/08/30 07:50:18 davygrvy Exp $ + * RCS: @(#) $Id: tclAsync.c,v 1.6.12.1 2006/07/11 13:18:10 vasiljevic Exp $ */ #include "tclInt.h" @@ -286,20 +286,29 @@ Tcl_AsyncDelete(async) AsyncHandler *asyncPtr = (AsyncHandler *) async; AsyncHandler *prevPtr; + /* + * Conservatively check the existence of the linked list of + * registered handlers, as we may come at this point even + * when the TSD's for the current thread have been already + * garbage-collected. + */ + Tcl_MutexLock(&tsdPtr->asyncMutex); - if (tsdPtr->firstHandler == asyncPtr) { - tsdPtr->firstHandler = asyncPtr->nextPtr; - if (tsdPtr->firstHandler == NULL) { - tsdPtr->lastHandler = NULL; - } - } else { - prevPtr = tsdPtr->firstHandler; - while (prevPtr->nextPtr != asyncPtr) { - prevPtr = prevPtr->nextPtr; - } - prevPtr->nextPtr = asyncPtr->nextPtr; - if (tsdPtr->lastHandler == asyncPtr) { - tsdPtr->lastHandler = prevPtr; + if (tsdPtr->firstHandler != NULL ) { + if (tsdPtr->firstHandler == asyncPtr) { + tsdPtr->firstHandler = asyncPtr->nextPtr; + if (tsdPtr->firstHandler == NULL) { + tsdPtr->lastHandler = NULL; + } + } else { + prevPtr = tsdPtr->firstHandler; + while (prevPtr->nextPtr != asyncPtr) { + prevPtr = prevPtr->nextPtr; + } + prevPtr->nextPtr = asyncPtr->nextPtr; + if (tsdPtr->lastHandler == asyncPtr) { + tsdPtr->lastHandler = prevPtr; + } } } Tcl_MutexUnlock(&tsdPtr->asyncMutex); |