From: Zoran V. <vas...@us...> - 2005-10-15 07:19:07
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32167 Modified Files: tclfile.c Log Message: Improved UnspliceChannel to properly disable ready-to-fire events still sitting in the threads event queue prior detachment of the channel. Index: tclfile.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclfile.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tclfile.c 8 Oct 2005 12:06:07 -0000 1.6 --- tclfile.c 15 Oct 2005 07:18:59 -0000 1.7 *************** *** 764,770 **** UnspliceChannel(Tcl_Interp *interp, Tcl_Channel chan) { Tcl_ClearChannelHandlers(chan); ! Tcl_RegisterChannel((Tcl_Interp*)NULL, chan); /* Prevent closing */ Tcl_UnregisterChannel(interp, chan); Tcl_CutChannel(chan); } --- 764,797 ---- UnspliceChannel(Tcl_Interp *interp, Tcl_Channel chan) { + Tcl_ChannelType *chanTypePtr; + Tcl_DriverWatchProc *watchProc; + Tcl_ClearChannelHandlers(chan); ! ! chanTypePtr = Tcl_GetChannelType(chan); ! watchProc = Tcl_ChannelWatchProc(chanTypePtr); ! ! /* ! * This effectively disables processing of pending ! * events which are ready to fire for the given ! * channel. If we do not do this, events will hit ! * the detached channel which is potentially being ! * owned by some other thread. This will wreck havoc ! * on our memory and eventually badly hurt us... ! */ ! ! if (watchProc) { ! (*watchProc)(Tcl_GetChannelInstanceData(chan), 0); ! } ! ! /* ! * Artificially bump the channel reference count ! * which protects us from channel being closed ! * during the Tcl_UnregisterChannel(). ! */ ! ! Tcl_RegisterChannel((Tcl_Interp *) NULL, chan); Tcl_UnregisterChannel(interp, chan); + Tcl_CutChannel(chan); } |