0000: 2f 2a 0a 20 2a 20 74 63 6c 55 6e 69 78 4e 6f 74 /*. * tclUnixNot
0010: 69 66 79 2e 63 20 2d 2d 0a 20 2a 0a 20 2a 09 54 ify.c --. *. *.T
0020: 68 69 73 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e his file contain
0030: 73 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 s the implementa
0040: 74 69 6f 6e 20 6f 66 20 74 68 65 20 73 65 6c 65 tion of the sele
0050: 63 74 2d 62 61 73 65 64 0a 20 2a 09 55 6e 69 78 ct-based. *.Unix
0060: 2d 73 70 65 63 69 66 69 63 20 6e 6f 74 69 66 69 -specific notifi
0070: 65 72 2c 20 77 68 69 63 68 20 69 73 20 74 68 65 er, which is the
0080: 20 6c 6f 77 65 73 74 2d 6c 65 76 65 6c 20 70 61 lowest-level pa
0090: 72 74 20 6f 66 20 74 68 65 0a 20 2a 09 54 63 6c rt of the. *.Tcl
00a0: 20 65 76 65 6e 74 20 6c 6f 6f 70 2e 20 20 54 68 event loop. Th
00b0: 69 73 20 66 69 6c 65 20 77 6f 72 6b 73 20 74 6f is file works to
00c0: 67 65 74 68 65 72 20 77 69 74 68 0a 20 2a 09 2e gether with. *..
00d0: 2e 2f 67 65 6e 65 72 69 63 2f 74 63 6c 4e 6f 74 ./generic/tclNot
00e0: 69 66 79 2e 63 2e 0a 20 2a 0a 20 2a 20 43 6f 70 ify.c.. *. * Cop
00f0: 79 72 69 67 68 74 20 28 63 29 20 31 39 39 35 2d yright (c) 1995-
0100: 31 39 39 37 20 53 75 6e 20 4d 69 63 72 6f 73 79 1997 Sun Microsy
0110: 73 74 65 6d 73 2c 20 49 6e 63 2e 0a 20 2a 0a 20 stems, Inc.. *.
0120: 2a 20 53 65 65 20 74 68 65 20 66 69 6c 65 20 22 * See the file "
0130: 6c 69 63 65 6e 73 65 2e 74 65 72 6d 73 22 20 66 license.terms" f
0140: 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f or information o
0150: 6e 20 75 73 61 67 65 20 61 6e 64 20 72 65 64 69 n usage and redi
0160: 73 74 72 69 62 75 74 69 6f 6e 0a 20 2a 20 6f 66 stribution. * of
0170: 20 74 68 69 73 20 66 69 6c 65 2c 20 61 6e 64 20 this file, and
0180: 66 6f 72 20 61 20 44 49 53 43 4c 41 49 4d 45 52 for a DISCLAIMER
0190: 20 4f 46 20 41 4c 4c 20 57 41 52 52 41 4e 54 49 OF ALL WARRANTI
01a0: 45 53 2e 0a 20 2a 0a 20 2a 20 52 43 53 3a 20 40 ES.. *. * RCS: @
01b0: 28 23 29 20 24 49 64 3a 20 74 63 6c 55 6e 69 78 (#) $Id: tclUnix
01c0: 4e 6f 74 66 79 2e 63 2c 76 20 31 2e 31 31 2e 32 Notfy.c,v 1.11.2
01d0: 2e 31 36 20 32 30 30 36 2f 30 38 2f 32 32 20 31 .16 2006/08/22 1
01e0: 37 3a 34 35 3a 30 32 20 61 6e 64 72 65 61 73 5f 7:45:02 andreas_
01f0: 6b 75 70 72 69 65 73 20 45 78 70 20 24 0a 20 2a kupries Exp $. *
0200: 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 74 63 6c /..#include "tcl
0210: 49 6e 74 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 Int.h".#include
0220: 22 74 63 6c 50 6f 72 74 2e 68 22 0a 23 69 66 6e "tclPort.h".#ifn
0230: 64 65 66 20 48 41 56 45 5f 43 4f 52 45 46 4f 55 def HAVE_COREFOU
0240: 4e 44 41 54 49 4f 4e 20 2f 2a 20 44 61 72 77 69 NDATION /* Darwi
0250: 6e 2f 4d 61 63 20 4f 53 20 58 20 43 6f 72 65 46 n/Mac OS X CoreF
0260: 6f 75 6e 64 61 74 69 6f 6e 20 6e 6f 74 69 66 69 oundation notifi
0270: 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 er.
0280: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0290: 2a 20 69 73 20 69 6e 20 74 63 6c 4d 61 63 4f 53 * is in tclMacOS
02a0: 58 4e 6f 74 69 66 79 2e 63 20 2a 2f 0a 23 69 6e XNotify.c */.#in
02b0: 63 6c 75 64 65 20 3c 73 69 67 6e 61 6c 2e 68 3e clude <signal.h>
02c0: 20 0a 0a 65 78 74 65 72 6e 20 54 63 6c 53 74 75 ..extern TclStu
02d0: 62 73 20 74 63 6c 53 74 75 62 73 3b 0a 65 78 74 bs tclStubs;.ext
02e0: 65 72 6e 20 54 63 6c 5f 4e 6f 74 69 66 69 65 72 ern Tcl_Notifier
02f0: 50 72 6f 63 73 20 74 63 6c 4f 72 69 67 69 6e 61 Procs tclOrigina
0300: 6c 4e 6f 74 69 66 69 65 72 3b 0a 0a 2f 2a 0a 20 lNotifier;../*.
0310: 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 * This structure
0320: 20 69 73 20 75 73 65 64 20 74 6f 20 6b 65 65 70 is used to keep
0330: 20 74 72 61 63 6b 20 6f 66 20 74 68 65 20 6e 6f track of the no
0340: 74 69 66 69 65 72 20 69 6e 66 6f 20 66 6f 72 20 tifier info for
0350: 61 20 0a 20 2a 20 61 20 72 65 67 69 73 74 65 72 a . * a register
0360: 65 64 20 66 69 6c 65 2e 0a 20 2a 2f 0a 0a 74 79 ed file.. */..ty
0370: 70 65 64 65 66 20 73 74 72 75 63 74 20 46 69 6c pedef struct Fil
0380: 65 48 61 6e 64 6c 65 72 20 7b 0a 20 20 20 20 69 eHandler {. i
0390: 6e 74 20 66 64 3b 0a 20 20 20 20 69 6e 74 20 6d nt fd;. int m
03a0: 61 73 6b 3b 09 09 09 2f 2a 20 4d 61 73 6b 20 6f ask;.../* Mask o
03b0: 66 20 64 65 73 69 72 65 64 20 65 76 65 6e 74 73 f desired events
03c0: 3a 20 54 43 4c 5f 52 45 41 44 41 42 4c 45 2c 0a : TCL_READABLE,.
03d0: 09 09 09 09 20 2a 20 65 74 63 2e 20 2a 2f 0a 20 .... * etc. */.
03e0: 20 20 20 69 6e 74 20 72 65 61 64 79 4d 61 73 6b int readyMask
03f0: 3b 09 09 2f 2a 20 4d 61 73 6b 20 6f 66 20 65 76 ;../* Mask of ev
0400: 65 6e 74 73 20 74 68 61 74 20 68 61 76 65 20 62 ents that have b
0410: 65 65 6e 20 73 65 65 6e 20 73 69 6e 63 65 20 74 een seen since t
0420: 68 65 0a 09 09 09 09 20 2a 20 6c 61 73 74 20 74 he..... * last t
0430: 69 6d 65 20 66 69 6c 65 20 68 61 6e 64 6c 65 72 ime file handler
0440: 73 20 77 65 72 65 20 69 6e 76 6f 6b 65 64 20 66 s were invoked f
0450: 6f 72 0a 09 09 09 09 20 2a 20 74 68 69 73 20 66 or..... * this f
0460: 69 6c 65 2e 20 2a 2f 0a 20 20 20 20 54 63 6c 5f ile. */. Tcl_
0470: 46 69 6c 65 50 72 6f 63 20 2a 70 72 6f 63 3b 09 FileProc *proc;.
0480: 09 2f 2a 20 50 72 6f 63 65 64 75 72 65 20 74 6f ./* Procedure to
0490: 20 63 61 6c 6c 2c 20 69 6e 20 74 68 65 20 73 74 call, in the st
04a0: 79 6c 65 20 6f 66 0a 09 09 09 09 20 2a 20 54 63 yle of..... * Tc
04b0: 6c 5f 43 72 65 61 74 65 46 69 6c 65 48 61 6e 64 l_CreateFileHand
04c0: 6c 65 72 2e 20 2a 2f 0a 20 20 20 20 43 6c 69 65 ler. */. Clie
04d0: 6e 74 44 61 74 61 20 63 6c 69 65 6e 74 44 61 74 ntData clientDat
04e0: 61 3b 09 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 a;./* Argument t
04f0: 6f 20 70 61 73 73 20 74 6f 20 70 72 6f 63 2e 20 o pass to proc.
0500: 2a 2f 0a 20 20 20 20 73 74 72 75 63 74 20 46 69 */. struct Fi
0510: 6c 65 48 61 6e 64 6c 65 72 20 2a 6e 65 78 74 50 leHandler *nextP
0520: 74 72 3b 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 tr;/* Next in li
0530: 73 74 20 6f 66 20 61 6c 6c 20 66 69 6c 65 73 20 st of all files
0540: 77 65 20 63 61 72 65 20 61 62 6f 75 74 2e 20 2a we care about. *
0550: 2f 0a 7d 20 46 69 6c 65 48 61 6e 64 6c 65 72 3b /.} FileHandler;
0560: 0a 0a 2f 2a 0a 20 2a 20 54 68 65 20 66 6f 6c 6c ../*. * The foll
0570: 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 owing structure
0580: 69 73 20 77 68 61 74 20 69 73 20 61 64 64 65 64 is what is added
0590: 20 74 6f 20 74 68 65 20 54 63 6c 20 65 76 65 6e to the Tcl even
05a0: 74 20 71 75 65 75 65 20 77 68 65 6e 0a 20 2a 20 t queue when. *
05b0: 66 69 6c 65 20 68 61 6e 64 6c 65 72 73 20 61 72 file handlers ar
05c0: 65 20 72 65 61 64 79 20 74 6f 20 66 69 72 65 2e e ready to fire.
05d0: 0a 20 2a 2f 0a 0a 74 79 70 65 64 65 66 20 73 74 . */..typedef st
05e0: 72 75 63 74 20 46 69 6c 65 48 61 6e 64 6c 65 72 ruct FileHandler
05f0: 45 76 65 6e 74 20 7b 0a 20 20 20 20 54 63 6c 5f Event {. Tcl_
0600: 45 76 65 6e 74 20 68 65 61 64 65 72 3b 09 09 2f Event header;../
0610: 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 68 * Information th
0620: 61 74 20 69 73 20 73 74 61 6e 64 61 72 64 20 66 at is standard f
0630: 6f 72 0a 09 09 09 09 20 2a 20 61 6c 6c 20 65 76 or..... * all ev
0640: 65 6e 74 73 2e 20 2a 2f 0a 20 20 20 20 69 6e 74 ents. */. int
0650: 20 66 64 3b 09 09 09 2f 2a 20 46 69 6c 65 20 64 fd;.../* File d
0660: 65 73 63 72 69 70 74 6f 72 20 74 68 61 74 20 69 escriptor that i
0670: 73 20 72 65 61 64 79 2e 20 20 55 73 65 64 0a 09 s ready. Used..
0680: 09 09 09 20 2a 20 74 6f 20 66 69 6e 64 20 74 68 ... * to find th
0690: 65 20 46 69 6c 65 48 61 6e 64 6c 65 72 20 73 74 e FileHandler st
06a0: 72 75 63 74 75 72 65 20 66 6f 72 0a 09 09 09 09 ructure for.....
06b0: 20 2a 20 74 68 65 20 66 69 6c 65 20 28 63 61 6e * the file (can
06c0: 27 74 20 70 6f 69 6e 74 20 64 69 72 65 63 74 6c 't point directl
06d0: 79 20 74 6f 20 74 68 65 0a 09 09 09 09 20 2a 20 y to the..... *
06e0: 46 69 6c 65 48 61 6e 64 6c 65 72 20 73 74 72 75 FileHandler stru
06f0: 63 74 75 72 65 20 62 65 63 61 75 73 65 20 69 74 cture because it
0700: 20 63 6f 75 6c 64 0a 09 09 09 09 20 2a 20 67 6f could..... * go
0710: 20 61 77 61 79 20 77 68 69 6c 65 20 74 68 65 20 away while the
0720: 65 76 65 6e 74 20 69 73 20 71 75 65 75 65 64 29 event is queued)
0730: 2e 20 2a 2f 0a 7d 20 46 69 6c 65 48 61 6e 64 6c . */.} FileHandl
0740: 65 72 45 76 65 6e 74 3b 0a 0a 2f 2a 0a 20 2a 0a erEvent;../*. *.
0750: 20 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 * The following
0760: 20 73 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 structure conta
0770: 69 6e 73 20 61 20 73 65 74 20 6f 66 20 73 65 6c ins a set of sel
0780: 65 63 74 28 29 20 6d 61 73 6b 73 20 74 6f 20 74 ect() masks to t
0790: 72 61 63 6b 0a 20 2a 20 72 65 61 64 61 62 6c 65 rack. * readable
07a0: 2c 20 77 72 69 74 61 62 6c 65 2c 20 61 6e 64 20 , writable, and
07b0: 65 78 63 65 70 74 69 6f 6e 61 6c 20 63 6f 6e 64 exceptional cond
07c0: 69 74 69 6f 6e 73 2e 0a 20 2a 2f 0a 0a 74 79 70 itions.. */..typ
07d0: 65 64 65 66 20 73 74 72 75 63 74 20 53 65 6c 65 edef struct Sele
07e0: 63 74 4d 61 73 6b 73 20 7b 0a 20 20 20 20 66 64 ctMasks {. fd
07f0: 5f 73 65 74 20 72 65 61 64 61 62 6c 65 3b 0a 20 _set readable;.
0800: 20 20 20 66 64 5f 73 65 74 20 77 72 69 74 61 62 fd_set writab
0810: 6c 65 3b 0a 20 20 20 20 66 64 5f 73 65 74 20 65 le;. fd_set e
0820: 78 63 65 70 74 69 6f 6e 61 6c 3b 0a 7d 20 53 65 xceptional;.} Se
0830: 6c 65 63 74 4d 61 73 6b 73 3b 0a 0a 2f 2a 0a 20 lectMasks;../*.
0840: 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
0850: 73 74 61 74 69 63 20 73 74 72 75 63 74 75 72 65 static structure
0860: 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 73 74 contains the st
0870: 61 74 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 ate information
0880: 66 6f 72 20 74 68 65 0a 20 2a 20 73 65 6c 65 63 for the. * selec
0890: 74 20 62 61 73 65 64 20 69 6d 70 6c 65 6d 65 6e t based implemen
08a0: 74 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 54 63 tation of the Tc
08b0: 6c 20 6e 6f 74 69 66 69 65 72 2e 20 20 4f 6e 65 l notifier. One
08c0: 20 6f 66 20 74 68 65 73 65 20 73 74 72 75 63 74 of these struct
08d0: 75 72 65 73 0a 20 2a 20 69 73 20 63 72 65 61 74 ures. * is creat
08e0: 65 64 20 66 6f 72 20 65 61 63 68 20 74 68 72 65 ed for each thre
08f0: 61 64 20 74 68 61 74 20 69 73 20 75 73 69 6e 67 ad that is using
0900: 20 74 68 65 20 6e 6f 74 69 66 69 65 72 2e 20 20 the notifier.
0910: 0a 20 2a 2f 0a 0a 74 79 70 65 64 65 66 20 73 74 . */..typedef st
0920: 72 75 63 74 20 54 68 72 65 61 64 53 70 65 63 69 ruct ThreadSpeci
0930: 66 69 63 44 61 74 61 20 7b 0a 20 20 20 20 46 69 ficData {. Fi
0940: 6c 65 48 61 6e 64 6c 65 72 20 2a 66 69 72 73 74 leHandler *first
0950: 46 69 6c 65 48 61 6e 64 6c 65 72 50 74 72 3b 0a FileHandlerPtr;.
0960: 09 09 09 09 2f 2a 20 50 6f 69 6e 74 65 72 20 74 ..../* Pointer t
0970: 6f 20 68 65 61 64 20 6f 66 20 66 69 6c 65 20 68 o head of file h
0980: 61 6e 64 6c 65 72 20 6c 69 73 74 2e 20 2a 2f 0a andler list. */.
0990: 20 20 20 20 0a 20 20 20 20 53 65 6c 65 63 74 4d . SelectM
09a0: 61 73 6b 73 20 63 68 65 63 6b 4d 61 73 6b 73 3b asks checkMasks;
09b0: 09 2f 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 ./* This structu
09c0: 72 65 20 69 73 20 75 73 65 64 20 74 6f 20 62 75 re is used to bu
09d0: 69 6c 64 20 75 70 20 74 68 65 20 6d 61 73 6b 73 ild up the masks
09e0: 0a 09 09 09 09 20 2a 20 74 6f 20 62 65 20 75 73 ..... * to be us
09f0: 65 64 20 69 6e 20 74 68 65 20 6e 65 78 74 20 63 ed in the next c
0a00: 61 6c 6c 20 74 6f 20 73 65 6c 65 63 74 2e 0a 09 all to select...
0a10: 09 09 09 20 2a 20 42 69 74 73 20 61 72 65 20 73 ... * Bits are s
0a20: 65 74 20 69 6e 20 72 65 73 70 6f 6e 73 65 20 74 et in response t
0a30: 6f 20 63 61 6c 6c 73 20 74 6f 0a 09 09 09 09 20 o calls to.....
0a40: 2a 20 54 63 6c 5f 43 72 65 61 74 65 46 69 6c 65 * Tcl_CreateFile
0a50: 48 61 6e 64 6c 65 72 2e 20 2a 2f 0a 20 20 20 20 Handler. */.
0a60: 53 65 6c 65 63 74 4d 61 73 6b 73 20 72 65 61 64 SelectMasks read
0a70: 79 4d 61 73 6b 73 3b 09 2f 2a 20 54 68 69 73 20 yMasks;./* This
0a80: 61 72 72 61 79 20 72 65 66 6c 65 63 74 73 20 74 array reflects t
0a90: 68 65 20 72 65 61 64 61 62 6c 65 2f 77 72 69 74 he readable/writ
0aa0: 61 62 6c 65 0a 09 09 09 09 20 2a 20 63 6f 6e 64 able..... * cond
0ab0: 69 74 69 6f 6e 73 20 74 68 61 74 20 77 65 72 65 itions that were
0ac0: 20 66 6f 75 6e 64 20 74 6f 20 65 78 69 73 74 20 found to exist
0ad0: 62 79 20 74 68 65 0a 09 09 09 09 20 2a 20 6c 61 by the..... * la
0ae0: 73 74 20 63 61 6c 6c 20 74 6f 20 73 65 6c 65 63 st call to selec
0af0: 74 2e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 75 t. */. int nu
0b00: 6d 46 64 42 69 74 73 3b 09 09 2f 2a 20 4e 75 6d mFdBits;../* Num
0b10: 62 65 72 20 6f 66 20 76 61 6c 69 64 20 62 69 74 ber of valid bit
0b20: 73 20 69 6e 20 63 68 65 63 6b 4d 61 73 6b 73 0a s in checkMasks.
0b30: 09 09 09 09 20 2a 20 28 6f 6e 65 20 6d 6f 72 65 .... * (one more
0b40: 20 74 68 61 6e 20 68 69 67 68 65 73 74 20 66 64 than highest fd
0b50: 20 66 6f 72 20 77 68 69 63 68 0a 09 09 09 09 20 for which.....
0b60: 2a 20 54 63 6c 5f 57 61 74 63 68 46 69 6c 65 20 * Tcl_WatchFile
0b70: 68 61 73 20 62 65 65 6e 20 63 61 6c 6c 65 64 29 has been called)
0b80: 2e 20 2a 2f 0a 23 69 66 64 65 66 20 54 43 4c 5f . */.#ifdef TCL_
0b90: 54 48 52 45 41 44 53 0a 20 20 20 20 69 6e 74 20 THREADS. int
0ba0: 6f 6e 4c 69 73 74 3b 09 09 09 2f 2a 20 54 72 75 onList;.../* Tru
0bb0: 65 20 69 66 20 69 74 20 69 73 20 69 6e 20 74 68 e if it is in th
0bc0: 69 73 20 6c 69 73 74 20 2a 2f 0a 20 20 20 20 75 is list */. u
0bd0: 6e 73 69 67 6e 65 64 20 69 6e 74 20 70 6f 6c 6c nsigned int poll
0be0: 53 74 61 74 65 3b 09 2f 2a 20 70 6f 6c 6c 53 74 State;./* pollSt
0bf0: 61 74 65 20 69 73 20 75 73 65 64 20 74 6f 20 69 ate is used to i
0c00: 6d 70 6c 65 6d 65 6e 74 20 61 20 70 6f 6c 6c 69 mplement a polli
0c10: 6e 67 20 0a 09 09 09 09 20 2a 20 68 61 6e 64 73 ng ..... * hands
0c20: 68 61 6b 65 20 62 65 74 77 65 65 6e 20 65 61 63 hake between eac
0c30: 68 20 74 68 72 65 61 64 20 61 6e 64 20 74 68 65 h thread and the
0c40: 0a 09 09 09 09 20 2a 20 6e 6f 74 69 66 69 65 72 ..... * notifier
0c50: 20 74 68 72 65 61 64 2e 20 42 69 74 73 20 64 65 thread. Bits de
0c60: 66 69 6e 65 64 20 62 65 6c 6f 77 2e 20 2a 2f 0a fined below. */.
0c70: 20 20 20 20 73 74 72 75 63 74 20 54 68 72 65 61 struct Threa
0c80: 64 53 70 65 63 69 66 69 63 44 61 74 61 20 2a 6e dSpecificData *n
0c90: 65 78 74 50 74 72 2c 20 2a 70 72 65 76 50 74 72 extPtr, *prevPtr
0ca0: 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;.
0cb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0cc0: 20 20 2f 2a 20 41 6c 6c 20 74 68 72 65 61 64 73 /* All threads
0cd0: 20 74 68 61 74 20 61 72 65 20 63 75 72 72 65 6e that are curren
0ce0: 74 6c 79 20 77 61 69 74 69 6e 67 20 6f 6e 20 0a tly waiting on .
0cf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d10: 20 2a 20 61 6e 20 65 76 65 6e 74 20 68 61 76 65 * an event have
0d20: 20 74 68 65 69 72 20 54 68 72 65 61 64 53 70 65 their ThreadSpe
0d30: 63 69 66 69 63 44 61 74 61 0a 20 20 20 20 20 20 cificData.
0d40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0d50: 20 20 20 20 20 20 20 20 20 20 20 2a 20 73 74 72 * str
0d60: 75 63 74 75 72 65 20 6f 6e 20 61 20 64 6f 75 62 ucture on a doub
0d70: 6c 79 2d 6c 69 6e 6b 65 64 20 6c 69 73 74 65 64 ly-linked listed
0d80: 20 66 6f 72 6d 65 64 0a 20 20 20 20 20 20 20 20 formed.
0d90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0da0: 20 20 20 20 20 20 20 20 20 2a 20 66 72 6f 6d 20 * from
0db0: 74 68 65 73 65 20 70 6f 69 6e 74 65 72 73 2e 20 these pointers.
0dc0: 20 59 6f 75 20 6d 75 73 74 20 68 6f 6c 64 20 74 You must hold t
0dd0: 68 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 he.
0de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0df0: 20 20 20 20 2a 20 6e 6f 74 69 66 69 65 72 4d 75 * notifierMu
0e00: 74 65 78 20 6c 6f 63 6b 20 62 65 66 6f 72 65 20 tex lock before
0e10: 61 63 63 65 73 73 69 6e 67 20 74 68 65 73 65 0a accessing these.
0e20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0e30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0e40: 20 2a 20 66 69 65 6c 64 73 2e 20 2a 2f 0a 20 20 * fields. */.
0e50: 20 20 54 63 6c 5f 43 6f 6e 64 69 74 69 6f 6e 20 Tcl_Condition
0e60: 77 61 69 74 43 56 3b 20 20 20 20 20 2f 2a 20 41 waitCV; /* A
0e70: 6e 79 20 6f 74 68 65 72 20 74 68 72 65 61 64 20 ny other thread
0e80: 61 6c 65 72 74 73 20 61 20 6e 6f 74 69 66 69 65 alerts a notifie
0e90: 72 0a 09 09 09 09 20 2a 20 74 68 61 74 20 61 6e r..... * that an
0ea0: 20 65 76 65 6e 74 20 69 73 20 72 65 61 64 79 20 event is ready
0eb0: 74 6f 20 62 65 20 70 72 6f 63 65 73 73 65 64 0a to be processed.
0ec0: 09 09 09 09 20 2a 20 62 79 20 73 69 67 6e 61 6c .... * by signal
0ed0: 69 6e 67 20 74 68 69 73 20 63 6f 6e 64 69 74 69 ing this conditi
0ee0: 6f 6e 20 76 61 72 69 61 62 6c 65 2e 20 2a 2f 0a on variable. */.
0ef0: 20 20 20 20 69 6e 74 20 65 76 65 6e 74 52 65 61 int eventRea
0f00: 64 79 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a dy; /*
0f10: 20 54 72 75 65 20 69 66 20 61 6e 20 65 76 65 6e True if an even
0f20: 74 20 69 73 20 72 65 61 64 79 20 74 6f 20 62 65 t is ready to be
0f30: 20 70 72 6f 63 65 73 73 65 64 2e 0a 20 20 20 20 processed..
0f40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0f50: 20 20 20 20 20 20 20 20 20 20 20 2a 20 55 73 65 * Use
0f60: 64 20 61 73 20 63 6f 6e 64 69 74 69 6f 6e 20 66 d as condition f
0f70: 6c 61 67 20 74 6f 67 65 74 68 65 72 20 77 69 74 lag together wit
0f80: 68 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 h.
0f90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0fa0: 20 2a 20 77 61 69 74 43 56 20 61 62 6f 76 65 2e * waitCV above.
0fb0: 20 2a 2f 0a 23 65 6e 64 69 66 0a 7d 20 54 68 72 */.#endif.} Thr
0fc0: 65 61 64 53 70 65 63 69 66 69 63 44 61 74 61 3b eadSpecificData;
0fd0: 0a 0a 73 74 61 74 69 63 20 54 63 6c 5f 54 68 72 ..static Tcl_Thr
0fe0: 65 61 64 44 61 74 61 4b 65 79 20 64 61 74 61 4b eadDataKey dataK
0ff0: 65 79 3b 0a 0a 23 69 66 64 65 66 20 54 43 4c 5f ey;..#ifdef TCL_
1000: 54 48 52 45 41 44 53 0a 2f 2a 0a 20 2a 20 54 68 THREADS./*. * Th
1010: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 61 74 e following stat
1020: 69 63 20 69 6e 64 69 63 61 74 65 73 20 74 68 65 ic indicates the
1030: 20 6e 75 6d 62 65 72 20 6f 66 20 74 68 72 65 61 number of threa
1040: 64 73 20 74 68 61 74 20 68 61 76 65 0a 20 2a 20 ds that have. *
1050: 69 6e 69 74 69 61 6c 69 7a 65 64 20 6e 6f 74 69 initialized noti
1060: 66 69 65 72 73 2e 0a 20 2a 0a 20 2a 20 59 6f 75 fiers.. *. * You
1070: 20 6d 75 73 74 20 68 6f 6c 64 20 74 68 65 20 6e must hold the n
1080: 6f 74 69 66 69 65 72 4d 75 74 65 78 20 6c 6f 63 otifierMutex loc
1090: 6b 20 62 65 66 6f 72 65 20 61 63 63 65 73 73 69 k before accessi
10a0: 6e 67 20 74 68 69 73 20 76 61 72 69 61 62 6c 65 ng this variable
10b0: 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e .. */..static in
10c0: 74 20 6e 6f 74 69 66 69 65 72 43 6f 75 6e 74 20 t notifierCount
10d0: 3d 20 30 3b 0a 0a 2f 2a 0a 20 2a 20 54 68 65 20 = 0;../*. * The
10e0: 66 6f 6c 6c 6f 77 69 6e 67 20 76 61 72 69 61 62 following variab
10f0: 6c 65 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 le points to the
1100: 20 68 65 61 64 20 6f 66 20 61 20 64 6f 75 62 6c head of a doubl
1110: 79 2d 6c 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 y-linked list of
1120: 20 0a 20 2a 20 6f 66 20 54 68 72 65 61 64 53 70 . * of ThreadSp
1130: 65 63 69 66 69 63 44 61 74 61 20 73 74 72 75 63 ecificData struc
1140: 74 75 72 65 73 20 66 6f 72 20 61 6c 6c 20 74 68 tures for all th
1150: 72 65 61 64 73 20 74 68 61 74 20 61 72 65 20 63 reads that are c
1160: 75 72 72 65 6e 74 6c 79 0a 20 2a 20 77 61 69 74 urrently. * wait
1170: 69 6e 67 20 6f 6e 20 61 6e 20 65 76 65 6e 74 2e ing on an event.
1180: 0a 20 2a 0a 20 2a 20 59 6f 75 20 6d 75 73 74 20 . *. * You must
1190: 68 6f 6c 64 20 74 68 65 20 6e 6f 74 69 66 69 65 hold the notifie
11a0: 72 4d 75 74 65 78 20 6c 6f 63 6b 20 62 65 66 6f rMutex lock befo
11b0: 72 65 20 61 63 63 65 73 73 69 6e 67 20 74 68 69 re accessing thi
11c0: 73 20 6c 69 73 74 2e 0a 20 2a 2f 0a 0a 73 74 61 s list.. */..sta
11d0: 74 69 63 20 54 68 72 65 61 64 53 70 65 63 69 66 tic ThreadSpecif
11e0: 69 63 44 61 74 61 20 2a 77 61 69 74 69 6e 67 4c icData *waitingL
11f0: 69 73 74 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 0a istPtr = NULL;..
1200: 2f 2a 0a 20 2a 20 54 68 65 20 6e 6f 74 69 66 69 /*. * The notifi
1210: 65 72 20 74 68 72 65 61 64 20 73 70 65 6e 64 73 er thread spends
1220: 20 61 6c 6c 20 69 74 73 20 74 69 6d 65 20 69 6e all its time in
1230: 20 73 65 6c 65 63 74 28 29 20 77 61 69 74 69 6e select() waitin
1240: 67 20 66 6f 72 20 61 0a 20 2a 20 66 69 6c 65 20 g for a. * file
1250: 64 65 73 63 72 69 70 74 6f 72 20 61 73 73 6f 63 descriptor assoc
1260: 69 61 74 65 64 20 77 69 74 68 20 6f 6e 65 20 6f iated with one o
1270: 66 20 74 68 65 20 74 68 72 65 61 64 73 20 6f 6e f the threads on
1280: 20 74 68 65 20 77 61 69 74 69 6e 67 4c 69 73 74 the waitingList
1290: 50 74 72 0a 20 2a 20 6c 69 73 74 20 74 6f 20 64 Ptr. * list to d
12a0: 6f 20 73 6f 6d 65 74 68 69 6e 67 20 69 6e 74 65 o something inte
12b0: 72 65 73 74 69 6e 67 2e 20 20 42 75 74 20 69 66 resting. But if
12c0: 20 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66 the contents of
12d0: 20 74 68 65 0a 20 2a 20 77 61 69 74 69 6e 67 4c the. * waitingL
12e0: 69 73 74 50 74 72 20 6c 69 73 74 20 65 76 65 72 istPtr list ever
12f0: 20 63 68 61 6e 67 65 73 2c 20 77 65 20 6e 65 65 changes, we nee
1300: 64 20 74 6f 20 77 61 6b 65 20 75 70 20 61 6e 64 d to wake up and
1310: 20 72 65 73 74 61 72 74 0a 20 2a 20 74 68 65 20 restart. * the
1320: 73 65 6c 65 63 74 28 29 20 73 79 73 74 65 6d 20 select() system
1330: 63 61 6c 6c 2e 20 20 59 6f 75 20 63 61 6e 20 77 call. You can w
1340: 61 6b 65 20 75 70 20 74 68 65 20 6e 6f 74 69 66 ake up the notif
1350: 69 65 72 20 74 68 72 65 61 64 20 62 79 0a 20 2a ier thread by. *
1360: 20 77 72 69 74 69 6e 67 20 61 20 73 69 6e 67 6c writing a singl
1370: 65 20 62 79 74 65 20 74 6f 20 74 68 65 20 66 69 e byte to the fi
1380: 6c 65 20 64 65 73 63 72 69 70 74 6f 72 20 64 65 le descriptor de
1390: 66 69 6e 65 64 20 62 65 6c 6f 77 2e 20 20 54 68 fined below. Th
13a0: 69 73 0a 20 2a 20 66 69 6c 65 20 64 65 73 63 72 is. * file descr
13b0: 69 70 74 6f 72 20 69 73 20 74 68 65 20 69 6e 70 iptor is the inp
13c0: 75 74 2d 65 6e 64 20 6f 66 20 61 20 70 69 70 65 ut-end of a pipe
13d0: 20 61 6e 64 20 74 68 65 20 6e 6f 74 69 66 69 65 and the notifie
13e0: 72 20 74 68 72 65 61 64 20 69 73 0a 20 2a 20 6c r thread is. * l
13f0: 69 73 74 65 6e 69 6e 67 20 66 6f 72 20 64 61 74 istening for dat
1400: 61 20 6f 6e 20 74 68 65 20 6f 75 74 70 75 74 2d a on the output-
1410: 65 6e 64 20 6f 66 20 74 68 65 20 73 61 6d 65 20 end of the same
1420: 70 69 70 65 2e 20 20 48 65 6e 63 65 20 77 72 69 pipe. Hence wri
1430: 74 69 6e 67 0a 20 2a 20 74 6f 20 74 68 69 73 20 ting. * to this
1440: 66 69 6c 65 20 64 65 73 63 72 69 70 74 6f 72 20 file descriptor
1450: 77 69 6c 6c 20 63 61 75 73 65 20 74 68 65 20 73 will cause the s
1460: 65 6c 65 63 74 28 29 20 73 79 73 74 65 6d 20 63 elect() system c
1470: 61 6c 6c 20 74 6f 20 72 65 74 75 72 6e 0a 20 2a all to return. *
1480: 20 61 6e 64 20 77 61 6b 65 20 75 70 20 74 68 65 and wake up the
1490: 20 6e 6f 74 69 66 69 65 72 20 74 68 72 65 61 64 notifier thread
14a0: 2e 0a 20 2a 0a 20 2a 20 59 6f 75 20 6d 75 73 74 .. *. * You must
14b0: 20 68 6f 6c 64 20 74 68 65 20 6e 6f 74 69 66 69 hold the notifi
14c0: 65 72 4d 75 74 65 78 20 6c 6f 63 6b 20 62 65 66 erMutex lock bef
14d0: 6f 72 65 20 61 63 63 65 73 73 69 6e 67 20 74 68 ore accessing th
14e0: 69 73 20 6c 69 73 74 2e 0a 20 2a 2f 0a 0a 73 74 is list.. */..st
14f0: 61 74 69 63 20 69 6e 74 20 74 72 69 67 67 65 72 atic int trigger
1500: 50 69 70 65 20 3d 20 2d 31 3b 0a 0a 2f 2a 0a 20 Pipe = -1;../*.
1510: 2a 20 54 68 65 20 6e 6f 74 69 66 69 65 72 4d 75 * The notifierMu
1520: 74 65 78 20 6c 6f 63 6b 73 20 61 63 63 65 73 73 tex locks access
1530: 20 74 6f 20 61 6c 6c 20 6f 66 20 74 68 65 20 67 to all of the g
1540: 6c 6f 62 61 6c 20 6e 6f 74 69 66 69 65 72 20 73 lobal notifier s
1550: 74 61 74 65 2e 20 0a 20 2a 2f 0a 0a 54 43 4c 5f tate. . */..TCL_
1560: 44 45 43 4c 41 52 45 5f 4d 55 54 45 58 28 6e 6f DECLARE_MUTEX(no
1570: 74 69 66 69 65 72 4d 75 74 65 78 29 0a 0a 2f 2a tifierMutex)../*
1580: 0a 20 2a 20 54 68 65 20 6e 6f 74 69 66 69 65 72 . * The notifier
1590: 20 74 68 72 65 61 64 20 73 69 67 6e 61 6c 73 20 thread signals
15a0: 74 68 65 20 6e 6f 74 69 66 69 65 72 43 56 20 77 the notifierCV w
15b0: 68 65 6e 20 69 74 20 68 61 73 20 66 69 6e 69 73 hen it has finis
15c0: 68 65 64 0a 20 2a 20 69 6e 69 74 69 61 6c 69 7a hed. * initializ
15d0: 69 6e 67 20 74 68 65 20 74 72 69 67 67 65 72 50 ing the triggerP
15e0: 69 70 65 20 61 6e 64 20 72 69 67 68 74 20 62 65 ipe and right be
15f0: 66 6f 72 65 20 74 68 65 20 6e 6f 74 69 66 69 65 fore the notifie
1600: 72 0a 20 2a 20 74 68 72 65 61 64 20 74 65 72 6d r. * thread term
1610: 69 6e 61 74 65 73 2e 0a 20 2a 2f 0a 0a 73 74 61 inates.. */..sta
1620: 74 69 63 20 54 63 6c 5f 43 6f 6e 64 69 74 69 6f tic Tcl_Conditio
1630: 6e 20 6e 6f 74 69 66 69 65 72 43 56 3b 0a 0a 2f n notifierCV;../
1640: 2a 0a 20 2a 20 54 68 65 20 70 6f 6c 6c 53 74 61 *. * The pollSta
1650: 74 65 20 62 69 74 73 0a 20 2a 09 50 4f 4c 4c 5f te bits. *.POLL_
1660: 57 41 4e 54 20 69 73 20 73 65 74 20 62 79 20 65 WANT is set by e
1670: 61 63 68 20 74 68 72 65 61 64 20 62 65 66 6f 72 ach thread befor
1680: 65 20 69 74 20 77 61 69 74 73 20 6f 6e 20 69 74 e it waits on it
1690: 73 20 63 6f 6e 64 69 74 69 6f 6e 0a 20 2a 09 09 s condition. *..
16a0: 76 61 72 69 61 62 6c 65 2e 20 20 49 74 20 69 73 variable. It is
16b0: 20 63 68 65 63 6b 65 64 20 62 79 20 74 68 65 20 checked by the
16c0: 6e 6f 74 69 66 69 65 72 20 62 65 66 6f 72 65 20 notifier before
16d0: 69 74 20 64 6f 65 73 0a 20 2a 09 09 73 65 6c 65 it does. *..sele
16e0: 63 74 2e 0a 20 2a 09 50 4f 4c 4c 5f 44 4f 4e 45 ct.. *.POLL_DONE
16f0: 20 69 73 20 73 65 74 20 62 79 20 74 68 65 20 6e is set by the n
1700: 6f 74 69 66 69 65 72 20 69 66 20 69 74 20 67 6f otifier if it go
1710: 65 73 20 69 6e 74 6f 20 73 65 6c 65 63 74 20 61 es into select a
1720: 66 74 65 72 0a 20 2a 09 09 73 65 65 69 6e 67 20 fter. *..seeing
1730: 50 4f 4c 4c 5f 57 41 4e 54 2e 20 20 54 68 65 20 POLL_WANT. The
1740: 69 64 65 61 20 69 73 20 74 6f 20 65 6e 73 75 72 idea is to ensur
1750: 65 20 69 74 20 74 72 69 65 73 20 61 20 73 65 6c e it tries a sel
1760: 65 63 74 0a 20 2a 09 09 77 69 74 68 20 74 68 65 ect. *..with the
1770: 20 73 61 6d 65 20 62 69 74 73 20 74 68 65 20 69 same bits the i
1780: 6e 69 74 69 61 6c 20 74 68 72 65 61 64 20 68 61 nitial thread ha
1790: 64 20 73 65 74 2e 0a 20 2a 2f 0a 23 64 65 66 69 d set.. */.#defi
17a0: 6e 65 20 50 4f 4c 4c 5f 57 41 4e 54 09 30 78 31 ne POLL_WANT.0x1
17b0: 0a 23 64 65 66 69 6e 65 20 50 4f 4c 4c 5f 44 4f .#define POLL_DO
17c0: 4e 45 09 30 78 32 0a 0a 2f 2a 0a 20 2a 20 54 68 NE.0x2../*. * Th
17d0: 69 73 20 69 73 20 74 68 65 20 74 68 72 65 61 64 is is the thread
17e0: 20 49 44 20 6f 66 20 74 68 65 20 6e 6f 74 69 66 ID of the notif
17f0: 69 65 72 20 74 68 72 65 61 64 20 74 68 61 74 20 ier thread that
1800: 64 6f 65 73 20 73 65 6c 65 63 74 2e 0a 20 2a 2f does select.. */
1810: 0a 73 74 61 74 69 63 20 54 63 6c 5f 54 68 72 65 .static Tcl_Thre
1820: 61 64 49 64 20 6e 6f 74 69 66 69 65 72 54 68 72 adId notifierThr
1830: 65 61 64 3b 0a 0a 23 65 6e 64 69 66 0a 0a 2f 2a ead;..#endif../*
1840: 0a 20 2a 20 53 74 61 74 69 63 20 72 6f 75 74 69 . * Static routi
1850: 6e 65 73 20 64 65 66 69 6e 65 64 20 69 6e 20 74 nes defined in t
1860: 68 69 73 20 66 69 6c 65 2e 0a 20 2a 2f 0a 0a 23 his file.. */..#
1870: 69 66 64 65 66 20 54 43 4c 5f 54 48 52 45 41 44 ifdef TCL_THREAD
1880: 53 0a 73 74 61 74 69 63 20 76 6f 69 64 09 4e 6f S.static void.No
1890: 74 69 66 69 65 72 54 68 72 65 61 64 50 72 6f 63 tifierThreadProc
18a0: 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 43 6c _ANSI_ARGS_((Cl
18b0: 69 65 6e 74 44 61 74 61 20 63 6c 69 65 6e 74 44 ientData clientD
18c0: 61 74 61 29 29 3b 0a 23 65 6e 64 69 66 0a 73 74 ata));.#endif.st
18d0: 61 74 69 63 20 69 6e 74 09 46 69 6c 65 48 61 6e atic int.FileHan
18e0: 64 6c 65 72 45 76 65 6e 74 50 72 6f 63 20 5f 41 dlerEventProc _A
18f0: 4e 53 49 5f 41 52 47 53 5f 28 28 54 63 6c 5f 45 NSI_ARGS_((Tcl_E
1900: 76 65 6e 74 20 2a 65 76 50 74 72 2c 0a 09 09 20 vent *evPtr,...
1910: 20 20 20 69 6e 74 20 66 6c 61 67 73 29 29 3b 0a int flags));.
1920: 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d ../*. *---------
1930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1950: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a -------------. *
1970: 0a 20 2a 20 54 63 6c 5f 49 6e 69 74 4e 6f 74 69 . * Tcl_InitNoti
1980: 66 69 65 72 20 2d 2d 0a 20 2a 0a 20 2a 09 49 6e fier --. *. *.In
1990: 69 74 69 61 6c 69 7a 65 73 20 74 68 65 20 70 6c itializes the pl
19a0: 61 74 66 6f 72 6d 20 73 70 65 63 69 66 69 63 20 atform specific
19b0: 6e 6f 74 69 66 69 65 72 20 73 74 61 74 65 2e 0a notifier state..
19c0: 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 *. * Results:.
19d0: 2a 09 52 65 74 75 72 6e 73 20 61 20 68 61 6e 64 *.Returns a hand
19e0: 6c 65 20 74 6f 20 74 68 65 20 6e 6f 74 69 66 69 le to the notifi
19f0: 65 72 20 73 74 61 74 65 20 66 6f 72 20 74 68 69 er state for thi
1a00: 73 20 74 68 72 65 61 64 2e 2e 0a 20 2a 0a 20 2a s thread... *. *
1a10: 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 Side effects:.
1a20: 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d *.None.. *. *---
1a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1a60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1a70: 2d 2d 2d 0a 20 2a 2f 0a 0a 43 6c 69 65 6e 74 44 ---. */..ClientD
1a80: 61 74 61 0a 54 63 6c 5f 49 6e 69 74 4e 6f 74 69 ata.Tcl_InitNoti
1a90: 66 69 65 72 28 29 0a 7b 0a 20 20 20 20 54 68 72 fier().{. Thr
1aa0: 65 61 64 53 70 65 63 69 66 69 63 44 61 74 61 20 eadSpecificData
1ab0: 2a 74 73 64 50 74 72 20 3d 20 54 43 4c 5f 54 53 *tsdPtr = TCL_TS
1ac0: 44 5f 49 4e 49 54 28 26 64 61 74 61 4b 65 79 29 D_INIT(&dataKey)
1ad0: 3b 0a 0a 23 69 66 64 65 66 20 54 43 4c 5f 54 48 ;..#ifdef TCL_TH
1ae0: 52 45 41 44 53 0a 20 20 20 20 74 73 64 50 74 72 READS. tsdPtr
1af0: 2d 3e 65 76 65 6e 74 52 65 61 64 79 20 3d 20 30 ->eventReady = 0
1b00: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
1b10: 20 53 74 61 72 74 20 74 68 65 20 4e 6f 74 69 66 Start the Notif
1b20: 69 65 72 20 74 68 72 65 61 64 20 69 66 20 6e 65 ier thread if ne
1b30: 63 65 73 73 61 72 79 2e 0a 20 20 20 20 20 2a 2f cessary.. */
1b40: 0a 0a 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c .. Tcl_MutexL
1b50: 6f 63 6b 28 26 6e 6f 74 69 66 69 65 72 4d 75 74 ock(¬ifierMut
1b60: 65 78 29 3b 0a 20 20 20 20 69 66 20 28 6e 6f 74 ex);. if (not
1b70: 69 66 69 65 72 43 6f 75 6e 74 20 3d 3d 20 30 29 ifierCount == 0)
1b80: 20 7b 0a 09 69 66 20 28 54 63 6c 70 54 68 72 65 {..if (TclpThre
1b90: 61 64 43 72 65 61 74 65 28 26 6e 6f 74 69 66 69 adCreate(¬ifi
1ba0: 65 72 54 68 72 65 61 64 2c 20 4e 6f 74 69 66 69 erThread, Notifi
1bb0: 65 72 54 68 72 65 61 64 50 72 6f 63 2c 20 4e 55 erThreadProc, NU
1bc0: 4c 4c 2c 0a 09 09 20 20 20 20 20 54 43 4c 5f 54 LL,... TCL_T
1bd0: 48 52 45 41 44 5f 53 54 41 43 4b 5f 44 45 46 41 HREAD_STACK_DEFA
1be0: 55 4c 54 2c 20 54 43 4c 5f 54 48 52 45 41 44 5f ULT, TCL_THREAD_
1bf0: 4a 4f 49 4e 41 42 4c 45 29 20 21 3d 20 54 43 4c JOINABLE) != TCL
1c00: 5f 4f 4b 29 20 7b 0a 09 20 20 20 20 70 61 6e 69 _OK) {.. pani
1c10: 63 28 22 54 63 6c 5f 49 6e 69 74 4e 6f 74 69 66 c("Tcl_InitNotif
1c20: 69 65 72 3a 20 75 6e 61 62 6c 65 20 74 6f 20 73 ier: unable to s
1c30: 74 61 72 74 20 6e 6f 74 69 66 69 65 72 20 74 68 tart notifier th
1c40: 72 65 61 64 22 29 3b 0a 09 7d 0a 20 20 20 20 7d read");..}. }
1c50: 0a 20 20 20 20 6e 6f 74 69 66 69 65 72 43 6f 75 . notifierCou
1c60: 6e 74 2b 2b 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 nt++;.. /*.
1c70: 20 20 20 2a 20 57 61 69 74 20 66 6f 72 20 74 68 * Wait for th
1c80: 65 20 6e 6f 74 69 66 69 65 72 20 70 69 70 65 20 e notifier pipe
1c90: 74 6f 20 62 65 20 63 72 65 61 74 65 64 2e 0a 20 to be created..
1ca0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 77 68 69 6c */.. whil
1cb0: 65 20 28 74 72 69 67 67 65 72 50 69 70 65 20 3c e (triggerPipe <
1cc0: 20 30 29 20 7b 0a 09 54 63 6c 5f 43 6f 6e 64 69 0) {..Tcl_Condi
1cd0: 74 69 6f 6e 57 61 69 74 28 26 6e 6f 74 69 66 69 tionWait(¬ifi
1ce0: 65 72 43 56 2c 20 26 6e 6f 74 69 66 69 65 72 4d erCV, ¬ifierM
1cf0: 75 74 65 78 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 utex, NULL);.
1d00: 20 7d 0a 0a 20 20 20 20 54 63 6c 5f 4d 75 74 65 }.. Tcl_Mute
1d10: 78 55 6e 6c 6f 63 6b 28 26 6e 6f 74 69 66 69 65 xUnlock(¬ifie
1d20: 72 4d 75 74 65 78 29 3b 0a 23 65 6e 64 69 66 0a rMutex);.#endif.
1d30: 20 20 20 20 72 65 74 75 72 6e 20 28 43 6c 69 65 return (Clie
1d40: 6e 74 44 61 74 61 29 20 74 73 64 50 74 72 3b 0a ntData) tsdPtr;.
1d50: 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d }.../*. *-------
1d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
1da0: 20 2a 0a 20 2a 20 54 63 6c 5f 46 69 6e 61 6c 69 *. * Tcl_Finali
1db0: 7a 65 4e 6f 74 69 66 69 65 72 20 2d 2d 0a 20 2a zeNotifier --. *
1dc0: 0a 20 2a 09 54 68 69 73 20 66 75 6e 63 74 69 6f . *.This functio
1dd0: 6e 20 69 73 20 63 61 6c 6c 65 64 20 74 6f 20 63 n is called to c
1de0: 6c 65 61 6e 75 70 20 74 68 65 20 6e 6f 74 69 66 leanup the notif
1df0: 69 65 72 20 73 74 61 74 65 20 62 65 66 6f 72 65 ier state before
1e00: 0a 20 2a 09 61 20 74 68 72 65 61 64 20 69 73 20 . *.a thread is
1e10: 74 65 72 6d 69 6e 61 74 65 64 2e 0a 20 2a 0a 20 terminated.. *.
1e20: 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 4e 6f * Results:. *.No
1e30: 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 ne.. *. * Side e
1e40: 66 66 65 63 74 73 3a 0a 20 2a 09 4d 61 79 20 74 ffects:. *.May t
1e50: 65 72 6d 69 6e 61 74 65 20 74 68 65 20 62 61 63 erminate the bac
1e60: 6b 67 72 6f 75 6e 64 20 6e 6f 74 69 66 69 65 72 kground notifier
1e70: 20 74 68 72 65 61 64 20 69 66 20 74 68 69 73 20 thread if this
1e80: 69 73 20 74 68 65 0a 20 2a 09 6c 61 73 74 20 6e is the. *.last n
1e90: 6f 74 69 66 69 65 72 20 69 6e 73 74 61 6e 63 65 otifier instance
1ea0: 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d .. *. *---------
1eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1ec0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1ed0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
1ee0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a -------------. *
1ef0: 2f 0a 0a 76 6f 69 64 0a 54 63 6c 5f 46 69 6e 61 /..void.Tcl_Fina
1f00: 6c 69 7a 65 4e 6f 74 69 66 69 65 72 28 63 6c 69 lizeNotifier(cli
1f10: 65 6e 74 44 61 74 61 29 0a 20 20 20 20 43 6c 69 entData). Cli
1f20: 65 6e 74 44 61 74 61 20 63 6c 69 65 6e 74 44 61 entData clientDa
1f30: 74 61 3b 09 09 2f 2a 20 4e 6f 74 20 75 73 65 64 ta;../* Not used
1f40: 2e 20 2a 2f 0a 7b 0a 23 69 66 64 65 66 20 54 43 . */.{.#ifdef TC
1f50: 4c 5f 54 48 52 45 41 44 53 0a 20 20 20 20 54 68 L_THREADS. Th
1f60: 72 65 61 64 53 70 65 63 69 66 69 63 44 61 74 61 readSpecificData
1f70: 20 2a 74 73 64 50 74 72 20 3d 20 54 43 4c 5f 54 *tsdPtr = TCL_T
1f80: 53 44 5f 49 4e 49 54 28 26 64 61 74 61 4b 65 79 SD_INIT(&dataKey
1f90: 29 3b 0a 0a 20 20 20 20 54 63 6c 5f 4d 75 74 65 );.. Tcl_Mute
1fa0: 78 4c 6f 63 6b 28 26 6e 6f 74 69 66 69 65 72 4d xLock(¬ifierM
1fb0: 75 74 65 78 29 3b 0a 20 20 20 20 6e 6f 74 69 66 utex);. notif
1fc0: 69 65 72 43 6f 75 6e 74 2d 2d 3b 0a 0a 20 20 20 ierCount--;..
1fd0: 20 2f 2a 0a 20 20 20 20 20 2a 20 49 66 20 74 68 /*. * If th
1fe0: 69 73 20 69 73 20 74 68 65 20 6c 61 73 74 20 74 is is the last t
1ff0: 68 72 65 61 64 20 74 6f 20 75 73 65 20 74 68 65 hread to use the
2000: 20 6e 6f 74 69 66 69 65 72 2c 20 63 6c 6f 73 65 notifier, close
2010: 20 74 68 65 20 6e 6f 74 69 66 69 65 72 0a 20 20 the notifier.
2020: 20 20 20 2a 20 70 69 70 65 20 61 6e 64 20 77 61 * pipe and wa
2030: 69 74 20 66 6f 72 20 74 68 65 20 62 61 63 6b 67 it for the backg
2040: 72 6f 75 6e 64 20 74 68 72 65 61 64 20 74 6f 20 round thread to
2050: 74 65 72 6d 69 6e 61 74 65 2e 0a 20 20 20 20 20 terminate..
2060: 2a 2f 0a 0a 20 20 20 20 69 66 20 28 6e 6f 74 69 */.. if (noti
2070: 66 69 65 72 43 6f 75 6e 74 20 3d 3d 20 30 29 20 fierCount == 0)
2080: 7b 0a 09 69 6e 74 20 72 65 73 75 6c 74 3b 0a 09 {..int result;..
2090: 69 66 20 28 74 72 69 67 67 65 72 50 69 70 65 20 if (triggerPipe
20a0: 3c 20 30 29 20 7b 0a 09 20 20 20 20 70 61 6e 69 < 0) {.. pani
20b0: 63 28 22 54 63 6c 5f 46 69 6e 61 6c 69 7a 65 4e c("Tcl_FinalizeN
20c0: 6f 74 69 66 69 65 72 3a 20 6e 6f 74 69 66 69 65 otifier: notifie
20d0: 72 20 70 69 70 65 20 6e 6f 74 20 69 6e 69 74 69 r pipe not initi
20e0: 61 6c 69 7a 65 64 22 29 3b 0a 09 7d 0a 0a 09 2f alized");..}.../
20f0: 2a 0a 09 20 2a 20 53 65 6e 64 20 22 71 22 20 6d *.. * Send "q" m
2100: 65 73 73 61 67 65 20 74 6f 20 74 68 65 20 6e 6f essage to the no
2110: 74 69 66 69 65 72 20 74 68 72 65 61 64 20 73 6f tifier thread so
2120: 20 74 68 61 74 20 69 74 20 77 69 6c 6c 0a 09 20 that it will..
2130: 2a 20 74 65 72 6d 69 6e 61 74 65 2e 20 20 54 68 * terminate. Th
2140: 65 20 6e 6f 74 69 66 69 65 72 20 77 69 6c 6c 20 e notifier will
2150: 72 65 74 75 72 6e 20 66 72 6f 6d 20 69 74 73 20 return from its
2160: 63 61 6c 6c 20 74 6f 20 73 65 6c 65 63 74 28 29 call to select()
2170: 0a 09 20 2a 20 61 6e 64 20 6e 6f 74 69 63 65 20 .. * and notice
2180: 74 68 61 74 20 61 20 22 71 22 20 6d 65 73 73 61 that a "q" messa
2190: 67 65 20 68 61 73 20 61 72 72 69 76 65 64 2c 20 ge has arrived,
21a0: 69 74 20 77 69 6c 6c 20 74 68 65 6e 20 63 6c 6f it will then clo
21b0: 73 65 0a 09 20 2a 20 69 74 73 20 73 69 64 65 20 se.. * its side
21c0: 6f 66 20 74 68 65 20 70 69 70 65 20 61 6e 64 20 of the pipe and
21d0: 74 65 72 6d 69 6e 61 74 65 20 69 74 73 20 74 68 terminate its th
21e0: 72 65 61 64 2e 20 20 4e 6f 74 65 20 74 68 65 20 read. Note the
21f0: 77 65 20 63 61 6e 0a 09 20 2a 20 6e 6f 74 20 6a we can.. * not j
2200: 75 73 74 20 63 6c 6f 73 65 20 74 68 65 20 70 69 ust close the pi
2210: 70 65 20 61 6e 64 20 63 68 65 63 6b 20 66 6f 72 pe and check for
2220: 20 45 4f 46 20 69 6e 20 74 68 65 20 6e 6f 74 69 EOF in the noti
2230: 66 69 65 72 0a 09 20 2a 20 74 68 72 65 61 64 20 fier.. * thread
2240: 62 65 63 61 75 73 65 20 69 66 20 61 20 62 61 63 because if a bac
2250: 6b 67 72 6f 75 6e 64 20 63 68 69 6c 64 20 70 72 kground child pr
2260: 6f 63 65 73 73 20 77 61 73 20 63 72 65 61 74 65 ocess was create
2270: 64 20 77 69 74 68 0a 09 20 2a 20 65 78 65 63 2c d with.. * exec,
2280: 20 73 65 6c 65 63 74 28 29 20 77 6f 75 6c 64 20 select() would
2290: 6e 6f 74 20 72 65 67 69 73 74 65 72 20 74 68 65 not register the
22a0: 20 45 4f 46 20 6f 6e 20 74 68 65 20 70 69 70 65 EOF on the pipe
22b0: 20 75 6e 74 69 6c 20 74 68 65 0a 09 20 2a 20 63 until the.. * c
22c0: 68 69 6c 64 20 70 72 6f 63 65 73 73 65 73 20 68 hild processes h
22d0: 61 64 20 74 65 72 6d 69 6e 61 74 65 64 2e 20 5b ad terminated. [
22e0: 42 75 67 3a 20 34 31 33 39 5d 20 5b 42 75 67 3a Bug: 4139] [Bug:
22f0: 20 31 32 32 32 38 37 32 5d 0a 09 20 2a 2f 0a 0a 1222872].. */..
2300: 09 77 72 69 74 65 28 74 72 69 67 67 65 72 50 69 .write(triggerPi
2310: 70 65 2c 20 22 71 22 2c 20 31 29 3b 0a 09 63 6c pe, "q", 1);..cl
2320: 6f 73 65 28 74 72 69 67 67 65 72 50 69 70 65 29 ose(triggerPipe)
2330: 3b 0a 09 77 68 69 6c 65 28 74 72 69 67 67 65 72 ;..while(trigger
2340: 50 69 70 65 20 3e 3d 20 30 29 20 7b 0a 09 20 20 Pipe >= 0) {..
2350: 20 20 54 63 6c 5f 43 6f 6e 64 69 74 69 6f 6e 57 Tcl_ConditionW
2360: 61 69 74 28 26 6e 6f 74 69 66 69 65 72 43 56 2c ait(¬ifierCV,
2370: 20 26 6e 6f 74 69 66 69 65 72 4d 75 74 65 78 2c ¬ifierMutex,
2380: 20 4e 55 4c 4c 29 3b 0a 09 7d 0a 09 72 65 73 75 NULL);..}..resu
2390: 6c 74 20 3d 20 54 63 6c 5f 4a 6f 69 6e 54 68 72 lt = Tcl_JoinThr
23a0: 65 61 64 28 6e 6f 74 69 66 69 65 72 54 68 72 65 ead(notifierThre
23b0: 61 64 2c 20 4e 55 4c 4c 29 3b 0a 09 69 66 20 28 ad, NULL);..if (
23c0: 72 65 73 75 6c 74 29 20 7b 0a 09 20 20 20 20 54 result) {.. T
23d0: 63 6c 5f 50 61 6e 69 63 28 22 54 63 6c 5f 46 69 cl_Panic("Tcl_Fi
23e0: 6e 61 6c 69 7a 65 4e 6f 74 69 66 69 65 72 3a 20 nalizeNotifier:
23f0: 75 6e 61 62 6c 65 20 74 6f 20 6a 6f 69 6e 20 6e unable to join n
2400: 6f 74 69 66 69 65 72 20 74 68 72 65 61 64 22 29 otifier thread")
2410: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 ;..}. }..
2420: 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 65 61 6e 20 /*. * Clean
2430: 75 70 20 61 6e 79 20 73 79 6e 63 68 72 6f 6e 69 up any synchroni
2440: 7a 61 74 69 6f 6e 20 6f 62 6a 65 63 74 73 20 69 zation objects i
2450: 6e 20 74 68 65 20 74 68 72 65 61 64 20 6c 6f 63 n the thread loc
2460: 61 6c 20 73 74 6f 72 61 67 65 2e 0a 20 20 20 20 al storage..
2470: 20 2a 2f 0a 0a 20 20 20 20 54 63 6c 5f 43 6f 6e */.. Tcl_Con
2480: 64 69 74 69 6f 6e 46 69 6e 61 6c 69 7a 65 28 26 ditionFinalize(&
2490: 28 74 73 64 50 74 72 2d 3e 77 61 69 74 43 56 29 (tsdPtr->waitCV)
24a0: 29 3b 0a 0a 20 20 20 20 54 63 6c 5f 4d 75 74 65 );.. Tcl_Mute
24b0: 78 55 6e 6c 6f 63 6b 28 26 6e 6f 74 69 66 69 65 xUnlock(¬ifie
24c0: 72 4d 75 74 65 78 29 3b 0a 23 65 6e 64 69 66 0a rMutex);.#endif.
24d0: 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d }.../*. *-------
24e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
24f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2510: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
2520: 20 2a 0a 20 2a 20 54 63 6c 5f 41 6c 65 72 74 4e *. * Tcl_AlertN
2530: 6f 74 69 66 69 65 72 20 2d 2d 0a 20 2a 0a 20 2a otifier --. *. *
2540: 09 57 61 6b 65 20 75 70 20 74 68 65 20 73 70 65 .Wake up the spe
2550: 63 69 66 69 65 64 20 6e 6f 74 69 66 69 65 72 20 cified notifier
2560: 66 72 6f 6d 20 61 6e 79 20 74 68 72 65 61 64 2e from any thread.
2570: 20 54 68 69 73 20 72 6f 75 74 69 6e 65 0a 20 2a This routine. *
2580: 09 69 73 20 63 61 6c 6c 65 64 20 62 79 20 74 68 .is called by th
2590: 65 20 70 6c 61 74 66 6f 72 6d 20 69 6e 64 65 70 e platform indep
25a0: 65 6e 64 65 6e 74 20 6e 6f 74 69 66 69 65 72 20 endent notifier
25b0: 63 6f 64 65 20 77 68 65 6e 65 76 65 72 0a 20 2a code whenever. *
25c0: 09 74 68 65 20 54 63 6c 5f 54 68 72 65 61 64 41 .the Tcl_ThreadA
25d0: 6c 65 72 74 20 72 6f 75 74 69 6e 65 20 69 73 20 lert routine is
25e0: 63 61 6c 6c 65 64 2e 20 20 54 68 69 73 20 72 6f called. This ro
25f0: 75 74 69 6e 65 20 69 73 0a 20 2a 09 67 75 61 72 utine is. *.guar
2600: 61 6e 74 65 65 64 20 6e 6f 74 20 74 6f 20 62 65 anteed not to be
2610: 20 63 61 6c 6c 65 64 20 6f 6e 20 61 20 67 69 76 called on a giv
2620: 65 6e 20 6e 6f 74 69 66 69 65 72 20 61 66 74 65 en notifier afte
2630: 72 0a 20 2a 09 54 63 6c 5f 46 69 6e 61 6c 69 7a r. *.Tcl_Finaliz
2640: 65 4e 6f 74 69 66 69 65 72 20 69 73 20 63 61 6c eNotifier is cal
2650: 6c 65 64 20 66 6f 72 20 74 68 61 74 20 6e 6f 74 led for that not
2660: 69 66 69 65 72 2e 0a 20 2a 0a 20 2a 20 52 65 73 ifier.. *. * Res
2670: 75 6c 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 ults:. *.None..
2680: 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 *. * Side effect
2690: 73 3a 0a 20 2a 09 53 69 67 6e 61 6c 73 20 74 68 s:. *.Signals th
26a0: 65 20 6e 6f 74 69 66 69 65 72 20 63 6f 6e 64 69 e notifier condi
26b0: 74 69 6f 6e 20 76 61 72 69 61 62 6c 65 20 66 6f tion variable fo
26c0: 72 20 74 68 65 20 73 70 65 63 69 66 69 65 64 0a r the specified.
26d0: 20 2a 09 6e 6f 74 69 66 69 65 72 2e 0a 20 2a 0a *.notifier.. *.
26e0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *--------------
26f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2700: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2710: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2720: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 76 6f --------. */..vo
2730: 69 64 0a 54 63 6c 5f 41 6c 65 72 74 4e 6f 74 69 id.Tcl_AlertNoti
2740: 66 69 65 72 28 63 6c 69 65 6e 74 44 61 74 61 29 fier(clientData)
2750: 0a 20 20 20 20 43 6c 69 65 6e 74 44 61 74 61 20 . ClientData
2760: 63 6c 69 65 6e 74 44 61 74 61 3b 0a 7b 0a 23 69 clientData;.{.#i
2770: 66 64 65 66 20 54 43 4c 5f 54 48 52 45 41 44 53 fdef TCL_THREADS
2780: 0a 20 20 20 20 54 68 72 65 61 64 53 70 65 63 69 . ThreadSpeci
2790: 66 69 63 44 61 74 61 20 2a 74 73 64 50 74 72 20 ficData *tsdPtr
27a0: 3d 20 28 54 68 72 65 61 64 53 70 65 63 69 66 69 = (ThreadSpecifi
27b0: 63 44 61 74 61 20 2a 29 20 63 6c 69 65 6e 74 44 cData *) clientD
27c0: 61 74 61 3b 0a 20 20 20 20 54 63 6c 5f 4d 75 74 ata;. Tcl_Mut
27d0: 65 78 4c 6f 63 6b 28 26 6e 6f 74 69 66 69 65 72 exLock(¬ifier
27e0: 4d 75 74 65 78 29 3b 0a 20 20 20 20 74 73 64 50 Mutex);. tsdP
27f0: 74 72 2d 3e 65 76 65 6e 74 52 65 61 64 79 20 3d tr->eventReady =
2800: 20 31 3b 0a 20 20 20 20 54 63 6c 5f 43 6f 6e 64 1;. Tcl_Cond
2810: 69 74 69 6f 6e 4e 6f 74 69 66 79 28 26 74 73 64 itionNotify(&tsd
2820: 50 74 72 2d 3e 77 61 69 74 43 56 29 3b 0a 20 20 Ptr->waitCV);.
2830: 20 20 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 Tcl_MutexUnloc
2840: 6b 28 26 6e 6f 74 69 66 69 65 72 4d 75 74 65 78 k(¬ifierMutex
2850: 29 3b 0a 23 65 6e 64 69 66 0a 7d 0a 0c 0a 2f 2a );.#endif.}.../*
2860: 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d . *-------------
2870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2890: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
28a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 ---------. *. *
28b0: 54 63 6c 5f 53 65 74 54 69 6d 65 72 20 2d 2d 0a Tcl_SetTimer --.
28c0: 20 2a 0a 20 2a 09 54 68 69 73 20 70 72 6f 63 65 *. *.This proce
28d0: 64 75 72 65 20 73 65 74 73 20 74 68 65 20 63 75 dure sets the cu
28e0: 72 72 65 6e 74 20 6e 6f 74 69 66 69 65 72 20 74 rrent notifier t
28f0: 69 6d 65 72 20 76 61 6c 75 65 2e 20 20 54 68 69 imer value. Thi
2900: 73 0a 20 2a 09 69 6e 74 65 72 66 61 63 65 20 69 s. *.interface i
2910: 73 20 6e 6f 74 20 69 6d 70 6c 65 6d 65 6e 74 65 s not implemente
2920: 64 20 69 6e 20 74 68 69 73 20 6e 6f 74 69 66 69 d in this notifi
2930: 65 72 20 62 65 63 61 75 73 65 20 77 65 20 61 72 er because we ar
2940: 65 0a 20 2a 09 61 6c 77 61 79 73 20 72 75 6e 6e e. *.always runn
2950: 69 6e 67 20 69 6e 73 69 64 65 20 6f 66 20 54 63 ing inside of Tc
2960: 6c 5f 44 6f 4f 6e 65 45 76 65 6e 74 2e 0a 20 2a l_DoOneEvent.. *
2970: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 . * Results:. *.
2980: 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 None.. *. * Side
2990: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 4e 6f 6e effects:. *.Non
29a0: 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d e.. *. *--------
29b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 --------------.
29f0: 2a 2f 0a 0a 76 6f 69 64 0a 54 63 6c 5f 53 65 74 */..void.Tcl_Set
2a00: 54 69 6d 65 72 28 74 69 6d 65 50 74 72 29 0a 20 Timer(timePtr).
2a10: 20 20 20 54 63 6c 5f 54 69 6d 65 20 2a 74 69 6d Tcl_Time *tim
2a20: 65 50 74 72 3b 09 09 2f 2a 20 54 69 6d 65 6f 75 ePtr;../* Timeou
2a30: 74 20 76 61 6c 75 65 2c 20 6d 61 79 20 62 65 20 t value, may be
2a40: 4e 55 4c 4c 2e 20 2a 2f 0a 7b 0a 20 20 20 20 2f NULL. */.{. /
2a50: 2a 0a 20 20 20 20 20 2a 20 54 68 65 20 69 6e 74 *. * The int
2a60: 65 72 76 61 6c 20 74 69 6d 65 72 20 64 6f 65 73 erval timer does
2a70: 6e 27 74 20 64 6f 20 61 6e 79 74 68 69 6e 67 20 n't do anything
2a80: 69 6e 20 74 68 69 73 20 69 6d 70 6c 65 6d 65 6e in this implemen
2a90: 74 61 74 69 6f 6e 2c 0a 20 20 20 20 20 2a 20 62 tation,. * b
2aa0: 65 63 61 75 73 65 20 74 68 65 20 6f 6e 6c 79 20 ecause the only
2ab0: 65 76 65 6e 74 20 6c 6f 6f 70 20 69 73 20 76 69 event loop is vi
2ac0: 61 20 54 63 6c 5f 44 6f 4f 6e 65 45 76 65 6e 74 a Tcl_DoOneEvent
2ad0: 2c 20 77 68 69 63 68 20 70 61 73 73 65 73 0a 20 , which passes.
2ae0: 20 20 20 20 2a 20 74 69 6d 65 6f 75 74 20 76 61 * timeout va
2af0: 6c 75 65 73 20 74 6f 20 54 63 6c 5f 57 61 69 74 lues to Tcl_Wait
2b00: 46 6f 72 45 76 65 6e 74 2e 0a 20 20 20 20 20 2a ForEvent.. *
2b10: 2f 0a 0a 20 20 20 20 69 66 20 28 74 63 6c 53 74 /.. if (tclSt
2b20: 75 62 73 2e 74 63 6c 5f 53 65 74 54 69 6d 65 72 ubs.tcl_SetTimer
2b30: 20 21 3d 20 74 63 6c 4f 72 69 67 69 6e 61 6c 4e != tclOriginalN
2b40: 6f 74 69 66 69 65 72 2e 73 65 74 54 69 6d 65 72 otifier.setTimer
2b50: 50 72 6f 63 29 20 7b 0a 09 74 63 6c 53 74 75 62 Proc) {..tclStub
2b60: 73 2e 74 63 6c 5f 53 65 74 54 69 6d 65 72 28 74 s.tcl_SetTimer(t
2b70: 69 6d 65 50 74 72 29 3b 0a 20 20 20 20 7d 0a 7d imePtr);. }.}
2b80: 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d .../*. *--------
2b90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2ba0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2bb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2bc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 --------------.
2bd0: 2a 0a 20 2a 20 54 63 6c 5f 53 65 72 76 69 63 65 *. * Tcl_Service
2be0: 4d 6f 64 65 48 6f 6f 6b 20 2d 2d 0a 20 2a 0a 20 ModeHook --. *.
2bf0: 2a 09 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 *.This function
2c00: 69 73 20 69 6e 76 6f 6b 65 64 20 77 68 65 6e 65 is invoked whene
2c10: 76 65 72 20 74 68 65 20 73 65 72 76 69 63 65 20 ver the service
2c20: 6d 6f 64 65 20 63 68 61 6e 67 65 73 2e 0a 20 2a mode changes.. *
2c30: 0a 20 2a 20 52 65 73 75 6c 74 73 3a 0a 20 2a 09 . * Results:. *.
2c40: 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 None.. *. * Side
2c50: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 4e 6f 6e effects:. *.Non
2c60: 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d e.. *. *--------
2c70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2c80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2c90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2ca0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 --------------.
2cb0: 2a 2f 0a 0a 76 6f 69 64 0a 54 63 6c 5f 53 65 72 */..void.Tcl_Ser
2cc0: 76 69 63 65 4d 6f 64 65 48 6f 6f 6b 28 6d 6f 64 viceModeHook(mod
2cd0: 65 29 0a 20 20 20 20 69 6e 74 20 6d 6f 64 65 3b e). int mode;
2ce0: 09 09 09 2f 2a 20 45 69 74 68 65 72 20 54 43 4c .../* Either TCL
2cf0: 5f 53 45 52 56 49 43 45 5f 41 4c 4c 2c 20 6f 72 _SERVICE_ALL, or
2d00: 0a 09 09 09 09 20 2a 20 54 43 4c 5f 53 45 52 56 ..... * TCL_SERV
2d10: 49 43 45 5f 4e 4f 4e 45 2e 20 2a 2f 0a 7b 0a 7d ICE_NONE. */.{.}
2d20: 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d .../*. *--------
2d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2d40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 --------------.
2d70: 2a 0a 20 2a 20 54 63 6c 5f 43 72 65 61 74 65 46 *. * Tcl_CreateF
2d80: 69 6c 65 48 61 6e 64 6c 65 72 20 2d 2d 0a 20 2a ileHandler --. *
2d90: 0a 20 2a 09 54 68 69 73 20 70 72 6f 63 65 64 75 . *.This procedu
2da0: 72 65 20 72 65 67 69 73 74 65 72 73 20 61 20 66 re registers a f
2db0: 69 6c 65 20 68 61 6e 64 6c 65 72 20 77 69 74 68 ile handler with
2dc0: 20 74 68 65 20 73 65 6c 65 63 74 20 6e 6f 74 69 the select noti
2dd0: 66 69 65 72 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 fier.. *. * Resu
2de0: 6c 74 73 3a 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a lts:. *.None.. *
2df0: 0a 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 . * Side effects
2e00: 3a 0a 20 2a 09 43 72 65 61 74 65 73 20 61 20 6e :. *.Creates a n
2e10: 65 77 20 66 69 6c 65 20 68 61 6e 64 6c 65 72 20 ew file handler
2e20: 73 74 72 75 63 74 75 72 65 2e 0a 20 2a 0a 20 2a structure.. *. *
2e30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2e40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2e50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2e60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2e70: 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 76 6f 69 64 ------. */..void
2e80: 0a 54 63 6c 5f 43 72 65 61 74 65 46 69 6c 65 48 .Tcl_CreateFileH
2e90: 61 6e 64 6c 65 72 28 66 64 2c 20 6d 61 73 6b 2c andler(fd, mask,
2ea0: 20 70 72 6f 63 2c 20 63 6c 69 65 6e 74 44 61 74 proc, clientDat
2eb0: 61 29 0a 20 20 20 20 69 6e 74 20 66 64 3b 09 09 a). int fd;..
2ec0: 09 2f 2a 20 48 61 6e 64 6c 65 20 6f 66 20 73 74 ./* Handle of st
2ed0: 72 65 61 6d 20 74 6f 20 77 61 74 63 68 2e 20 2a ream to watch. *
2ee0: 2f 0a 20 20 20 20 69 6e 74 20 6d 61 73 6b 3b 09 /. int mask;.
2ef0: 09 09 2f 2a 20 4f 52 27 65 64 20 63 6f 6d 62 69 ../* OR'ed combi
2f00: 6e 61 74 69 6f 6e 20 6f 66 20 54 43 4c 5f 52 45 nation of TCL_RE
2f10: 41 44 41 42 4c 45 2c 0a 09 09 09 09 20 2a 20 54 ADABLE,..... * T
2f20: 43 4c 5f 57 52 49 54 41 42 4c 45 2c 20 61 6e 64 CL_WRITABLE, and
2f30: 20 54 43 4c 5f 45 58 43 45 50 54 49 4f 4e 3a 0a TCL_EXCEPTION:.
2f40: 09 09 09 09 20 2a 20 69 6e 64 69 63 61 74 65 73 .... * indicates
2f50: 20 63 6f 6e 64 69 74 69 6f 6e 73 20 75 6e 64 65 conditions unde
2f60: 72 20 77 68 69 63 68 0a 09 09 09 09 20 2a 20 70 r which..... * p
2f70: 72 6f 63 20 73 68 6f 75 6c 64 20 62 65 20 63 61 roc should be ca
2f80: 6c 6c 65 64 2e 20 2a 2f 0a 20 20 20 20 54 63 6c lled. */. Tcl
2f90: 5f 46 69 6c 65 50 72 6f 63 20 2a 70 72 6f 63 3b _FileProc *proc;
2fa0: 09 09 2f 2a 20 50 72 6f 63 65 64 75 72 65 20 74 ../* Procedure t
2fb0: 6f 20 63 61 6c 6c 20 66 6f 72 20 65 61 63 68 0a o call for each.
2fc0: 09 09 09 09 20 2a 20 73 65 6c 65 63 74 65 64 20 .... * selected
2fd0: 65 76 65 6e 74 2e 20 2a 2f 0a 20 20 20 20 43 6c event. */. Cl
2fe0: 69 65 6e 74 44 61 74 61 20 63 6c 69 65 6e 74 44 ientData clientD
2ff0: 61 74 61 3b 09 2f 2a 20 41 72 62 69 74 72 61 72 ata;./* Arbitrar
3000: 79 20 64 61 74 61 20 74 6f 20 70 61 73 73 20 74 y data to pass t
3010: 6f 20 70 72 6f 63 2e 20 2a 2f 0a 7b 0a 20 20 20 o proc. */.{.
3020: 20 54 68 72 65 61 64 53 70 65 63 69 66 69 63 44 ThreadSpecificD
3030: 61 74 61 20 2a 74 73 64 50 74 72 20 3d 20 54 43 ata *tsdPtr = TC
3040: 4c 5f 54 53 44 5f 49 4e 49 54 28 26 64 61 74 61 L_TSD_INIT(&data
3050: 4b 65 79 29 3b 0a 20 20 20 20 46 69 6c 65 48 61 Key);. FileHa
3060: 6e 64 6c 65 72 20 2a 66 69 6c 65 50 74 72 3b 0a ndler *filePtr;.
3070: 0a 20 20 20 20 69 66 20 28 74 63 6c 53 74 75 62 . if (tclStub
3080: 73 2e 74 63 6c 5f 43 72 65 61 74 65 46 69 6c 65 s.tcl_CreateFile
3090: 48 61 6e 64 6c 65 72 20 21 3d 20 74 63 6c 4f 72 Handler != tclOr
30a0: 69 67 69 6e 61 6c 4e 6f 74 69 66 69 65 72 2e 63 iginalNotifier.c
30b0: 72 65 61 74 65 46 69 6c 65 48 61 6e 64 6c 65 72 reateFileHandler
30c0: 50 72 6f 63 29 20 7b 0a 09 74 63 6c 53 74 75 62 Proc) {..tclStub
30d0: 73 2e 74 63 6c 5f 43 72 65 61 74 65 46 69 6c 65 s.tcl_CreateFile
30e0: 48 61 6e 64 6c 65 72 28 66 64 2c 20 6d 61 73 6b Handler(fd, mask
30f0: 2c 20 70 72 6f 63 2c 20 63 6c 69 65 6e 74 44 61 , proc, clientDa
3100: 74 61 29 3b 0a 09 72 65 74 75 72 6e 3b 0a 20 20 ta);..return;.
3110: 20 20 7d 0a 0a 20 20 20 20 66 6f 72 20 28 66 69 }.. for (fi
3120: 6c 65 50 74 72 20 3d 20 74 73 64 50 74 72 2d 3e lePtr = tsdPtr->
3130: 66 69 72 73 74 46 69 6c 65 48 61 6e 64 6c 65 72 firstFileHandler
3140: 50 74 72 3b 20 66 69 6c 65 50 74 72 20 21 3d 20 Ptr; filePtr !=
3150: 4e 55 4c 4c 3b 0a 09 20 66 69 6c 65 50 74 72 20 NULL;.. filePtr
3160: 3d 20 66 69 6c 65 50 74 72 2d 3e 6e 65 78 74 50 = filePtr->nextP
3170: 74 72 29 20 7b 0a 09 69 66 20 28 66 69 6c 65 50 tr) {..if (fileP
3180: 74 72 2d 3e 66 64 20 3d 3d 20 66 64 29 20 7b 0a tr->fd == fd) {.
3190: 09 20 20 20 20 62 72 65 61 6b 3b 0a 09 7d 0a 20 . break;..}.
31a0: 20 20 20 7d 0a 20 20 20 20 69 66 20 28 66 69 6c }. if (fil
31b0: 65 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a ePtr == NULL) {.
31c0: 09 66 69 6c 65 50 74 72 20 3d 20 28 46 69 6c 65 .filePtr = (File
31d0: 48 61 6e 64 6c 65 72 2a 29 20 63 6b 61 6c 6c 6f Handler*) ckallo
31e0: 63 28 73 69 7a 65 6f 66 28 46 69 6c 65 48 61 6e c(sizeof(FileHan
31f0: 64 6c 65 72 29 29 3b 0a 09 66 69 6c 65 50 74 72 dler));..filePtr
3200: 2d 3e 66 64 20 3d 20 66 64 3b 0a 09 66 69 6c 65 ->fd = fd;..file
3210: 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 6b 20 3d Ptr->readyMask =
3220: 20 30 3b 0a 09 66 69 6c 65 50 74 72 2d 3e 6e 65 0;..filePtr->ne
3230: 78 74 50 74 72 20 3d 20 74 73 64 50 74 72 2d 3e xtPtr = tsdPtr->
3240: 66 69 72 73 74 46 69 6c 65 48 61 6e 64 6c 65 72 firstFileHandler
3250: 50 74 72 3b 0a 09 74 73 64 50 74 72 2d 3e 66 69 Ptr;..tsdPtr->fi
3260: 72 73 74 46 69 6c 65 48 61 6e 64 6c 65 72 50 74 rstFileHandlerPt
3270: 72 20 3d 20 66 69 6c 65 50 74 72 3b 0a 20 20 20 r = filePtr;.
3280: 20 7d 0a 20 20 20 20 66 69 6c 65 50 74 72 2d 3e }. filePtr->
3290: 70 72 6f 63 20 3d 20 70 72 6f 63 3b 0a 20 20 20 proc = proc;.
32a0: 20 66 69 6c 65 50 74 72 2d 3e 63 6c 69 65 6e 74 filePtr->client
32b0: 44 61 74 61 20 3d 20 63 6c 69 65 6e 74 44 61 74 Data = clientDat
32c0: 61 3b 0a 20 20 20 20 66 69 6c 65 50 74 72 2d 3e a;. filePtr->
32d0: 6d 61 73 6b 20 3d 20 6d 61 73 6b 3b 0a 0a 20 20 mask = mask;..
32e0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 55 70 64 61 /*. * Upda
32f0: 74 65 20 74 68 65 20 63 68 65 63 6b 20 6d 61 73 te the check mas
3300: 6b 73 20 66 6f 72 20 74 68 69 73 20 66 69 6c 65 ks for this file
3310: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 69 .. */.. i
3320: 66 20 28 20 6d 61 73 6b 20 26 20 54 43 4c 5f 52 f ( mask & TCL_R
3330: 45 41 44 41 42 4c 45 20 29 20 7b 0a 09 46 44 5f EADABLE ) {..FD_
3340: 53 45 54 28 20 66 64 2c 20 26 28 74 73 64 50 74 SET( fd, &(tsdPt
3350: 72 2d 3e 63 68 65 63 6b 4d 61 73 6b 73 2e 72 65 r->checkMasks.re
3360: 61 64 61 62 6c 65 29 20 29 3b 0a 20 20 20 20 7d adable) );. }
3370: 20 65 6c 73 65 20 7b 0a 09 46 44 5f 43 4c 52 28 else {..FD_CLR(
3380: 20 66 64 2c 20 26 28 74 73 64 50 74 72 2d 3e 63 fd, &(tsdPtr->c
3390: 68 65 63 6b 4d 61 73 6b 73 2e 72 65 61 64 61 62 heckMasks.readab
33a0: 6c 65 29 20 29 3b 0a 20 20 20 20 7d 0a 20 20 20 le) );. }.
33b0: 20 69 66 20 28 20 6d 61 73 6b 20 26 20 54 43 4c if ( mask & TCL
33c0: 5f 57 52 49 54 41 42 4c 45 20 29 20 7b 0a 09 46 _WRITABLE ) {..F
33d0: 44 5f 53 45 54 28 20 66 64 2c 20 26 28 74 73 64 D_SET( fd, &(tsd
33e0: 50 74 72 2d 3e 63 68 65 63 6b 4d 61 73 6b 73 2e Ptr->checkMasks.
33f0: 77 72 69 74 61 62 6c 65 29 20 29 3b 0a 20 20 20 writable) );.
3400: 20 7d 20 65 6c 73 65 20 7b 0a 09 46 44 5f 43 4c } else {..FD_CL
3410: 52 28 20 66 64 2c 20 26 28 74 73 64 50 74 72 2d R( fd, &(tsdPtr-
3420: 3e 63 68 65 63 6b 4d 61 73 6b 73 2e 77 72 69 74 >checkMasks.writ
3430: 61 62 6c 65 29 20 29 3b 0a 20 20 20 20 7d 0a 20 able) );. }.
3440: 20 20 20 69 66 20 28 20 6d 61 73 6b 20 26 20 54 if ( mask & T
3450: 43 4c 5f 45 58 43 45 50 54 49 4f 4e 20 29 20 7b CL_EXCEPTION ) {
3460: 0a 09 46 44 5f 53 45 54 28 20 66 64 2c 20 26 28 ..FD_SET( fd, &(
3470: 74 73 64 50 74 72 2d 3e 63 68 65 63 6b 4d 61 73 tsdPtr->checkMas
3480: 6b 73 2e 65 78 63 65 70 74 69 6f 6e 61 6c 29 20 ks.exceptional)
3490: 29 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a );. } else {.
34a0: 09 46 44 5f 43 4c 52 28 20 66 64 2c 20 26 28 74 .FD_CLR( fd, &(t
34b0: 73 64 50 74 72 2d 3e 63 68 65 63 6b 4d 61 73 6b sdPtr->checkMask
34c0: 73 2e 65 78 63 65 70 74 69 6f 6e 61 6c 29 20 29 s.exceptional) )
34d0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 ;. }. if (
34e0: 74 73 64 50 74 72 2d 3e 6e 75 6d 46 64 42 69 74 tsdPtr->numFdBit
34f0: 73 20 3c 3d 20 66 64 29 20 7b 0a 09 74 73 64 50 s <= fd) {..tsdP
3500: 74 72 2d 3e 6e 75 6d 46 64 42 69 74 73 20 3d 20 tr->numFdBits =
3510: 66 64 2b 31 3b 0a 20 20 20 20 7d 0a 7d 0a 0c 0a fd+1;. }.}...
3520: 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d /*. *-----------
3530: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 -----------. *.
3570: 2a 20 54 63 6c 5f 44 65 6c 65 74 65 46 69 6c 65 * Tcl_DeleteFile
3580: 48 61 6e 64 6c 65 72 20 2d 2d 0a 20 2a 0a 20 2a Handler --. *. *
3590: 09 43 61 6e 63 65 6c 20 61 20 70 72 65 76 69 6f .Cancel a previo
35a0: 75 73 6c 79 2d 61 72 72 61 6e 67 65 64 20 63 61 usly-arranged ca
35b0: 6c 6c 62 61 63 6b 20 61 72 72 61 6e 67 65 6d 65 llback arrangeme
35c0: 6e 74 20 66 6f 72 0a 20 2a 09 61 20 66 69 6c 65 nt for. *.a file
35d0: 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c 74 73 3a .. *. * Results:
35e0: 0a 20 2a 09 4e 6f 6e 65 2e 0a 20 2a 0a 20 2a 20 . *.None.. *. *
35f0: 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a Side effects:. *
3600: 09 49 66 20 61 20 63 61 6c 6c 62 61 63 6b 20 77 .If a callback w
3610: 61 73 20 70 72 65 76 69 6f 75 73 6c 79 20 72 65 as previously re
3620: 67 69 73 74 65 72 65 64 20 6f 6e 20 66 69 6c 65 gistered on file
3630: 2c 20 72 65 6d 6f 76 65 20 69 74 2e 0a 20 2a 0a , remove it.. *.
3640: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *--------------
3650: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3660: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3670: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3680: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 76 6f --------. */..vo
3690: 69 64 0a 54 63 6c 5f 44 65 6c 65 74 65 46 69 6c id.Tcl_DeleteFil
36a0: 65 48 61 6e 64 6c 65 72 28 66 64 29 0a 20 20 20 eHandler(fd).
36b0: 20 69 6e 74 20 66 64 3b 09 09 2f 2a 20 53 74 72 int fd;../* Str
36c0: 65 61 6d 20 69 64 20 66 6f 72 20 77 68 69 63 68 eam id for which
36d0: 20 74 6f 20 72 65 6d 6f 76 65 20 63 61 6c 6c 62 to remove callb
36e0: 61 63 6b 20 70 72 6f 63 65 64 75 72 65 2e 20 2a ack procedure. *
36f0: 2f 0a 7b 0a 20 20 20 20 46 69 6c 65 48 61 6e 64 /.{. FileHand
3700: 6c 65 72 20 2a 66 69 6c 65 50 74 72 2c 20 2a 70 ler *filePtr, *p
3710: 72 65 76 50 74 72 3b 0a 20 20 20 20 69 6e 74 20 revPtr;. int
3720: 69 3b 0a 20 20 20 20 54 68 72 65 61 64 53 70 65 i;. ThreadSpe
3730: 63 69 66 69 63 44 61 74 61 20 2a 74 73 64 50 74 cificData *tsdPt
3740: 72 20 3d 20 54 43 4c 5f 54 53 44 5f 49 4e 49 54 r = TCL_TSD_INIT
3750: 28 26 64 61 74 61 4b 65 79 29 3b 0a 0a 20 20 20 (&dataKey);..
3760: 20 69 66 20 28 74 63 6c 53 74 75 62 73 2e 74 63 if (tclStubs.tc
3770: 6c 5f 44 65 6c 65 74 65 46 69 6c 65 48 61 6e 64 l_DeleteFileHand
3780: 6c 65 72 20 21 3d 20 74 63 6c 4f 72 69 67 69 6e ler != tclOrigin
3790: 61 6c 4e 6f 74 69 66 69 65 72 2e 64 65 6c 65 74 alNotifier.delet
37a0: 65 46 69 6c 65 48 61 6e 64 6c 65 72 50 72 6f 63 eFileHandlerProc
37b0: 29 20 7b 0a 09 74 63 6c 53 74 75 62 73 2e 74 63 ) {..tclStubs.tc
37c0: 6c 5f 44 65 6c 65 74 65 46 69 6c 65 48 61 6e 64 l_DeleteFileHand
37d0: 6c 65 72 28 66 64 29 3b 0a 09 72 65 74 75 72 6e ler(fd);..return
37e0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a ;. }.. /*.
37f0: 20 20 20 20 20 2a 20 46 69 6e 64 20 74 68 65 20 * Find the
3800: 65 6e 74 72 79 20 66 6f 72 20 74 68 65 20 67 69 entry for the gi
3810: 76 65 6e 20 66 69 6c 65 20 28 61 6e 64 20 72 65 ven file (and re
3820: 74 75 72 6e 20 69 66 20 74 68 65 72 65 20 69 73 turn if there is
3830: 6e 27 74 20 6f 6e 65 29 2e 0a 20 20 20 20 20 2a n't one).. *
3840: 2f 0a 0a 20 20 20 20 66 6f 72 20 28 70 72 65 76 /.. for (prev
3850: 50 74 72 20 3d 20 4e 55 4c 4c 2c 20 66 69 6c 65 Ptr = NULL, file
3860: 50 74 72 20 3d 20 74 73 64 50 74 72 2d 3e 66 69 Ptr = tsdPtr->fi
3870: 72 73 74 46 69 6c 65 48 61 6e 64 6c 65 72 50 74 rstFileHandlerPt
3880: 72 3b 20 3b 0a 09 20 70 72 65 76 50 74 72 20 3d r; ;.. prevPtr =
3890: 20 66 69 6c 65 50 74 72 2c 20 66 69 6c 65 50 74 filePtr, filePt
38a0: 72 20 3d 20 66 69 6c 65 50 74 72 2d 3e 6e 65 78 r = filePtr->nex
38b0: 74 50 74 72 29 20 7b 0a 09 69 66 20 28 66 69 6c tPtr) {..if (fil
38c0: 65 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a ePtr == NULL) {.
38d0: 09 20 20 20 20 72 65 74 75 72 6e 3b 0a 09 7d 0a . return;..}.
38e0: 09 69 66 20 28 66 69 6c 65 50 74 72 2d 3e 66 64 .if (filePtr->fd
38f0: 20 3d 3d 20 66 64 29 20 7b 0a 09 20 20 20 20 62 == fd) {.. b
3900: 72 65 61 6b 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a reak;..}. }..
3910: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 55 70 /*. * Up
3920: 64 61 74 65 20 74 68 65 20 63 68 65 63 6b 20 6d date the check m
3930: 61 73 6b 73 20 66 6f 72 20 74 68 69 73 20 66 69 asks for this fi
3940: 6c 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 le.. */..
3950: 20 69 66 20 28 66 69 6c 65 50 74 72 2d 3e 6d 61 if (filePtr->ma
3960: 73 6b 20 26 20 54 43 4c 5f 52 45 41 44 41 42 4c sk & TCL_READABL
3970: 45 29 20 7b 0a 09 46 44 5f 43 4c 52 28 20 66 64 E) {..FD_CLR( fd
3980: 2c 20 26 28 74 73 64 50 74 72 2d 3e 63 68 65 63 , &(tsdPtr->chec
3990: 6b 4d 61 73 6b 73 2e 72 65 61 64 61 62 6c 65 29 kMasks.readable)
39a0: 20 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 );. }. if
39b0: 20 28 66 69 6c 65 50 74 72 2d 3e 6d 61 73 6b 20 (filePtr->mask
39c0: 26 20 54 43 4c 5f 57 52 49 54 41 42 4c 45 29 20 & TCL_WRITABLE)
39d0: 7b 0a 09 46 44 5f 43 4c 52 28 20 66 64 2c 20 26 {..FD_CLR( fd, &
39e0: 28 74 73 64 50 74 72 2d 3e 63 68 65 63 6b 4d 61 (tsdPtr->checkMa
39f0: 73 6b 73 2e 77 72 69 74 61 62 6c 65 29 20 29 3b sks.writable) );
3a00: 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 66 . }. if (f
3a10: 69 6c 65 50 74 72 2d 3e 6d 61 73 6b 20 26 20 54 ilePtr->mask & T
3a20: 43 4c 5f 45 58 43 45 50 54 49 4f 4e 29 20 7b 0a CL_EXCEPTION) {.
3a30: 09 46 44 5f 43 4c 52 28 20 66 64 2c 20 26 28 74 .FD_CLR( fd, &(t
3a40: 73 64 50 74 72 2d 3e 63 68 65 63 6b 4d 61 73 6b sdPtr->checkMask
3a50: 73 2e 65 78 63 65 70 74 69 6f 6e 61 6c 29 20 29 s.exceptional) )
3a60: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a ;. }.. /*.
3a70: 20 20 20 20 20 2a 20 46 69 6e 64 20 63 75 72 72 * Find curr
3a80: 65 6e 74 20 6d 61 78 20 66 64 2e 0a 20 20 20 20 ent max fd..
3a90: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 66 64 2b */.. if (fd+
3aa0: 31 20 3d 3d 20 74 73 64 50 74 72 2d 3e 6e 75 6d 1 == tsdPtr->num
3ab0: 46 64 42 69 74 73 29 20 7b 0a 09 74 73 64 50 74 FdBits) {..tsdPt
3ac0: 72 2d 3e 6e 75 6d 46 64 42 69 74 73 20 3d 20 30 r->numFdBits = 0
3ad0: 3b 0a 09 66 6f 72 20 28 69 20 3d 20 66 64 2d 31 ;..for (i = fd-1
3ae0: 3b 20 69 20 3e 3d 20 30 3b 20 69 2d 2d 29 20 7b ; i >= 0; i--) {
3af0: 0a 09 20 20 20 20 69 66 20 28 20 46 44 5f 49 53 .. if ( FD_IS
3b00: 53 45 54 28 20 69 2c 20 26 28 74 73 64 50 74 72 SET( i, &(tsdPtr
3b10: 2d 3e 63 68 65 63 6b 4d 61 73 6b 73 2e 72 65 61 ->checkMasks.rea
3b20: 64 61 62 6c 65 29 20 29 0a 09 09 20 7c 7c 20 46 dable) )... || F
3b30: 44 5f 49 53 53 45 54 28 20 69 2c 20 26 28 74 73 D_ISSET( i, &(ts
3b40: 64 50 74 72 2d 3e 63 68 65 63 6b 4d 61 73 6b 73 dPtr->checkMasks
3b50: 2e 77 72 69 74 61 62 6c 65 29 20 29 0a 09 09 20 .writable) )...
3b60: 7c 7c 20 46 44 5f 49 53 53 45 54 28 20 69 2c 20 || FD_ISSET( i,
3b70: 26 28 74 73 64 50 74 72 2d 3e 63 68 65 63 6b 4d &(tsdPtr->checkM
3b80: 61 73 6b 73 2e 65 78 63 65 70 74 69 6f 6e 61 6c asks.exceptional
3b90: 20 29 20 29 20 29 20 7b 0a 09 09 74 73 64 50 74 ) ) ) {...tsdPt
3ba0: 72 2d 3e 6e 75 6d 46 64 42 69 74 73 20 3d 20 69 r->numFdBits = i
3bb0: 2b 31 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 +1;...break;..
3bc0: 20 20 7d 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 }..}. }..
3bd0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 65 61 /*. * Clea
3be0: 6e 20 75 70 20 69 6e 66 6f 72 6d 61 74 69 6f 6e n up information
3bf0: 20 69 6e 20 74 68 65 20 63 61 6c 6c 62 61 63 6b in the callback
3c00: 20 72 65 63 6f 72 64 2e 0a 20 20 20 20 20 2a 2f record.. */
3c10: 0a 0a 20 20 20 20 69 66 20 28 70 72 65 76 50 74 .. if (prevPt
3c20: 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 74 73 r == NULL) {..ts
3c30: 64 50 74 72 2d 3e 66 69 72 73 74 46 69 6c 65 48 dPtr->firstFileH
3c40: 61 6e 64 6c 65 72 50 74 72 20 3d 20 66 69 6c 65 andlerPtr = file
3c50: 50 74 72 2d 3e 6e 65 78 74 50 74 72 3b 0a 20 20 Ptr->nextPtr;.
3c60: 20 20 7d 20 65 6c 73 65 20 7b 0a 09 70 72 65 76 } else {..prev
3c70: 50 74 72 2d 3e 6e 65 78 74 50 74 72 20 3d 20 66 Ptr->nextPtr = f
3c80: 69 6c 65 50 74 72 2d 3e 6e 65 78 74 50 74 72 3b ilePtr->nextPtr;
3c90: 0a 20 20 20 20 7d 0a 20 20 20 20 63 6b 66 72 65 . }. ckfre
3ca0: 65 28 28 63 68 61 72 20 2a 29 20 66 69 6c 65 50 e((char *) fileP
3cb0: 74 72 29 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d tr);.}.../*. *--
3cc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3cd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3ce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3cf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3d00: 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 46 69 6c 65 48 ----. *. * FileH
3d10: 61 6e 64 6c 65 72 45 76 65 6e 74 50 72 6f 63 20 andlerEventProc
3d20: 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 70 72 --. *. *.This pr
3d30: 6f 63 65 64 75 72 65 20 69 73 20 63 61 6c 6c 65 ocedure is calle
3d40: 64 20 62 79 20 54 63 6c 5f 53 65 72 76 69 63 65 d by Tcl_Service
3d50: 45 76 65 6e 74 20 77 68 65 6e 20 61 20 66 69 6c Event when a fil
3d60: 65 20 65 76 65 6e 74 0a 20 2a 09 72 65 61 63 68 e event. *.reach
3d70: 65 73 20 74 68 65 20 66 72 6f 6e 74 20 6f 66 20 es the front of
3d80: 74 68 65 20 65 76 65 6e 74 20 71 75 65 75 65 2e the event queue.
3d90: 20 20 54 68 69 73 20 70 72 6f 63 65 64 75 72 65 This procedure
3da0: 20 69 73 0a 20 2a 09 72 65 73 70 6f 6e 73 69 62 is. *.responsib
3db0: 6c 65 20 66 6f 72 20 61 63 74 75 61 6c 6c 79 20 le for actually
3dc0: 68 61 6e 64 6c 69 6e 67 20 74 68 65 20 65 76 65 handling the eve
3dd0: 6e 74 20 62 79 20 69 6e 76 6f 6b 69 6e 67 20 74 nt by invoking t
3de0: 68 65 0a 20 2a 09 63 61 6c 6c 62 61 63 6b 20 66 he. *.callback f
3df0: 6f 72 20 74 68 65 20 66 69 6c 65 20 68 61 6e 64 or the file hand
3e00: 6c 65 72 2e 0a 20 2a 0a 20 2a 20 52 65 73 75 6c ler.. *. * Resul
3e10: 74 73 3a 0a 20 2a 09 52 65 74 75 72 6e 73 20 31 ts:. *.Returns 1
3e20: 20 69 66 20 74 68 65 20 65 76 65 6e 74 20 77 61 if the event wa
3e30: 73 20 68 61 6e 64 6c 65 64 2c 20 6d 65 61 6e 69 s handled, meani
3e40: 6e 67 20 69 74 20 73 68 6f 75 6c 64 20 62 65 20 ng it should be
3e50: 72 65 6d 6f 76 65 64 0a 20 2a 09 66 72 6f 6d 20 removed. *.from
3e60: 74 68 65 20 71 75 65 75 65 2e 20 20 52 65 74 75 the queue. Retu
3e70: 72 6e 73 20 30 20 69 66 20 74 68 65 20 65 76 65 rns 0 if the eve
3e80: 6e 74 20 77 61 73 20 6e 6f 74 20 68 61 6e 64 6c nt was not handl
3e90: 65 64 2c 20 6d 65 61 6e 69 6e 67 0a 20 2a 09 69 ed, meaning. *.i
3ea0: 74 20 73 68 6f 75 6c 64 20 73 74 61 79 20 6f 6e t should stay on
3eb0: 20 74 68 65 20 71 75 65 75 65 2e 20 20 54 68 65 the queue. The
3ec0: 20 6f 6e 6c 79 20 74 69 6d 65 20 74 68 65 20 65 only time the e
3ed0: 76 65 6e 74 20 69 73 6e 27 74 0a 20 2a 09 68 61 vent isn't. *.ha
3ee0: 6e 64 6c 65 64 20 69 73 20 69 66 20 74 68 65 20 ndled is if the
3ef0: 54 43 4c 5f 46 49 4c 45 5f 45 56 45 4e 54 53 20 TCL_FILE_EVENTS
3f00: 66 6c 61 67 20 62 69 74 20 69 73 6e 27 74 20 73 flag bit isn't s
3f10: 65 74 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 et.. *. * Side e
3f20: 66 66 65 63 74 73 3a 0a 20 2a 09 57 68 61 74 65 ffects:. *.Whate
3f30: 76 65 72 20 74 68 65 20 66 69 6c 65 20 68 61 6e ver the file han
3f40: 64 6c 65 72 27 73 20 63 61 6c 6c 62 61 63 6b 20 dler's callback
3f50: 70 72 6f 63 65 64 75 72 65 20 64 6f 65 73 2e 0a procedure does..
3f60: 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *. *-----------
3f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3f90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
3fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a -----------. */.
3fb0: 0a 73 74 61 74 69 63 20 69 6e 74 0a 46 69 6c 65 .static int.File
3fc0: 48 61 6e 64 6c 65 72 45 76 65 6e 74 50 72 6f 63 HandlerEventProc
3fd0: 28 65 76 50 74 72 2c 20 66 6c 61 67 73 29 0a 20 (evPtr, flags).
3fe0: 20 20 20 54 63 6c 5f 45 76 65 6e 74 20 2a 65 76 Tcl_Event *ev
3ff0: 50 74 72 3b 09 09 2f 2a 20 45 76 65 6e 74 20 74 Ptr;../* Event t
4000: 6f 20 73 65 72 76 69 63 65 2e 20 2a 2f 0a 20 20 o service. */.
4010: 20 20 69 6e 74 20 66 6c 61 67 73 3b 09 09 09 2f int flags;.../
4020: 2a 20 46 6c 61 67 73 20 74 68 61 74 20 69 6e 64 * Flags that ind
4030: 69 63 61 74 65 20 77 68 61 74 20 65 76 65 6e 74 icate what event
4040: 73 20 74 6f 0a 09 09 09 09 20 2a 20 68 61 6e 64 s to..... * hand
4050: 6c 65 2c 20 73 75 63 68 20 61 73 20 54 43 4c 5f le, such as TCL_
4060: 46 49 4c 45 5f 45 56 45 4e 54 53 2e 20 2a 2f 0a FILE_EVENTS. */.
4070: 7b 0a 20 20 20 20 69 6e 74 20 6d 61 73 6b 3b 0a {. int mask;.
4080: 20 20 20 20 46 69 6c 65 48 61 6e 64 6c 65 72 20 FileHandler
4090: 2a 66 69 6c 65 50 74 72 3b 0a 20 20 20 20 46 69 *filePtr;. Fi
40a0: 6c 65 48 61 6e 64 6c 65 72 45 76 65 6e 74 20 2a leHandlerEvent *
40b0: 66 69 6c 65 45 76 50 74 72 20 3d 20 28 46 69 6c fileEvPtr = (Fil
40c0: 65 48 61 6e 64 6c 65 72 45 76 65 6e 74 20 2a 29 eHandlerEvent *)
40d0: 20 65 76 50 74 72 3b 0a 20 20 20 20 54 68 72 65 evPtr;. Thre
40e0: 61 64 53 70 65 63 69 66 69 63 44 61 74 61 20 2a adSpecificData *
40f0: 74 73 64 50 74 72 3b 0a 0a 20 20 20 20 69 66 20 tsdPtr;.. if
4100: 28 21 28 66 6c 61 67 73 20 26 20 54 43 4c 5f 46 (!(flags & TCL_F
4110: 49 4c 45 5f 45 56 45 4e 54 53 29 29 20 7b 0a 09 ILE_EVENTS)) {..
4120: 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 20 7d 0a return 0;. }.
4130: 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 53 . /*. * S
4140: 65 61 72 63 68 20 74 68 72 6f 75 67 68 20 74 68 earch through th
4150: 65 20 66 69 6c 65 20 68 61 6e 64 6c 65 72 73 20 e file handlers
4160: 74 6f 20 66 69 6e 64 20 74 68 65 20 6f 6e 65 20 to find the one
4170: 77 68 6f 73 65 20 68 61 6e 64 6c 65 20 6d 61 74 whose handle mat
4180: 63 68 65 73 0a 20 20 20 20 20 2a 20 74 68 65 20 ches. * the
4190: 65 76 65 6e 74 2e 20 20 57 65 20 64 6f 20 74 68 event. We do th
41a0: 69 73 20 72 61 74 68 65 72 20 74 68 61 6e 20 6b is rather than k
41b0: 65 65 70 69 6e 67 20 61 20 70 6f 69 6e 74 65 72 eeping a pointer
41c0: 20 74 6f 20 74 68 65 20 66 69 6c 65 0a 20 20 20 to the file.
41d0: 20 20 2a 20 68 61 6e 64 6c 65 72 20 64 69 72 65 * handler dire
41e0: 63 74 6c 79 20 69 6e 20 74 68 65 20 65 76 65 6e ctly in the even
41f0: 74 2c 20 73 6f 20 74 68 61 74 20 74 68 65 20 68 t, so that the h
4200: 61 6e 64 6c 65 72 20 63 61 6e 20 62 65 20 64 65 andler can be de
4210: 6c 65 74 65 64 0a 20 20 20 20 20 2a 20 77 68 69 leted. * whi
4220: 6c 65 20 74 68 65 20 65 76 65 6e 74 20 69 73 20 le the event is
4230: 71 75 65 75 65 64 20 77 69 74 68 6f 75 74 20 6c queued without l
4240: 65 61 76 69 6e 67 20 61 20 64 61 6e 67 6c 69 6e eaving a danglin
4250: 67 20 70 6f 69 6e 74 65 72 2e 0a 20 20 20 20 20 g pointer..
4260: 2a 2f 0a 0a 20 20 20 20 74 73 64 50 74 72 20 3d */.. tsdPtr =
4270: 20 54 43 4c 5f 54 53 44 5f 49 4e 49 54 28 26 64 TCL_TSD_INIT(&d
4280: 61 74 61 4b 65 79 29 3b 0a 20 20 20 20 66 6f 72 ataKey);. for
4290: 20 28 66 69 6c 65 50 74 72 20 3d 20 74 73 64 50 (filePtr = tsdP
42a0: 74 72 2d 3e 66 69 72 73 74 46 69 6c 65 48 61 6e tr->firstFileHan
42b0: 64 6c 65 72 50 74 72 3b 20 66 69 6c 65 50 74 72 dlerPtr; filePtr
42c0: 20 21 3d 20 4e 55 4c 4c 3b 0a 09 20 66 69 6c 65 != NULL;.. file
42d0: 50 74 72 20 3d 20 66 69 6c 65 50 74 72 2d 3e 6e Ptr = filePtr->n
42e0: 65 78 74 50 74 72 29 20 7b 0a 09 69 66 20 28 66 extPtr) {..if (f
42f0: 69 6c 65 50 74 72 2d 3e 66 64 20 21 3d 20 66 69 ilePtr->fd != fi
4300: 6c 65 45 76 50 74 72 2d 3e 66 64 29 20 7b 0a 09 leEvPtr->fd) {..
4310: 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 09 7d continue;..}
4320: 0a 0a 09 2f 2a 0a 09 20 2a 20 54 68 65 20 63 6f .../*.. * The co
4330: 64 65 20 69 73 20 74 72 69 63 6b 79 20 66 6f 72 de is tricky for
4340: 20 74 77 6f 20 72 65 61 73 6f 6e 73 3a 0a 09 20 two reasons:..
4350: 2a 20 31 2e 20 54 68 65 20 66 69 6c 65 20 68 61 * 1. The file ha
4360: 6e 64 6c 65 72 27 73 20 64 65 73 69 72 65 64 20 ndler's desired
4370: 65 76 65 6e 74 73 20 63 6f 75 6c 64 20 68 61 76 events could hav
4380: 65 20 63 68 61 6e 67 65 64 0a 09 20 2a 20 20 20 e changed.. *
4390: 20 73 69 6e 63 65 20 74 68 65 20 74 69 6d 65 20 since the time
43a0: 77 68 65 6e 20 74 68 65 20 65 76 65 6e 74 20 77 when the event w
43b0: 61 73 20 71 75 65 75 65 64 2c 20 73 6f 20 41 4e as queued, so AN
43c0: 44 20 74 68 65 0a 09 20 2a 20 20 20 20 72 65 61 D the.. * rea
43d0: 64 79 20 6d 61 73 6b 20 77 69 74 68 20 74 68 65 dy mask with the
43e0: 20 64 65 73 69 72 65 64 20 6d 61 73 6b 2e 0a 09 desired mask...
43f0: 20 2a 20 32 2e 20 54 68 65 20 66 69 6c 65 20 63 * 2. The file c
4400: 6f 75 6c 64 20 68 61 76 65 20 62 65 65 6e 20 63 ould have been c
4410: 6c 6f 73 65 64 20 61 6e 64 20 72 65 2d 6f 70 65 losed and re-ope
4420: 6e 65 64 20 73 69 6e 63 65 0a 09 20 2a 20 20 20 ned since.. *
4430: 20 74 68 65 20 74 69 6d 65 20 77 68 65 6e 20 74 the time when t
4440: 68 65 20 65 76 65 6e 74 20 77 61 73 20 71 75 65 he event was que
4450: 75 65 64 2e 20 20 54 68 69 73 20 69 73 20 77 68 ued. This is wh
4460: 79 20 74 68 65 0a 09 20 2a 20 20 20 20 72 65 61 y the.. * rea
4470: 64 79 20 6d 61 73 6b 20 69 73 20 73 74 6f 72 65 dy mask is store
4480: 64 20 69 6e 20 74 68 65 20 66 69 6c 65 20 68 61 d in the file ha
4490: 6e 64 6c 65 72 20 72 61 74 68 65 72 20 74 68 61 ndler rather tha
44a0: 6e 0a 09 20 2a 20 20 20 20 74 68 65 20 71 75 65 n.. * the que
44b0: 75 65 64 20 65 76 65 6e 74 3a 20 20 69 74 20 77 ued event: it w
44c0: 69 6c 6c 20 62 65 20 7a 65 72 6f 65 64 20 77 68 ill be zeroed wh
44d0: 65 6e 20 61 20 6e 65 77 0a 09 20 2a 20 20 20 20 en a new.. *
44e0: 66 69 6c 65 20 68 61 6e 64 6c 65 72 20 69 73 20 file handler is
44f0: 63 72 65 61 74 65 64 20 66 6f 72 20 74 68 65 20 created for the
4500: 6e 65 77 6c 79 20 6f 70 65 6e 65 64 20 66 69 6c newly opened fil
4510: 65 2e 0a 09 20 2a 2f 0a 0a 09 6d 61 73 6b 20 3d e... */...mask =
4520: 20 66 69 6c 65 50 74 72 2d 3e 72 65 61 64 79 4d filePtr->readyM
4530: 61 73 6b 20 26 20 66 69 6c 65 50 74 72 2d 3e 6d ask & filePtr->m
4540: 61 73 6b 3b 0a 09 66 69 6c 65 50 74 72 2d 3e 72 ask;..filePtr->r
4550: 65 61 64 79 4d 61 73 6b 20 3d 20 30 3b 0a 09 69 eadyMask = 0;..i
4560: 66 20 28 6d 61 73 6b 20 21 3d 20 30 29 20 7b 0a f (mask != 0) {.
4570: 09 20 20 20 20 28 2a 66 69 6c 65 50 74 72 2d 3e . (*filePtr->
4580: 70 72 6f 63 29 28 66 69 6c 65 50 74 72 2d 3e 63 proc)(filePtr->c
4590: 6c 69 65 6e 74 44 61 74 61 2c 20 6d 61 73 6b 29 lientData, mask)
45a0: 3b 0a 09 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 ;..}..break;.
45b0: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b }. return 1;
45c0: 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d .}.../*. *------
45d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
45e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
45f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
4600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
4610: 0a 20 2a 0a 20 2a 20 54 63 6c 5f 57 61 69 74 46 . *. * Tcl_WaitF
4620: 6f 72 45 76 65 6e 74 20 2d 2d 0a 20 2a 0a 20 2a orEvent --. *. *
4630: 09 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 .This function i
4640: 73 20 63 61 6c 6c 65 64 20 62 79 20 54 63 6c 5f s called by Tcl_
4650: 44 6f 4f 6e 65 45 76 65 6e 74 20 74 6f 20 77 61 DoOneEvent to wa
4660: 69 74 20 66 6f 72 20 6e 65 77 0a 20 2a 09 65 76 it for new. *.ev
4670: 65 6e 74 73 20 6f 6e 20 74 68 65 20 6d 65 73 73 ents on the mess
4680: 61 67 65 20 71 75 65 75 65 2e 20 20 49 66 20 74 age queue. If t
4690: 68 65 20 62 6c 6f 63 6b 20 74 69 6d 65 20 69 73 he block time is
46a0: 20 30 2c 20 74 68 65 6e 0a 20 2a 09 54 63 6c 5f 0, then. *.Tcl_
46b0: 57 61 69 74 46 6f 72 45 76 65 6e 74 20 6a 75 73 WaitForEvent jus
46c0: 74 20 70 6f 6c 6c 73 20 77 69 74 68 6f 75 74 20 t polls without
46d0: 62 6c 6f 63 6b 69 6e 67 2e 0a 20 2a 0a 20 2a 20 blocking.. *. *
46e0: 52 65 73 75 6c 74 73 3a 0a 20 2a 09 52 65 74 75 Results:. *.Retu
46f0: 72 6e 73 20 2d 31 20 69 66 20 74 68 65 20 73 65 rns -1 if the se
4700: 6c 65 63 74 20 77 6f 75 6c 64 20 62 6c 6f 63 6b lect would block
4710: 20 66 6f 72 65 76 65 72 2c 20 6f 74 68 65 72 77 forever, otherw
4720: 69 73 65 0a 20 2a 09 72 65 74 75 72 6e 73 20 30 ise. *.returns 0
4730: 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 66 66 .. *. * Side eff
4740: 65 63 74 73 3a 0a 20 2a 09 51 75 65 75 65 73 20 ects:. *.Queues
4750: 66 69 6c 65 20 65 76 65 6e 74 73 20 74 68 61 74 file events that
4760: 20 61 72 65 20 64 65 74 65 63 74 65 64 20 62 79 are detected by
4770: 20 74 68 65 20 73 65 6c 65 63 74 2e 0a 20 2a 0a the select.. *.
4780: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *--------------
4790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
47a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
47b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
47c0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 2f 0a 0a 69 6e --------. */..in
47d0: 74 0a 54 63 6c 5f 57 61 69 74 46 6f 72 45 76 65 t.Tcl_WaitForEve
47e0: 6e 74 28 74 69 6d 65 50 74 72 29 0a 20 20 20 20 nt(timePtr).
47f0: 54 63 6c 5f 54 69 6d 65 20 2a 74 69 6d 65 50 74 Tcl_Time *timePt
4800: 72 3b 09 09 2f 2a 20 4d 61 78 69 6d 75 6d 20 62 r;../* Maximum b
4810: 6c 6f 63 6b 20 74 69 6d 65 2c 20 6f 72 20 4e 55 lock time, or NU
4820: 4c 4c 2e 20 2a 2f 0a 7b 0a 20 20 20 20 46 69 6c LL. */.{. Fil
4830: 65 48 61 6e 64 6c 65 72 20 2a 66 69 6c 65 50 74 eHandler *filePt
4840: 72 3b 0a 20 20 20 20 46 69 6c 65 48 61 6e 64 6c r;. FileHandl
4850: 65 72 45 76 65 6e 74 20 2a 66 69 6c 65 45 76 50 erEvent *fileEvP
4860: 74 72 3b 0a 20 20 20 20 69 6e 74 20 6d 61 73 6b tr;. int mask
4870: 3b 0a 23 69 66 64 65 66 20 54 43 4c 5f 54 48 52 ;.#ifdef TCL_THR
4880: 45 41 44 53 0a 20 20 20 20 69 6e 74 20 77 61 69 EADS. int wai
4890: 74 46 6f 72 46 69 6c 65 73 3b 0a 23 65 6c 73 65 tForFiles;.#else
48a0: 0a 20 20 20 20 2f 2a 20 49 6d 70 6c 2e 20 6e 6f . /* Impl. no
48b0: 74 65 73 3a 20 74 69 6d 65 6f 75 74 20 26 20 74 tes: timeout & t
48c0: 69 6d 65 6f 75 74 50 74 72 20 61 72 65 20 75 73 imeoutPtr are us
48d0: 65 64 20 69 66 2c 20 61 6e 64 20 6f 6e 6c 79 20 ed if, and only
48e0: 69 66 0a 20 20 20 20 20 2a 20 74 68 72 65 61 64 if. * thread
48f0: 73 20 61 72 65 20 6e 6f 74 20 65 6e 61 62 6c 65 s are not enable
4900: 64 2e 20 54 68 65 79 20 61 72 65 20 74 68 65 20 d. They are the
4910: 61 72 67 75 6d 65 6e 74 73 20 66 6f 72 20 74 68 arguments for th
4920: 65 20 72 65 67 75 6c 61 72 0a 20 20 20 20 20 2a e regular. *
4930: 20 73 65 6c 65 63 74 28 29 20 75 73 65 64 20 77 select() used w
4940: 68 65 6e 20 74 68 65 20 63 6f 72 65 20 69 73 20 hen the core is
4950: 6e 6f 74 20 74 68 72 65 61 64 2d 65 6e 61 62 6c not thread-enabl
4960: 65 64 2e 20 2a 2f 0a 0a 20 20 20 20 73 74 72 75 ed. */.. stru
4970: 63 74 20 74 69 6d 65 76 61 6c 20 74 69 6d 65 6f ct timeval timeo
4980: 75 74 2c 20 2a 74 69 6d 65 6f 75 74 50 74 72 3b ut, *timeoutPtr;
4990: 0a 20 20 20 20 69 6e 74 20 6e 75 6d 46 6f 75 6e . int numFoun
49a0: 64 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 54 68 d;.#endif. Th
49b0: 72 65 61 64 53 70 65 63 69 66 69 63 44 61 74 61 readSpecificData
49c0: 20 2a 74 73 64 50 74 72 20 3d 20 54 43 4c 5f 54 *tsdPtr = TCL_T
49d0: 53 44 5f 49 4e 49 54 28 26 64 61 74 61 4b 65 79 SD_INIT(&dataKey
49e0: 29 3b 0a 0a 20 20 20 20 69 66 20 28 74 63 6c 53 );.. if (tclS
49f0: 74 75 62 73 2e 74 63 6c 5f 57 61 69 74 46 6f 72 tubs.tcl_WaitFor
4a00: 45 76 65 6e 74 20 21 3d 20 74 63 6c 4f 72 69 67 Event != tclOrig
4a10: 69 6e 61 6c 4e 6f 74 69 66 69 65 72 2e 77 61 69 inalNotifier.wai
4a20: 74 46 6f 72 45 76 65 6e 74 50 72 6f 63 29 20 7b tForEventProc) {
4a30: 0a 09 72 65 74 75 72 6e 20 74 63 6c 53 74 75 62 ..return tclStub
4a40: 73 2e 74 63 6c 5f 57 61 69 74 46 6f 72 45 76 65 s.tcl_WaitForEve
4a50: 6e 74 28 74 69 6d 65 50 74 72 29 3b 0a 20 20 20 nt(timePtr);.
4a60: 20 7d 0a 0a 23 69 66 6e 64 65 66 20 54 43 4c 5f }..#ifndef TCL_
4a70: 54 48 52 45 41 44 53 0a 20 20 20 20 2f 2a 0a 20 THREADS. /*.
4a80: 20 20 20 20 2a 20 53 65 74 20 75 70 20 74 68 65 * Set up the
4a90: 20 74 69 6d 65 6f 75 74 20 73 74 72 75 63 74 75 timeout structu
4aa0: 72 65 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 69 re. Note that i
4ab0: 66 20 74 68 65 72 65 20 61 72 65 20 6e 6f 20 65 f there are no e
4ac0: 76 65 6e 74 73 20 74 6f 0a 20 20 20 20 20 2a 20 vents to. *
4ad0: 63 68 65 63 6b 20 66 6f 72 2c 20 77 65 20 72 65 check for, we re
4ae0: 74 75 72 6e 20 77 69 74 68 20 61 20 6e 65 67 61 turn with a nega
4af0: 74 69 76 65 20 72 65 73 75 6c 74 20 72 61 74 68 tive result rath
4b00: 65 72 20 74 68 61 6e 20 62 6c 6f 63 6b 69 6e 67 er than blocking
4b10: 0a 20 20 20 20 20 2a 20 66 6f 72 65 76 65 72 2e . * forever.
4b20: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 69 66 . */.. if
4b30: 20 28 74 69 6d 65 50 74 72 29 20 7b 0a 09 74 69 (timePtr) {..ti
4b40: 6d 65 6f 75 74 2e 74 76 5f 73 65 63 20 3d 20 74 meout.tv_sec = t
4b50: 69 6d 65 50 74 72 2d 3e 73 65 63 3b 0a 09 74 69 imePtr->sec;..ti
4b60: 6d 65 6f 75 74 2e 74 76 5f 75 73 65 63 20 3d 20 meout.tv_usec =
4b70: 74 69 6d 65 50 74 72 2d 3e 75 73 65 63 3b 0a 09 timePtr->usec;..
4b80: 74 69 6d 65 6f 75 74 50 74 72 20 3d 20 26 74 69 timeoutPtr = &ti
4b90: 6d 65 6f 75 74 3b 0a 20 20 20 20 7d 20 65 6c 73 meout;. } els
4ba0: 65 20 69 66 20 28 74 73 64 50 74 72 2d 3e 6e 75 e if (tsdPtr->nu
4bb0: 6d 46 64 42 69 74 73 20 3d 3d 20 30 29 20 7b 0a mFdBits == 0) {.
4bc0: 09 2f 2a 0a 09 20 2a 20 49 66 20 74 68 65 72 65 ./*.. * If there
4bd0: 20 61 72 65 20 6e 6f 20 74 68 72 65 61 64 73 2c are no threads,
4be0: 20 6e 6f 20 74 69 6d 65 6f 75 74 2c 20 61 6e 64 no timeout, and
4bf0: 20 6e 6f 20 66 64 73 20 72 65 67 69 73 74 65 72 no fds register
4c00: 65 64 2c 0a 09 20 2a 20 74 68 65 6e 20 74 68 65 ed,.. * then the
4c10: 72 65 20 61 72 65 20 6e 6f 20 65 76 65 6e 74 73 re are no events
4c20: 20 70 6f 73 73 69 62 6c 65 20 61 6e 64 20 77 65 possible and we
4c30: 20 6d 75 73 74 20 61 76 6f 69 64 20 64 65 61 64 must avoid dead
4c40: 6c 6f 63 6b 2e 0a 09 20 2a 20 4e 6f 74 65 20 74 lock... * Note t
4c50: 68 61 74 20 74 68 69 73 20 69 73 20 6e 6f 74 20 hat this is not
4c60: 65 6e 74 69 72 65 6c 79 20 63 6f 72 72 65 63 74 entirely correct
4c70: 20 62 65 63 61 75 73 65 20 74 68 65 72 65 20 6d because there m
4c80: 69 67 68 74 0a 09 20 2a 20 62 65 20 61 20 73 69 ight.. * be a si
4c90: 67 6e 61 6c 20 74 68 61 74 20 63 6f 75 6c 64 20 gnal that could
4ca0: 69 6e 74 65 72 72 75 70 74 20 74 68 65 20 73 65 interrupt the se
4cb0: 6c 65 63 74 20 63 61 6c 6c 2c 20 62 75 74 20 77 lect call, but w
4cc0: 65 0a 09 20 2a 20 64 6f 6e 27 74 20 68 61 6e 64 e.. * don't hand
4cd0: 6c 65 20 74 68 61 74 20 63 61 73 65 20 69 66 20 le that case if
4ce0: 77 65 20 61 72 65 6e 27 74 20 75 73 69 6e 67 20 we aren't using
4cf0: 74 68 72 65 61 64 73 2e 0a 09 20 2a 2f 0a 0a 09 threads... */...
4d00: 72 65 74 75 72 6e 20 2d 31 3b 0a 20 20 20 20 7d return -1;. }
4d10: 20 65 6c 73 65 20 7b 0a 09 74 69 6d 65 6f 75 74 else {..timeout
4d20: 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 Ptr = NULL;.
4d30: 7d 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 }.#endif..#ifdef
4d40: 20 54 43 4c 5f 54 48 52 45 41 44 53 0a 20 20 20 TCL_THREADS.
4d50: 20 2f 2a 0a 20 20 20 20 20 2a 20 50 6c 61 63 65 /*. * Place
4d60: 20 74 68 69 73 20 74 68 72 65 61 64 20 6f 6e 20 this thread on
4d70: 74 68 65 20 6c 69 73 74 20 6f 66 20 69 6e 74 65 the list of inte
4d80: 72 65 73 74 65 64 20 74 68 72 65 61 64 73 2c 20 rested threads,
4d90: 73 69 67 6e 61 6c 20 74 68 65 0a 20 20 20 20 20 signal the.
4da0: 2a 20 6e 6f 74 69 66 69 65 72 20 74 68 72 65 61 * notifier threa
4db0: 64 2c 20 61 6e 64 20 77 61 69 74 20 66 6f 72 20 d, and wait for
4dc0: 61 20 72 65 73 70 6f 6e 73 65 20 6f 72 20 61 20 a response or a
4dd0: 74 69 6d 65 6f 75 74 2e 0a 20 20 20 20 20 2a 2f timeout.. */
4de0: 0a 0a 20 20 20 20 54 63 6c 5f 4d 75 74 65 78 4c .. Tcl_MutexL
4df0: 6f 63 6b 28 26 6e 6f 74 69 66 69 65 72 4d 75 74 ock(¬ifierMut
4e00: 65 78 29 3b 0a 0a 20 20 20 20 77 61 69 74 46 6f ex);.. waitFo
4e10: 72 46 69 6c 65 73 20 3d 20 28 74 73 64 50 74 72 rFiles = (tsdPtr
4e20: 2d 3e 6e 75 6d 46 64 42 69 74 73 20 3e 20 30 29 ->numFdBits > 0)
4e30: 3b 0a 20 20 20 20 69 66 20 28 74 69 6d 65 50 74 ;. if (timePt
4e40: 72 20 21 3d 20 4e 55 4c 4c 20 26 26 20 74 69 6d r != NULL && tim
4e50: 65 50 74 72 2d 3e 73 65 63 20 3d 3d 20 30 20 26 ePtr->sec == 0 &
4e60: 26 20 28 74 69 6d 65 50 74 72 2d 3e 75 73 65 63 & (timePtr->usec
4e70: 20 3d 3d 20 30 0a 23 69 66 20 64 65 66 69 6e 65 == 0.#if define
4e80: 64 28 5f 5f 41 50 50 4c 45 5f 5f 29 20 26 26 20 d(__APPLE__) &&
4e90: 64 65 66 69 6e 65 64 28 5f 5f 4c 50 36 34 5f 5f defined(__LP64__
4ea0: 29 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 ).. /*..
4eb0: 2a 20 4f 6e 20 36 34 2d 62 69 74 20 44 61 72 77 * On 64-bit Darw
4ec0: 69 6e 2c 20 70 74 68 72 65 61 64 5f 63 6f 6e 64 in, pthread_cond
4ed0: 5f 74 69 6d 65 64 77 61 69 74 28 29 20 61 70 70 _timedwait() app
4ee0: 65 61 72 73 20 74 6f 20 68 61 76 65 20 61 20 62 ears to have a b
4ef0: 75 67 0a 09 20 20 20 20 20 2a 20 74 68 61 74 20 ug.. * that
4f00: 63 61 75 73 65 73 20 69 74 20 74 6f 20 77 61 69 causes it to wai
4f10: 74 20 66 6f 72 65 76 65 72 20 77 68 65 6e 20 70 t forever when p
4f20: 61 73 73 65 64 20 61 6e 20 61 62 73 6f 6c 75 74 assed an absolut
4f30: 65 20 74 69 6d 65 20 77 68 69 63 68 0a 09 20 20 e time which..
4f40: 20 20 20 2a 20 68 61 73 20 61 6c 72 65 61 64 79 * has already
4f50: 20 62 65 65 6e 20 65 78 63 65 65 64 65 64 20 62 been exceeded b
4f60: 79 20 74 68 65 20 73 79 73 74 65 6d 20 74 69 6d y the system tim
4f70: 65 3b 20 61 73 20 61 20 77 6f 72 6b 61 72 6f 75 e; as a workarou
4f80: 6e 64 2c 0a 09 20 20 20 20 20 2a 20 77 68 65 6e nd,.. * when
4f90: 20 67 69 76 65 6e 20 61 20 76 65 72 79 20 62 72 given a very br
4fa0: 69 65 66 20 74 69 6d 65 6f 75 74 2c 20 6a 75 73 ief timeout, jus
4fb0: 74 20 64 6f 20 61 20 70 6f 6c 6c 2e 20 5b 42 75 t do a poll. [Bu
4fc0: 67 20 31 34 35 37 37 39 37 5d 0a 09 20 20 20 20 g 1457797]..
4fd0: 20 2a 2f 0a 09 20 20 20 20 7c 7c 20 74 69 6d 65 */.. || time
4fe0: 50 74 72 2d 3e 75 73 65 63 20 3c 20 31 30 0a 23 Ptr->usec < 10.#
4ff0: 65 6e 64 69 66 0a 09 20 20 20 20 29 29 20 7b 0a endif.. )) {.
5000: 09 2f 2a 0a 09 20 2a 20 43 61 6e 6e 6f 74 20 65 ./*.. * Cannot e
5010: 6d 75 6c 61 74 65 20 61 20 70 6f 6c 6c 69 6e 67 mulate a polling
5020: 20 73 65 6c 65 63 74 20 77 69 74 68 20 61 20 70 select with a p
5030: 6f 6c 6c 69 6e 67 20 63 6f 6e 64 69 74 69 6f 6e olling condition
5040: 20 76 61 72 69 61 62 6c 65 2e 0a 09 20 2a 20 49 variable... * I
5050: 6e 73 74 65 61 64 2c 20 70 72 65 74 65 6e 64 20 nstead, pretend
5060: 74 6f 20 77 61 69 74 20 66 6f 72 20 66 69 6c 65 to wait for file
5070: 73 20 61 6e 64 20 74 65 6c 6c 20 74 68 65 20 6e s and tell the n
5080: 6f 74 69 66 69 65 72 0a 09 20 2a 20 74 68 72 65 otifier.. * thre
5090: 61 64 20 77 68 61 74 20 77 65 20 61 72 65 20 64 ad what we are d
50a0: 6f 69 6e 67 2e 20 20 54 68 65 20 6e 6f 74 69 66 oing. The notif
50b0: 69 65 72 20 74 68 72 65 61 64 20 6d 61 6b 65 73 ier thread makes
50c0: 20 73 75 72 65 0a 09 20 2a 20 69 74 20 67 6f 65 sure.. * it goe
50d0: 73 20 74 68 72 6f 75 67 68 20 73 65 6c 65 63 74 s through select
50e0: 20 77 69 74 68 20 69 74 73 20 73 65 6c 65 63 74 with its select
50f0: 20 6d 61 73 6b 20 69 6e 20 74 68 65 20 73 61 6d mask in the sam
5100: 65 20 73 74 61 74 65 0a 09 20 2a 20 61 73 20 6f e state.. * as o
5110: 75 72 73 20 63 75 72 72 65 6e 74 6c 79 20 69 73 urs currently is
5120: 2e 20 20 57 65 20 62 6c 6f 63 6b 20 75 6e 74 69 . We block unti
5130: 6c 20 74 68 61 74 20 68 61 70 70 65 6e 73 2e 0a l that happens..
5140: 09 20 2a 2f 0a 0a 09 77 61 69 74 46 6f 72 46 69 . */...waitForFi
5150: 6c 65 73 20 3d 20 31 3b 0a 09 74 73 64 50 74 72 les = 1;..tsdPtr
5160: 2d 3e 70 6f 6c 6c 53 74 61 74 65 20 3d 20 50 4f ->pollState = PO
5170: 4c 4c 5f 57 41 4e 54 3b 0a 09 74 69 6d 65 50 74 LL_WANT;..timePt
5180: 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 20 r = NULL;. }
5190: 65 6c 73 65 20 7b 0a 09 74 73 64 50 74 72 2d 3e else {..tsdPtr->
51a0: 70 6f 6c 6c 53 74 61 74 65 20 3d 20 30 3b 0a 20 pollState = 0;.
51b0: 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 77 61 }.. if (wa
51c0: 69 74 46 6f 72 46 69 6c 65 73 29 20 7b 0a 20 20 itForFiles) {.
51d0: 20 20 20 20 20 20 2f 2a 0a 20 20 20 20 20 20 20 /*.
51e0: 20 20 2a 20 41 64 64 20 74 68 65 20 54 68 72 65 * Add the Thre
51f0: 61 64 53 70 65 63 69 66 69 63 44 61 74 61 20 73 adSpecificData s
5200: 74 72 75 63 74 75 72 65 20 6f 66 20 74 68 69 73 tructure of this
5210: 20 74 68 72 65 61 64 20 74 6f 20 74 68 65 20 6c thread to the l
5220: 69 73 74 0a 20 20 20 20 20 20 20 20 20 2a 20 6f ist. * o
5230: 66 20 54 68 72 65 61 64 53 70 65 63 69 66 69 63 f ThreadSpecific
5240: 44 61 74 61 20 73 74 72 75 63 74 75 72 65 73 20 Data structures
5250: 6f 66 20 61 6c 6c 20 74 68 72 65 61 64 73 20 74 of all threads t
5260: 68 61 74 20 61 72 65 20 77 61 69 74 69 6e 67 0a hat are waiting.
5270: 20 20 20 20 20 20 20 20 20 2a 20 6f 6e 20 66 69 * on fi
5280: 6c 65 20 65 76 65 6e 74 73 2e 0a 20 20 20 20 20 le events..
5290: 20 20 20 20 2a 2f 0a 0a 0a 20 20 20 20 20 20 20 */...
52a0: 20 74 73 64 50 74 72 2d 3e 6e 65 78 74 50 74 72 tsdPtr->nextPtr
52b0: 20 3d 20 77 61 69 74 69 6e 67 4c 69 73 74 50 74 = waitingListPt
52c0: 72 3b 0a 20 20 20 20 20 20 20 20 69 66 20 28 77 r;. if (w
52d0: 61 69 74 69 6e 67 4c 69 73 74 50 74 72 29 20 7b aitingListPtr) {
52e0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 77 61 69 . wai
52f0: 74 69 6e 67 4c 69 73 74 50 74 72 2d 3e 70 72 65 tingListPtr->pre
5300: 76 50 74 72 20 3d 20 74 73 64 50 74 72 3b 0a 20 vPtr = tsdPtr;.
5310: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 }.
5320: 20 74 73 64 50 74 72 2d 3e 70 72 65 76 50 74 72 tsdPtr->prevPtr
5330: 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 77 61 = 0;. wa
5340: 69 74 69 6e 67 4c 69 73 74 50 74 72 20 3d 20 74 itingListPtr = t
5350: 73 64 50 74 72 3b 0a 09 74 73 64 50 74 72 2d 3e sdPtr;..tsdPtr->
5360: 6f 6e 4c 69 73 74 20 3d 20 31 3b 0a 09 0a 09 77 onList = 1;....w
5370: 72 69 74 65 28 74 72 69 67 67 65 72 50 69 70 65 rite(triggerPipe
5380: 2c 20 22 22 2c 20 31 29 3b 0a 20 20 20 20 7d 0a , "", 1);. }.
5390: 0a 20 20 20 20 46 44 5f 5a 45 52 4f 28 20 26 28 . FD_ZERO( &(
53a0: 74 73 64 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 tsdPtr->readyMas
53b0: 6b 73 2e 72 65 61 64 61 62 6c 65 29 20 29 3b 0a ks.readable) );.
53c0: 20 20 20 20 46 44 5f 5a 45 52 4f 28 20 26 28 74 FD_ZERO( &(t
53d0: 73 64 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 6b sdPtr->readyMask
53e0: 73 2e 77 72 69 74 61 62 6c 65 29 20 29 3b 0a 20 s.writable) );.
53f0: 20 20 20 46 44 5f 5a 45 52 4f 28 20 26 28 74 73 FD_ZERO( &(ts
5400: 64 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 6b 73 dPtr->readyMasks
5410: 2e 65 78 63 65 70 74 69 6f 6e 61 6c 29 20 29 3b .exceptional) );
5420: 0a 0a 20 20 20 20 69 66 20 28 21 74 73 64 50 74 .. if (!tsdPt
5430: 72 2d 3e 65 76 65 6e 74 52 65 61 64 79 29 20 7b r->eventReady) {
5440: 0a 20 20 20 20 20 20 20 20 54 63 6c 5f 43 6f 6e . Tcl_Con
5450: 64 69 74 69 6f 6e 57 61 69 74 28 26 74 73 64 50 ditionWait(&tsdP
5460: 74 72 2d 3e 77 61 69 74 43 56 2c 20 26 6e 6f 74 tr->waitCV, ¬
5470: 69 66 69 65 72 4d 75 74 65 78 2c 20 74 69 6d 65 ifierMutex, time
5480: 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 Ptr);. }.
5490: 74 73 64 50 74 72 2d 3e 65 76 65 6e 74 52 65 61 tsdPtr->eventRea
54a0: 64 79 20 3d 20 30 3b 0a 0a 20 20 20 20 69 66 20 dy = 0;.. if
54b0: 28 77 61 69 74 46 6f 72 46 69 6c 65 73 20 26 26 (waitForFiles &&
54c0: 20 74 73 64 50 74 72 2d 3e 6f 6e 4c 69 73 74 29 tsdPtr->onList)
54d0: 20 7b 0a 09 2f 2a 0a 09 20 2a 20 52 65 6d 6f 76 {../*.. * Remov
54e0: 65 20 74 68 65 20 54 68 72 65 61 64 53 70 65 63 e the ThreadSpec
54f0: 69 66 69 63 44 61 74 61 20 73 74 72 75 63 74 75 ificData structu
5500: 72 65 20 6f 66 20 74 68 69 73 20 74 68 72 65 61 re of this threa
5510: 64 20 66 72 6f 6d 20 74 68 65 0a 09 20 2a 20 77 d from the.. * w
5520: 61 69 74 69 6e 67 20 6c 69 73 74 2e 20 20 41 6c aiting list. Al
5530: 65 72 74 20 74 68 65 20 6e 6f 74 69 66 69 65 72 ert the notifier
5540: 20 74 68 72 65 61 64 20 74 6f 20 72 65 63 6f 6d thread to recom
5550: 70 75 74 65 20 69 74 73 20 73 65 6c 65 63 74 0a pute its select.
5560: 09 20 2a 20 6d 61 73 6b 73 20 2d 20 73 6b 69 70 . * masks - skip
5570: 70 69 6e 67 20 74 68 69 73 20 63 61 75 73 65 64 ping this caused
5580: 20 61 20 68 61 6e 67 20 77 68 65 6e 20 74 72 79 a hang when try
5590: 69 6e 67 20 74 6f 20 63 6c 6f 73 65 20 61 20 70 ing to close a p
55a0: 69 70 65 0a 09 20 2a 20 77 68 69 63 68 20 74 68 ipe.. * which th
55b0: 65 20 6e 6f 74 69 66 69 65 72 20 74 68 72 65 61 e notifier threa
55c0: 64 20 77 61 73 20 73 74 69 6c 6c 20 64 6f 69 6e d was still doin
55d0: 67 20 61 20 73 65 6c 65 63 74 20 6f 6e 2e 0a 09 g a select on...
55e0: 20 2a 2f 0a 0a 20 20 20 20 20 20 20 20 69 66 20 */.. if
55f0: 28 74 73 64 50 74 72 2d 3e 70 72 65 76 50 74 72 (tsdPtr->prevPtr
5600: 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 ) {.
5610: 74 73 64 50 74 72 2d 3e 70 72 65 76 50 74 72 2d tsdPtr->prevPtr-
5620: 3e 6e 65 78 74 50 74 72 20 3d 20 74 73 64 50 74 >nextPtr = tsdPt
5630: 72 2d 3e 6e 65 78 74 50 74 72 3b 0a 20 20 20 20 r->nextPtr;.
5640: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 } else {.
5650: 20 20 20 20 20 20 20 20 20 77 61 69 74 69 6e 67 waiting
5660: 4c 69 73 74 50 74 72 20 3d 20 74 73 64 50 74 72 ListPtr = tsdPtr
5670: 2d 3e 6e 65 78 74 50 74 72 3b 0a 20 20 20 20 20 ->nextPtr;.
5680: 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 66 20 }. if
5690: 28 74 73 64 50 74 72 2d 3e 6e 65 78 74 50 74 72 (tsdPtr->nextPtr
56a0: 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 ) {.
56b0: 74 73 64 50 74 72 2d 3e 6e 65 78 74 50 74 72 2d tsdPtr->nextPtr-
56c0: 3e 70 72 65 76 50 74 72 20 3d 20 74 73 64 50 74 >prevPtr = tsdPt
56d0: 72 2d 3e 70 72 65 76 50 74 72 3b 0a 20 20 20 20 r->prevPtr;.
56e0: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 74 73 }. ts
56f0: 64 50 74 72 2d 3e 6e 65 78 74 50 74 72 20 3d 20 dPtr->nextPtr =
5700: 74 73 64 50 74 72 2d 3e 70 72 65 76 50 74 72 20 tsdPtr->prevPtr
5710: 3d 20 4e 55 4c 4c 3b 0a 09 74 73 64 50 74 72 2d = NULL;..tsdPtr-
5720: 3e 6f 6e 4c 69 73 74 20 3d 20 30 3b 0a 09 77 72 >onList = 0;..wr
5730: 69 74 65 28 74 72 69 67 67 65 72 50 69 70 65 2c ite(triggerPipe,
5740: 20 22 22 2c 20 31 29 3b 0a 20 20 20 20 7d 0a 0a "", 1);. }..
5750: 20 20 20 20 0a 23 65 6c 73 65 0a 20 20 20 20 74 .#else. t
5760: 73 64 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 6b sdPtr->readyMask
5770: 73 20 3d 20 74 73 64 50 74 72 2d 3e 63 68 65 63 s = tsdPtr->chec
5780: 6b 4d 61 73 6b 73 3b 0a 20 20 20 20 6e 75 6d 46 kMasks;. numF
5790: 6f 75 6e 64 20 3d 20 73 65 6c 65 63 74 28 20 74 ound = select( t
57a0: 73 64 50 74 72 2d 3e 6e 75 6d 46 64 42 69 74 73 sdPtr->numFdBits
57b0: 2c 0a 09 09 20 20 20 20 20 20 20 26 28 74 73 64 ,... &(tsd
57c0: 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 6b 73 2e Ptr->readyMasks.
57d0: 72 65 61 64 61 62 6c 65 29 2c 0a 09 09 20 20 20 readable),...
57e0: 20 20 20 20 26 28 74 73 64 50 74 72 2d 3e 72 65 &(tsdPtr->re
57f0: 61 64 79 4d 61 73 6b 73 2e 77 72 69 74 61 62 6c adyMasks.writabl
5800: 65 29 2c 0a 09 09 20 20 20 20 20 20 20 26 28 74 e),... &(t
5810: 73 64 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 6b sdPtr->readyMask
5820: 73 2e 65 78 63 65 70 74 69 6f 6e 61 6c 29 2c 0a s.exceptional),.
5830: 09 09 20 20 20 20 20 20 20 74 69 6d 65 6f 75 74 .. timeout
5840: 50 74 72 20 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 Ptr );.. /*.
5850: 20 20 20 20 2a 20 53 6f 6d 65 20 73 79 73 74 65 * Some syste
5860: 6d 73 20 64 6f 6e 27 74 20 63 6c 65 61 72 20 74 ms don't clear t
5870: 68 65 20 6d 61 73 6b 73 20 61 66 74 65 72 20 61 he masks after a
5880: 6e 20 65 72 72 6f 72 2c 20 73 6f 0a 20 20 20 20 n error, so.
5890: 20 2a 20 77 65 20 68 61 76 65 20 74 6f 20 64 6f * we have to do
58a0: 20 69 74 20 68 65 72 65 2e 0a 20 20 20 20 20 2a it here.. *
58b0: 2f 0a 0a 20 20 20 20 69 66 20 28 6e 75 6d 46 6f /.. if (numFo
58c0: 75 6e 64 20 3d 3d 20 2d 31 29 20 7b 0a 09 46 44 und == -1) {..FD
58d0: 5f 5a 45 52 4f 28 20 26 28 74 73 64 50 74 72 2d _ZERO( &(tsdPtr-
58e0: 3e 72 65 61 64 79 4d 61 73 6b 73 2e 72 65 61 64 >readyMasks.read
58f0: 61 62 6c 65 20 29 20 29 3b 0a 09 46 44 5f 5a 45 able ) );..FD_ZE
5900: 52 4f 28 20 26 28 74 73 64 50 74 72 2d 3e 72 65 RO( &(tsdPtr->re
5910: 61 64 79 4d 61 73 6b 73 2e 77 72 69 74 61 62 6c adyMasks.writabl
5920: 65 20 29 20 29 3b 0a 09 46 44 5f 5a 45 52 4f 28 e ) );..FD_ZERO(
5930: 20 26 28 74 73 64 50 74 72 2d 3e 72 65 61 64 79 &(tsdPtr->ready
5940: 4d 61 73 6b 73 2e 65 78 63 65 70 74 69 6f 6e 61 Masks.exceptiona
5950: 6c 20 29 20 29 3b 0a 20 20 20 20 7d 0a 23 65 6e l ) );. }.#en
5960: 64 69 66 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 dif.. /*.
5970: 20 2a 20 51 75 65 75 65 20 61 6c 6c 20 64 65 74 * Queue all det
5980: 65 63 74 65 64 20 66 69 6c 65 20 65 76 65 6e 74 ected file event
5990: 73 20 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 s before returni
59a0: 6e 67 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ng.. */..
59b0: 20 66 6f 72 20 28 66 69 6c 65 50 74 72 20 3d 20 for (filePtr =
59c0: 74 73 64 50 74 72 2d 3e 66 69 72 73 74 46 69 6c tsdPtr->firstFil
59d0: 65 48 61 6e 64 6c 65 72 50 74 72 3b 20 28 66 69 eHandlerPtr; (fi
59e0: 6c 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 3b 0a lePtr != NULL);.
59f0: 09 20 66 69 6c 65 50 74 72 20 3d 20 66 69 6c 65 . filePtr = file
5a00: 50 74 72 2d 3e 6e 65 78 74 50 74 72 29 20 7b 0a Ptr->nextPtr) {.
5a10: 0a 09 6d 61 73 6b 20 3d 20 30 3b 0a 09 69 66 20 ..mask = 0;..if
5a20: 28 20 46 44 5f 49 53 53 45 54 28 20 66 69 6c 65 ( FD_ISSET( file
5a30: 50 74 72 2d 3e 66 64 2c 20 26 28 74 73 64 50 74 Ptr->fd, &(tsdPt
5a40: 72 2d 3e 72 65 61 64 79 4d 61 73 6b 73 2e 72 65 r->readyMasks.re
5a50: 61 64 61 62 6c 65 29 20 29 20 29 20 7b 0a 09 20 adable) ) ) {..
5a60: 20 20 20 6d 61 73 6b 20 7c 3d 20 54 43 4c 5f 52 mask |= TCL_R
5a70: 45 41 44 41 42 4c 45 3b 0a 09 7d 0a 09 69 66 20 EADABLE;..}..if
5a80: 28 20 46 44 5f 49 53 53 45 54 28 20 66 69 6c 65 ( FD_ISSET( file
5a90: 50 74 72 2d 3e 66 64 2c 20 26 28 74 73 64 50 74 Ptr->fd, &(tsdPt
5aa0: 72 2d 3e 72 65 61 64 79 4d 61 73 6b 73 2e 77 72 r->readyMasks.wr
5ab0: 69 74 61 62 6c 65 29 20 29 20 29 20 7b 0a 09 20 itable) ) ) {..
5ac0: 20 20 20 6d 61 73 6b 20 7c 3d 20 54 43 4c 5f 57 mask |= TCL_W
5ad0: 52 49 54 41 42 4c 45 3b 0a 09 7d 0a 09 69 66 20 RITABLE;..}..if
5ae0: 28 20 46 44 5f 49 53 53 45 54 28 20 66 69 6c 65 ( FD_ISSET( file
5af0: 50 74 72 2d 3e 66 64 2c 20 26 28 74 73 64 50 74 Ptr->fd, &(tsdPt
5b00: 72 2d 3e 72 65 61 64 79 4d 61 73 6b 73 2e 65 78 r->readyMasks.ex
5b10: 63 65 70 74 69 6f 6e 61 6c 29 20 29 20 29 20 7b ceptional) ) ) {
5b20: 0a 09 20 20 20 20 6d 61 73 6b 20 7c 3d 20 54 43 .. mask |= TC
5b30: 4c 5f 45 58 43 45 50 54 49 4f 4e 3b 0a 09 7d 0a L_EXCEPTION;..}.
5b40: 0a 09 69 66 20 28 21 6d 61 73 6b 29 20 7b 0a 09 ..if (!mask) {..
5b50: 20 20 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 09 7d continue;..}
5b60: 0a 0a 09 2f 2a 0a 09 20 2a 20 44 6f 6e 27 74 20 .../*.. * Don't
5b70: 62 6f 74 68 65 72 20 74 6f 20 71 75 65 75 65 20 bother to queue
5b80: 61 6e 20 65 76 65 6e 74 20 69 66 20 74 68 65 20 an event if the
5b90: 6d 61 73 6b 20 77 61 73 20 70 72 65 76 69 6f 75 mask was previou
5ba0: 73 6c 79 0a 09 20 2a 20 6e 6f 6e 2d 7a 65 72 6f sly.. * non-zero
5bb0: 20 73 69 6e 63 65 20 61 6e 20 65 76 65 6e 74 20 since an event
5bc0: 6d 75 73 74 20 73 74 69 6c 6c 20 62 65 20 6f 6e must still be on
5bd0: 20 74 68 65 20 71 75 65 75 65 2e 0a 09 20 2a 2f the queue... */
5be0: 0a 0a 09 69 66 20 28 66 69 6c 65 50 74 72 2d 3e ...if (filePtr->
5bf0: 72 65 61 64 79 4d 61 73 6b 20 3d 3d 20 30 29 20 readyMask == 0)
5c00: 7b 0a 09 20 20 20 20 66 69 6c 65 45 76 50 74 72 {.. fileEvPtr
5c10: 20 3d 20 28 46 69 6c 65 48 61 6e 64 6c 65 72 45 = (FileHandlerE
5c20: 76 65 6e 74 20 2a 29 20 63 6b 61 6c 6c 6f 63 28 vent *) ckalloc(
5c30: 0a 09 09 73 69 7a 65 6f 66 28 46 69 6c 65 48 61 ...sizeof(FileHa
5c40: 6e 64 6c 65 72 45 76 65 6e 74 29 29 3b 0a 09 20 ndlerEvent));..
5c50: 20 20 20 66 69 6c 65 45 76 50 74 72 2d 3e 68 65 fileEvPtr->he
5c60: 61 64 65 72 2e 70 72 6f 63 20 3d 20 46 69 6c 65 ader.proc = File
5c70: 48 61 6e 64 6c 65 72 45 76 65 6e 74 50 72 6f 63 HandlerEventProc
5c80: 3b 0a 09 20 20 20 20 66 69 6c 65 45 76 50 74 72 ;.. fileEvPtr
5c90: 2d 3e 66 64 20 3d 20 66 69 6c 65 50 74 72 2d 3e ->fd = filePtr->
5ca0: 66 64 3b 0a 09 20 20 20 20 54 63 6c 5f 51 75 65 fd;.. Tcl_Que
5cb0: 75 65 45 76 65 6e 74 28 28 54 63 6c 5f 45 76 65 ueEvent((Tcl_Eve
5cc0: 6e 74 20 2a 29 20 66 69 6c 65 45 76 50 74 72 2c nt *) fileEvPtr,
5cd0: 20 54 43 4c 5f 51 55 45 55 45 5f 54 41 49 4c 29 TCL_QUEUE_TAIL)
5ce0: 3b 0a 09 7d 0a 09 66 69 6c 65 50 74 72 2d 3e 72 ;..}..filePtr->r
5cf0: 65 61 64 79 4d 61 73 6b 20 3d 20 6d 61 73 6b 3b eadyMask = mask;
5d00: 0a 20 20 20 20 7d 0a 23 69 66 64 65 66 20 54 43 . }.#ifdef TC
5d10: 4c 5f 54 48 52 45 41 44 53 0a 20 20 20 20 54 63 L_THREADS. Tc
5d20: 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 26 6e l_MutexUnlock(&n
5d30: 6f 74 69 66 69 65 72 4d 75 74 65 78 29 3b 0a 23 otifierMutex);.#
5d40: 65 6e 64 69 66 0a 20 20 20 20 72 65 74 75 72 6e endif. return
5d50: 20 30 3b 0a 7d 0a 0c 0a 23 69 66 64 65 66 20 54 0;.}...#ifdef T
5d60: 43 4c 5f 54 48 52 45 41 44 53 0a 2f 2a 0a 20 2a CL_THREADS./*. *
5d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5da0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
5db0: 2d 2d 2d 2d 2d 2d 0a 20 2a 0a 20 2a 20 4e 6f 74 ------. *. * Not
5dc0: 69 66 69 65 72 54 68 72 65 61 64 50 72 6f 63 20 ifierThreadProc
5dd0: 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 72 6f --. *. *.This ro
5de0: 75 74 69 6e 65 20 69 73 20 74 68 65 20 69 6e 69 utine is the ini
5df0: 74 69 61 6c 20 28 61 6e 64 20 6f 6e 6c 79 29 20 tial (and only)
5e00: 66 75 6e 63 74 69 6f 6e 20 65 78 65 63 75 74 65 function execute
5e10: 64 20 62 79 20 74 68 65 0a 20 2a 09 73 70 65 63 d by the. *.spec
5e20: 69 61 6c 20 6e 6f 74 69 66 69 65 72 20 74 68 72 ial notifier thr
5e30: 65 61 64 2e 20 20 49 74 73 20 6a 6f 62 20 69 73 ead. Its job is
5e40: 20 74 6f 20 77 61 69 74 20 66 6f 72 20 66 69 6c to wait for fil
5e50: 65 20 64 65 73 63 72 69 70 74 6f 72 73 0a 20 2a e descriptors. *
5e60: 09 74 6f 20 62 65 63 6f 6d 65 20 72 65 61 64 61 .to become reada
5e70: 62 6c 65 20 6f 72 20 77 72 69 74 61 62 6c 65 20 ble or writable
5e80: 6f 72 20 74 6f 20 68 61 76 65 20 61 6e 20 65 78 or to have an ex
5e90: 63 65 70 74 69 6f 6e 20 63 6f 6e 64 69 74 69 6f ception conditio
5ea0: 6e 0a 20 2a 09 61 6e 64 20 74 68 65 6e 20 74 6f n. *.and then to
5eb0: 20 6e 6f 74 69 66 79 20 6f 74 68 65 72 20 74 68 notify other th
5ec0: 72 65 61 64 73 20 77 68 6f 20 61 72 65 20 69 6e reads who are in
5ed0: 74 65 72 65 73 74 65 64 20 69 6e 20 74 68 69 73 terested in this
5ee0: 0a 20 2a 09 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 . *.information
5ef0: 62 79 20 73 69 67 6e 61 6c 6c 69 6e 67 20 61 20 by signalling a
5f00: 63 6f 6e 64 69 74 69 6f 6e 20 76 61 72 69 61 62 condition variab
5f10: 6c 65 2e 20 20 4f 74 68 65 72 20 74 68 72 65 61 le. Other threa
5f20: 64 73 0a 20 2a 09 63 61 6e 20 73 69 67 6e 61 6c ds. *.can signal
5f30: 20 74 68 69 73 20 6e 6f 74 69 66 69 65 72 20 74 this notifier t
5f40: 68 72 65 61 64 20 6f 66 20 61 20 63 68 61 6e 67 hread of a chang
5f50: 65 20 69 6e 20 74 68 65 69 72 20 69 6e 74 65 72 e in their inter
5f60: 65 73 74 73 0a 20 2a 09 62 79 20 77 72 69 74 69 ests. *.by writi
5f70: 6e 67 20 61 20 73 69 6e 67 6c 65 20 62 79 74 65 ng a single byte
5f80: 20 74 6f 20 61 20 73 70 65 63 69 61 6c 20 70 69 to a special pi
5f90: 70 65 20 74 68 61 74 20 74 68 65 20 6e 6f 74 69 pe that the noti
5fa0: 66 69 65 72 0a 20 2a 09 74 68 72 65 61 64 20 69 fier. *.thread i
5fb0: 73 20 6d 6f 6e 69 74 6f 72 69 6e 67 2e 0a 20 2a s monitoring.. *
5fc0: 0a 20 2a 20 52 65 73 75 6c 74 3a 0a 20 2a 09 4e . * Result:. *.N
5fd0: 6f 6e 65 2e 20 20 4f 6e 63 65 20 73 74 61 72 74 one. Once start
5fe0: 65 64 2c 20 74 68 69 73 20 72 6f 75 74 69 6e 65 ed, this routine
5ff0: 20 6e 65 76 65 72 20 65 78 69 74 73 2e 20 20 49 never exits. I
6000: 74 20 64 69 65 73 20 77 69 74 68 0a 20 2a 09 74 t dies with. *.t
6010: 68 65 20 6f 76 65 72 61 6c 6c 20 70 72 6f 63 65 he overall proce
6020: 73 73 2e 0a 20 2a 0a 20 2a 20 53 69 64 65 20 65 ss.. *. * Side e
6030: 66 66 65 63 74 73 3a 0a 20 2a 09 54 68 65 20 74 ffects:. *.The t
6040: 72 69 67 67 65 72 20 70 69 70 65 20 75 73 65 64 rigger pipe used
6050: 20 74 6f 20 73 69 67 6e 61 6c 20 74 68 65 20 6e to signal the n
6060: 6f 74 69 66 69 65 72 20 74 68 72 65 61 64 20 69 otifier thread i
6070: 73 20 63 72 65 61 74 65 64 0a 20 2a 09 77 68 65 s created. *.whe
6080: 6e 20 74 68 65 20 6e 6f 74 69 66 69 65 72 20 74 n the notifier t
6090: 68 72 65 61 64 20 66 69 72 73 74 20 73 74 61 72 hread first star
60a0: 74 73 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d ts.. *. *-------
60b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
60c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
60d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
60e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
60f0: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 76 6f 69 64 */..static void
6100: 0a 4e 6f 74 69 66 69 65 72 54 68 72 65 61 64 50 .NotifierThreadP
6110: 72 6f 63 28 63 6c 69 65 6e 74 44 61 74 61 29 0a roc(clientData).
6120: 20 20 20 20 43 6c 69 65 6e 74 44 61 74 61 20 63 ClientData c
6130: 6c 69 65 6e 74 44 61 74 61 3b 09 2f 2a 20 4e 6f lientData;./* No
6140: 74 20 75 73 65 64 2e 20 2a 2f 0a 7b 0a 20 20 20 t used. */.{.
6150: 20 54 68 72 65 61 64 53 70 65 63 69 66 69 63 44 ThreadSpecificD
6160: 61 74 61 20 2a 74 73 64 50 74 72 3b 0a 20 20 20 ata *tsdPtr;.
6170: 20 66 64 5f 73 65 74 20 72 65 61 64 61 62 6c 65 fd_set readable
6180: 4d 61 73 6b 3b 0a 20 20 20 20 66 64 5f 73 65 74 Mask;. fd_set
6190: 20 77 72 69 74 61 62 6c 65 4d 61 73 6b 3b 0a 20 writableMask;.
61a0: 20 20 20 66 64 5f 73 65 74 20 65 78 63 65 70 74 fd_set except
61b0: 69 6f 6e 61 6c 4d 61 73 6b 3b 0a 20 20 20 20 69 ionalMask;. i
61c0: 6e 74 20 66 64 73 5b 32 5d 3b 0a 20 20 20 20 69 nt fds[2];. i
61d0: 6e 74 20 69 2c 20 73 74 61 74 75 73 2c 20 6e 75 nt i, status, nu
61e0: 6d 46 64 42 69 74 73 20 3d 20 30 2c 20 72 65 63 mFdBits = 0, rec
61f0: 65 69 76 65 50 69 70 65 3b 0a 20 20 20 20 6c 6f eivePipe;. lo
6200: 6e 67 20 66 6f 75 6e 64 3b 0a 20 20 20 20 73 74 ng found;. st
6210: 72 75 63 74 20 74 69 6d 65 76 61 6c 20 70 6f 6c ruct timeval pol
6220: 6c 20 3d 20 7b 30 2e 2c 20 30 2e 7d 2c 20 2a 74 l = {0., 0.}, *t
6230: 69 6d 65 50 74 72 3b 0a 20 20 20 20 63 68 61 72 imePtr;. char
6240: 20 62 75 66 5b 32 5d 3b 0a 0a 20 20 20 20 69 66 buf[2];.. if
6250: 20 28 70 69 70 65 28 66 64 73 29 20 21 3d 20 30 (pipe(fds) != 0
6260: 29 20 7b 0a 09 70 61 6e 69 63 28 22 4e 6f 74 69 ) {..panic("Noti
6270: 66 69 65 72 54 68 72 65 61 64 50 72 6f 63 3a 20 fierThreadProc:
6280: 63 6f 75 6c 64 20 6e 6f 74 20 63 72 65 61 74 65 could not create
6290: 20 74 72 69 67 67 65 72 20 70 69 70 65 2e 22 29 trigger pipe.")
62a0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 72 65 63 ;. }.. rec
62b0: 65 69 76 65 50 69 70 65 20 3d 20 66 64 73 5b 30 eivePipe = fds[0
62c0: 5d 3b 0a 0a 23 69 66 6e 64 65 66 20 55 53 45 5f ];..#ifndef USE_
62d0: 46 49 4f 4e 42 49 4f 0a 20 20 20 20 73 74 61 74 FIONBIO. stat
62e0: 75 73 20 3d 20 66 63 6e 74 6c 28 72 65 63 65 69 us = fcntl(recei
62f0: 76 65 50 69 70 65 2c 20 46 5f 47 45 54 46 4c 29 vePipe, F_GETFL)
6300: 3b 0a 20 20 20 20 73 74 61 74 75 73 20 7c 3d 20 ;. status |=
6310: 4f 5f 4e 4f 4e 42 4c 4f 43 4b 3b 0a 20 20 20 20 O_NONBLOCK;.
6320: 69 66 20 28 66 63 6e 74 6c 28 72 65 63 65 69 76 if (fcntl(receiv
6330: 65 50 69 70 65 2c 20 46 5f 53 45 54 46 4c 2c 20 ePipe, F_SETFL,
6340: 73 74 61 74 75 73 29 20 3c 20 30 29 20 7b 0a 09 status) < 0) {..
6350: 70 61 6e 69 63 28 22 4e 6f 74 69 66 69 65 72 54 panic("NotifierT
6360: 68 72 65 61 64 50 72 6f 63 3a 20 63 6f 75 6c 64 hreadProc: could
6370: 20 6e 6f 74 20 6d 61 6b 65 20 72 65 63 65 69 76 not make receiv
6380: 65 20 70 69 70 65 20 6e 6f 6e 20 62 6c 6f 63 6b e pipe non block
6390: 69 6e 67 2e 22 29 3b 0a 20 20 20 20 7d 0a 20 20 ing.");. }.
63a0: 20 20 73 74 61 74 75 73 20 3d 20 66 63 6e 74 6c status = fcntl
63b0: 28 66 64 73 5b 31 5d 2c 20 46 5f 47 45 54 46 4c (fds[1], F_GETFL
63c0: 29 3b 0a 20 20 20 20 73 74 61 74 75 73 20 7c 3d );. status |=
63d0: 20 4f 5f 4e 4f 4e 42 4c 4f 43 4b 3b 0a 20 20 20 O_NONBLOCK;.
63e0: 20 69 66 20 28 66 63 6e 74 6c 28 66 64 73 5b 31 if (fcntl(fds[1
63f0: 5d 2c 20 46 5f 53 45 54 46 4c 2c 20 73 74 61 74 ], F_SETFL, stat
6400: 75 73 29 20 3c 20 30 29 20 7b 0a 09 70 61 6e 69 us) < 0) {..pani
6410: 63 28 22 4e 6f 74 69 66 69 65 72 54 68 72 65 61 c("NotifierThrea
6420: 64 50 72 6f 63 3a 20 63 6f 75 6c 64 20 6e 6f 74 dProc: could not
6430: 20 6d 61 6b 65 20 74 72 69 67 67 65 72 20 70 69 make trigger pi
6440: 70 65 20 6e 6f 6e 20 62 6c 6f 63 6b 69 6e 67 2e pe non blocking.
6450: 22 29 3b 0a 20 20 20 20 7d 0a 23 65 6c 73 65 0a ");. }.#else.
6460: 20 20 20 20 69 66 20 28 69 6f 63 74 6c 28 72 65 if (ioctl(re
6470: 63 65 69 76 65 50 69 70 65 2c 20 28 69 6e 74 29 ceivePipe, (int)
6480: 20 46 49 4f 4e 42 49 4f 2c 20 26 73 74 61 74 75 FIONBIO, &statu
6490: 73 29 20 3c 20 30 29 20 7b 0a 09 70 61 6e 69 63 s) < 0) {..panic
64a0: 28 22 4e 6f 74 69 66 69 65 72 54 68 72 65 61 64 ("NotifierThread
64b0: 50 72 6f 63 3a 20 63 6f 75 6c 64 20 6e 6f 74 20 Proc: could not
64c0: 6d 61 6b 65 20 72 65 63 65 69 76 65 20 70 69 70 make receive pip
64d0: 65 20 6e 6f 6e 20 62 6c 6f 63 6b 69 6e 67 2e 22 e non blocking."
64e0: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 20 );. }. if
64f0: 28 69 6f 63 74 6c 28 66 64 73 5b 31 5d 2c 20 28 (ioctl(fds[1], (
6500: 69 6e 74 29 20 46 49 4f 4e 42 49 4f 2c 20 26 73 int) FIONBIO, &s
6510: 74 61 74 75 73 29 20 3c 20 30 29 20 7b 0a 09 70 tatus) < 0) {..p
6520: 61 6e 69 63 28 22 4e 6f 74 69 66 69 65 72 54 68 anic("NotifierTh
6530: 72 65 61 64 50 72 6f 63 3a 20 63 6f 75 6c 64 20 readProc: could
6540: 6e 6f 74 20 6d 61 6b 65 20 74 72 69 67 67 65 72 not make trigger
6550: 20 70 69 70 65 20 6e 6f 6e 20 62 6c 6f 63 6b 69 pipe non blocki
6560: 6e 67 2e 22 29 3b 0a 20 20 20 20 7d 0a 23 65 6e ng.");. }.#en
6570: 64 69 66 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 dif.. /*.
6580: 20 2a 20 49 6e 73 74 61 6c 6c 20 74 68 65 20 77 * Install the w
6590: 72 69 74 65 20 65 6e 64 20 6f 66 20 74 68 65 20 rite end of the
65a0: 70 69 70 65 20 69 6e 74 6f 20 74 68 65 20 67 6c pipe into the gl
65b0: 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 2e 0a 20 obal variable..
65c0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 54 63 6c 5f */.. Tcl_
65d0: 4d 75 74 65 78 4c 6f 63 6b 28 26 6e 6f 74 69 66 MutexLock(¬if
65e0: 69 65 72 4d 75 74 65 78 29 3b 0a 20 20 20 20 74 ierMutex);. t
65f0: 72 69 67 67 65 72 50 69 70 65 20 3d 20 66 64 73 riggerPipe = fds
6600: 5b 31 5d 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 [1];.. /*.
6610: 20 20 2a 20 53 69 67 6e 61 6c 20 61 6e 79 20 74 * Signal any t
6620: 68 72 65 61 64 73 20 74 68 61 74 20 61 72 65 20 hreads that are
6630: 77 61 69 74 69 6e 67 2e 0a 20 20 20 20 20 2a 2f waiting.. */
6640: 0a 0a 20 20 20 20 54 63 6c 5f 43 6f 6e 64 69 74 .. Tcl_Condit
6650: 69 6f 6e 4e 6f 74 69 66 79 28 26 6e 6f 74 69 66 ionNotify(¬if
6660: 69 65 72 43 56 29 3b 0a 20 20 20 20 54 63 6c 5f ierCV);. Tcl_
6670: 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 26 6e 6f 74 MutexUnlock(¬
6680: 69 66 69 65 72 4d 75 74 65 78 29 3b 0a 0a 20 20 ifierMutex);..
6690: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4c 6f 6f 6b /*. * Look
66a0: 20 66 6f 72 20 66 69 6c 65 20 65 76 65 6e 74 73 for file events
66b0: 20 61 6e 64 20 72 65 70 6f 72 74 20 74 68 65 6d and report them
66c0: 20 74 6f 20 69 6e 74 65 72 65 73 74 65 64 20 74 to interested t
66d0: 68 72 65 61 64 73 2e 0a 20 20 20 20 20 2a 2f 0a hreads.. */.
66e0: 0a 20 20 20 20 77 68 69 6c 65 20 28 31 29 20 7b . while (1) {
66f0: 0a 0a 09 46 44 5f 5a 45 52 4f 28 20 26 72 65 61 ...FD_ZERO( &rea
6700: 64 61 62 6c 65 4d 61 73 6b 20 29 3b 0a 09 46 44 dableMask );..FD
6710: 5f 5a 45 52 4f 28 20 26 77 72 69 74 61 62 6c 65 _ZERO( &writable
6720: 4d 61 73 6b 20 29 3b 0a 09 46 44 5f 5a 45 52 4f Mask );..FD_ZERO
6730: 28 20 26 65 78 63 65 70 74 69 6f 6e 61 6c 4d 61 ( &exceptionalMa
6740: 73 6b 20 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 43 sk );.../*.. * C
6750: 6f 6d 70 75 74 65 20 74 68 65 20 6c 6f 67 69 63 ompute the logic
6760: 61 6c 20 4f 52 20 6f 66 20 74 68 65 20 73 65 6c al OR of the sel
6770: 65 63 74 20 6d 61 73 6b 73 20 66 72 6f 6d 20 61 ect masks from a
6780: 6c 6c 20 74 68 65 0a 09 20 2a 20 77 61 69 74 69 ll the.. * waiti
6790: 6e 67 20 6e 6f 74 69 66 69 65 72 73 2e 0a 09 20 ng notifiers...
67a0: 2a 2f 0a 0a 09 54 63 6c 5f 4d 75 74 65 78 4c 6f */...Tcl_MutexLo
67b0: 63 6b 28 26 6e 6f 74 69 66 69 65 72 4d 75 74 65 ck(¬ifierMute
67c0: 78 29 3b 0a 09 74 69 6d 65 50 74 72 20 3d 20 4e x);..timePtr = N
67d0: 55 4c 4c 3b 0a 20 20 20 20 20 20 20 20 66 6f 72 ULL;. for
67e0: 20 28 74 73 64 50 74 72 20 3d 20 77 61 69 74 69 (tsdPtr = waiti
67f0: 6e 67 4c 69 73 74 50 74 72 3b 20 74 73 64 50 74 ngListPtr; tsdPt
6800: 72 3b 20 74 73 64 50 74 72 20 3d 20 74 73 64 50 r; tsdPtr = tsdP
6810: 74 72 2d 3e 6e 65 78 74 50 74 72 29 20 7b 0a 09 tr->nextPtr) {..
6820: 20 20 20 20 66 6f 72 20 28 20 69 20 3d 20 74 73 for ( i = ts
6830: 64 50 74 72 2d 3e 6e 75 6d 46 64 42 69 74 73 2d dPtr->numFdBits-
6840: 31 3b 20 69 20 3e 3d 20 30 3b 20 2d 2d 69 20 29 1; i >= 0; --i )
6850: 20 7b 0a 09 09 69 66 20 28 20 46 44 5f 49 53 53 {...if ( FD_ISS
6860: 45 54 28 20 69 2c 20 26 28 74 73 64 50 74 72 2d ET( i, &(tsdPtr-
6870: 3e 63 68 65 63 6b 4d 61 73 6b 73 2e 72 65 61 64 >checkMasks.read
6880: 61 62 6c 65 29 20 29 20 29 20 7b 0a 09 09 20 20 able) ) ) {...
6890: 20 20 46 44 5f 53 45 54 28 20 69 2c 20 26 72 65 FD_SET( i, &re
68a0: 61 64 61 62 6c 65 4d 61 73 6b 20 29 3b 0a 09 09 adableMask );...
68b0: 7d 0a 09 09 69 66 20 28 20 46 44 5f 49 53 53 45 }...if ( FD_ISSE
68c0: 54 28 20 69 2c 20 26 28 74 73 64 50 74 72 2d 3e T( i, &(tsdPtr->
68d0: 63 68 65 63 6b 4d 61 73 6b 73 2e 77 72 69 74 61 checkMasks.writa
68e0: 62 6c 65 29 20 29 20 29 20 7b 0a 09 09 20 20 20 ble) ) ) {...
68f0: 20 46 44 5f 53 45 54 28 20 69 2c 20 26 77 72 69 FD_SET( i, &wri
6900: 74 61 62 6c 65 4d 61 73 6b 20 29 3b 0a 09 09 7d tableMask );...}
6910: 0a 09 09 69 66 20 28 20 46 44 5f 49 53 53 45 54 ...if ( FD_ISSET
6920: 28 20 69 2c 20 26 28 74 73 64 50 74 72 2d 3e 63 ( i, &(tsdPtr->c
6930: 68 65 63 6b 4d 61 73 6b 73 2e 65 78 63 65 70 74 heckMasks.except
6940: 69 6f 6e 61 6c 29 20 29 20 29 20 7b 0a 09 09 20 ional) ) ) {...
6950: 20 20 20 46 44 5f 53 45 54 28 20 69 2c 20 26 65 FD_SET( i, &e
6960: 78 63 65 70 74 69 6f 6e 61 6c 4d 61 73 6b 20 29 xceptionalMask )
6970: 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 20 20 ;...}.. }..
6980: 20 20 69 66 20 28 20 74 73 64 50 74 72 2d 3e 6e if ( tsdPtr->n
6990: 75 6d 46 64 42 69 74 73 20 3e 20 6e 75 6d 46 64 umFdBits > numFd
69a0: 42 69 74 73 20 29 20 7b 0a 09 09 6e 75 6d 46 64 Bits ) {...numFd
69b0: 42 69 74 73 20 3d 20 74 73 64 50 74 72 2d 3e 6e Bits = tsdPtr->n
69c0: 75 6d 46 64 42 69 74 73 3b 0a 09 20 20 20 20 7d umFdBits;.. }
69d0: 0a 09 20 20 20 20 69 66 20 28 74 73 64 50 74 72 .. if (tsdPtr
69e0: 2d 3e 70 6f 6c 6c 53 74 61 74 65 20 26 20 50 4f ->pollState & PO
69f0: 4c 4c 5f 57 41 4e 54 29 20 7b 0a 09 09 2f 2a 0a LL_WANT) {.../*.
6a00: 09 09 20 2a 20 48 65 72 65 20 77 65 20 6d 61 6b .. * Here we mak
6a10: 65 20 73 75 72 65 20 77 65 20 67 6f 20 74 68 72 e sure we go thr
6a20: 6f 75 67 68 20 73 65 6c 65 63 74 28 29 20 77 69 ough select() wi
6a30: 74 68 20 74 68 65 20 73 61 6d 65 0a 09 09 20 2a th the same... *
6a40: 20 6d 61 73 6b 20 62 69 74 73 20 74 68 61 74 20 mask bits that
6a50: 77 65 72 65 20 70 72 65 73 65 6e 74 20 77 68 65 were present whe
6a60: 6e 20 74 68 65 20 74 68 72 65 61 64 20 74 72 69 n the thread tri
6a70: 65 64 20 74 6f 20 70 6f 6c 6c 2e 0a 09 09 20 2a ed to poll.... *
6a80: 2f 0a 0a 09 09 74 73 64 50 74 72 2d 3e 70 6f 6c /....tsdPtr->pol
6a90: 6c 53 74 61 74 65 20 7c 3d 20 50 4f 4c 4c 5f 44 lState |= POLL_D
6aa0: 4f 4e 45 3b 0a 09 09 74 69 6d 65 50 74 72 20 3d ONE;...timePtr =
6ab0: 20 26 70 6f 6c 6c 3b 0a 09 20 20 20 20 7d 0a 09 &poll;.. }..
6ac0: 7d 0a 09 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f }..Tcl_MutexUnlo
6ad0: 63 6b 28 26 6e 6f 74 69 66 69 65 72 4d 75 74 65 ck(¬ifierMute
6ae0: 78 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 74 x);.../*.. * Set
6af0: 20 75 70 20 74 68 65 20 73 65 6c 65 63 74 20 6d up the select m
6b00: 61 73 6b 20 74 6f 20 69 6e 63 6c 75 64 65 20 74 ask to include t
6b10: 68 65 20 72 65 63 65 69 76 65 20 70 69 70 65 2e he receive pipe.
6b20: 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 20 72 65 63 .. */...if ( rec
6b30: 65 69 76 65 50 69 70 65 20 3e 3d 20 6e 75 6d 46 eivePipe >= numF
6b40: 64 42 69 74 73 20 29 20 7b 0a 09 20 20 20 20 6e dBits ) {.. n
6b50: 75 6d 46 64 42 69 74 73 20 3d 20 72 65 63 65 69 umFdBits = recei
6b60: 76 65 50 69 70 65 20 2b 20 31 3b 0a 09 7d 0a 09 vePipe + 1;..}..
6b70: 46 44 5f 53 45 54 28 20 72 65 63 65 69 76 65 50 FD_SET( receiveP
6b80: 69 70 65 2c 20 26 72 65 61 64 61 62 6c 65 4d 61 ipe, &readableMa
6b90: 73 6b 20 29 3b 0a 0a 09 69 66 20 28 20 73 65 6c sk );...if ( sel
6ba0: 65 63 74 28 20 6e 75 6d 46 64 42 69 74 73 2c 20 ect( numFdBits,
6bb0: 26 72 65 61 64 61 62 6c 65 4d 61 73 6b 2c 20 26 &readableMask, &
6bc0: 77 72 69 74 61 62 6c 65 4d 61 73 6b 2c 0a 09 09 writableMask,...
6bd0: 20 20 20 20 20 26 65 78 63 65 70 74 69 6f 6e 61 &exceptiona
6be0: 6c 4d 61 73 6b 2c 20 74 69 6d 65 50 74 72 29 20 lMask, timePtr)
6bf0: 3d 3d 20 2d 31 20 29 20 7b 0a 09 20 20 20 20 2f == -1 ) {.. /
6c00: 2a 0a 09 20 20 20 20 20 2a 20 54 72 79 20 61 67 *.. * Try ag
6c10: 61 69 6e 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 ain immediately
6c20: 6f 6e 20 61 6e 20 65 72 72 6f 72 2e 0a 09 20 20 on an error...
6c30: 20 20 20 2a 2f 0a 0a 09 20 20 20 20 63 6f 6e 74 */... cont
6c40: 69 6e 75 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a inue;. }.
6c50: 0a 09 2f 2a 0a 09 20 2a 20 41 6c 65 72 74 20 61 ../*.. * Alert a
6c60: 6e 79 20 74 68 72 65 61 64 73 20 74 68 61 74 20 ny threads that
6c70: 61 72 65 20 77 61 69 74 69 6e 67 20 6f 6e 20 61 are waiting on a
6c80: 20 72 65 61 64 79 20 66 69 6c 65 20 64 65 73 63 ready file desc
6c90: 72 69 70 74 6f 72 2e 0a 09 20 2a 2f 0a 0a 09 54 riptor... */...T
6ca0: 63 6c 5f 4d 75 74 65 78 4c 6f 63 6b 28 26 6e 6f cl_MutexLock(&no
6cb0: 74 69 66 69 65 72 4d 75 74 65 78 29 3b 0a 20 20 tifierMutex);.
6cc0: 20 20 20 20 20 20 66 6f 72 20 28 74 73 64 50 74 for (tsdPt
6cd0: 72 20 3d 20 77 61 69 74 69 6e 67 4c 69 73 74 50 r = waitingListP
6ce0: 74 72 3b 20 74 73 64 50 74 72 3b 20 74 73 64 50 tr; tsdPtr; tsdP
6cf0: 74 72 20 3d 20 74 73 64 50 74 72 2d 3e 6e 65 78 tr = tsdPtr->nex
6d00: 74 50 74 72 29 20 7b 0a 09 20 20 20 20 66 6f 75 tPtr) {.. fou
6d10: 6e 64 20 3d 20 30 3b 0a 0a 09 20 20 20 20 66 6f nd = 0;... fo
6d20: 72 20 28 20 69 20 3d 20 74 73 64 50 74 72 2d 3e r ( i = tsdPtr->
6d30: 6e 75 6d 46 64 42 69 74 73 2d 31 3b 20 69 20 3e numFdBits-1; i >
6d40: 3d 20 30 3b 20 2d 2d 69 20 29 20 7b 0a 09 09 69 = 0; --i ) {...i
6d50: 66 20 28 20 46 44 5f 49 53 53 45 54 28 20 69 2c f ( FD_ISSET( i,
6d60: 20 26 28 74 73 64 50 74 72 2d 3e 63 68 65 63 6b &(tsdPtr->check
6d70: 4d 61 73 6b 73 2e 72 65 61 64 61 62 6c 65 29 20 Masks.readable)
6d80: 29 0a 09 09 20 20 20 20 20 26 26 20 46 44 5f 49 )... && FD_I
6d90: 53 53 45 54 28 20 69 2c 20 26 72 65 61 64 61 62 SSET( i, &readab
6da0: 6c 65 4d 61 73 6b 20 29 20 29 20 7b 0a 09 09 20 leMask ) ) {...
6db0: 20 20 20 46 44 5f 53 45 54 28 20 69 2c 20 26 28 FD_SET( i, &(
6dc0: 74 73 64 50 74 72 2d 3e 72 65 61 64 79 4d 61 73 tsdPtr->readyMas
6dd0: 6b 73 2e 72 65 61 64 61 62 6c 65 29 20 29 3b 0a ks.readable) );.
6de0: 09 09 20 20 20 20 66 6f 75 6e 64 20 3d 20 31 3b .. found = 1;
6df0: 0a 09 09 7d 0a 09 09 69 66 20 28 20 46 44 5f 49 ...}...if ( FD_I
6e00: 53 53 45 54 28 20 69 2c 20 26 28 74 73 64 50 74 SSET( i, &(tsdPt
6e10: 72 2d 3e 63 68 65 63 6b 4d 61 73 6b 73 2e 77 72 r->checkMasks.wr
6e20: 69 74 61 62 6c 65 29 20 29 0a 09 09 20 20 20 20 itable) )...
6e30: 20 26 26 20 46 44 5f 49 53 53 45 54 28 20 69 2c && FD_ISSET( i,
6e40: 20 26 77 72 69 74 61 62 6c 65 4d 61 73 6b 20 29 &writableMask )
6e50: 20 29 20 7b 0a 09 09 20 20 20 20 46 44 5f 53 45 ) {... FD_SE
6e60: 54 28 20 69 2c 20 26 28 74 73 64 50 74 72 2d 3e T( i, &(tsdPtr->
6e70: 72 65 61 64 79 4d 61 73 6b 73 2e 77 72 69 74 61 readyMasks.writa
6e80: 62 6c 65 29 20 29 3b 0a 09 09 20 20 20 20 66 6f ble) );... fo
6e90: 75 6e 64 20 3d 20 31 3b 0a 09 09 7d 0a 09 09 69 und = 1;...}...i
6ea0: 66 20 28 20 46 44 5f 49 53 53 45 54 28 20 69 2c f ( FD_ISSET( i,
6eb0: 20 26 28 74 73 64 50 74 72 2d 3e 63 68 65 63 6b &(tsdPtr->check
6ec0: 4d 61 73 6b 73 2e 65 78 63 65 70 74 69 6f 6e 61 Masks.exceptiona
6ed0: 6c 29 20 29 0a 09 09 20 20 20 20 20 26 26 20 46 l) )... && F
6ee0: 44 5f 49 53 53 45 54 28 20 69 2c 20 26 65 78 63 D_ISSET( i, &exc
6ef0: 65 70 74 69 6f 6e 61 6c 4d 61 73 6b 20 29 20 29 eptionalMask ) )
6f00: 20 7b 0a 09 09 20 20 20 20 46 44 5f 53 45 54 28 {... FD_SET(
6f10: 20 69 2c 20 26 28 74 73 64 50 74 72 2d 3e 72 65 i, &(tsdPtr->re
6f20: 61 64 79 4d 61 73 6b 73 2e 65 78 63 65 70 74 69 adyMasks.excepti
6f30: 6f 6e 61 6c 29 20 29 3b 0a 09 09 20 20 20 20 66 onal) );... f
6f40: 6f 75 6e 64 20 3d 20 31 3b 0a 09 09 7d 0a 09 20 ound = 1;...}..
6f50: 20 20 20 7d 0a 0a 20 20 20 20 20 20 20 20 20 20 }..
6f60: 20 20 69 66 20 28 66 6f 75 6e 64 20 7c 7c 20 28 if (found || (
6f70: 74 73 64 50 74 72 2d 3e 70 6f 6c 6c 53 74 61 74 tsdPtr->pollStat
6f80: 65 20 26 20 50 4f 4c 4c 5f 44 4f 4e 45 29 29 20 e & POLL_DONE))
6f90: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
6fa0: 20 20 74 73 64 50 74 72 2d 3e 65 76 65 6e 74 52 tsdPtr->eventR
6fb0: 65 61 64 79 20 3d 20 31 3b 0a 09 09 69 66 20 28 eady = 1;...if (
6fc0: 74 73 64 50 74 72 2d 3e 6f 6e 4c 69 73 74 29 20 tsdPtr->onList)
6fd0: 7b 0a 09 09 20 20 20 20 2f 2a 0a 09 09 20 20 20 {... /*...
6fe0: 20 20 2a 20 52 65 6d 6f 76 65 20 74 68 65 20 54 * Remove the T
6ff0: 68 72 65 61 64 53 70 65 63 69 66 69 63 44 61 74 hreadSpecificDat
7000: 61 20 73 74 72 75 63 74 75 72 65 20 6f 66 20 74 a structure of t
7010: 68 69 73 0a 09 09 20 20 20 20 20 2a 20 74 68 72 his... * thr
7020: 65 61 64 20 66 72 6f 6d 20 74 68 65 20 77 61 69 ead from the wai
7030: 74 69 6e 67 20 6c 69 73 74 2e 20 54 68 69 73 20 ting list. This
7040: 70 72 65 76 65 6e 74 73 20 75 73 20 66 72 6f 6d prevents us from
7050: 0a 09 09 20 20 20 20 20 2a 20 63 6f 6e 74 69 6e ... * contin
7060: 75 6f 75 73 6c 79 20 73 70 69 6e 69 6e 67 20 6f uously spining o
7070: 6e 20 73 65 6c 65 63 74 20 75 6e 74 69 6c 20 74 n select until t
7080: 68 65 20 6f 74 68 65 72 0a 09 09 20 20 20 20 20 he other...
7090: 2a 20 74 68 72 65 61 64 73 20 72 75 6e 73 20 61 * threads runs a
70a0: 6e 64 20 73 65 72 76 69 63 65 73 20 74 68 65 20 nd services the
70b0: 66 69 6c 65 20 65 76 65 6e 74 2e 0a 09 09 20 20 file event....
70c0: 20 20 20 2a 2f 0a 0a 09 09 20 20 20 20 69 66 20 */.... if
70d0: 28 74 73 64 50 74 72 2d 3e 70 72 65 76 50 74 72 (tsdPtr->prevPtr
70e0: 29 20 7b 0a 09 09 09 74 73 64 50 74 72 2d 3e 70 ) {....tsdPtr->p
70f0: 72 65 76 50 74 72 2d 3e 6e 65 78 74 50 74 72 20 revPtr->nextPtr
7100: 3d 20 74 73 64 50 74 72 2d 3e 6e 65 78 74 50 74 = tsdPtr->nextPt
7110: 72 3b 0a 09 09 20 20 20 20 7d 20 65 6c 73 65 20 r;... } else
7120: 7b 0a 09 09 09 77 61 69 74 69 6e 67 4c 69 73 74 {....waitingList
7130: 50 74 72 20 3d 20 74 73 64 50 74 72 2d 3e 6e 65 Ptr = tsdPtr->ne
7140: 78 74 50 74 72 3b 0a 09 09 20 20 20 20 7d 0a 09 xtPtr;... }..
7150: 09 20 20 20 20 69 66 20 28 74 73 64 50 74 72 2d . if (tsdPtr-
7160: 3e 6e 65 78 74 50 74 72 29 20 7b 0a 09 09 09 74 >nextPtr) {....t
7170: 73 64 50 74 72 2d 3e 6e 65 78 74 50 74 72 2d 3e sdPtr->nextPtr->
7180: 70 72 65 76 50 74 72 20 3d 20 74 73 64 50 74 72 prevPtr = tsdPtr
7190: 2d 3e 70 72 65 76 50 74 72 3b 0a 09 09 20 20 20 ->prevPtr;...
71a0: 20 7d 0a 09 09 20 20 20 20 74 73 64 50 74 72 2d }... tsdPtr-
71b0: 3e 6e 65 78 74 50 74 72 20 3d 20 74 73 64 50 74 >nextPtr = tsdPt
71c0: 72 2d 3e 70 72 65 76 50 74 72 20 3d 20 4e 55 4c r->prevPtr = NUL
71d0: 4c 3b 0a 09 09 20 20 20 20 74 73 64 50 74 72 2d L;... tsdPtr-
71e0: 3e 6f 6e 4c 69 73 74 20 3d 20 30 3b 0a 09 09 20 >onList = 0;...
71f0: 20 20 20 74 73 64 50 74 72 2d 3e 70 6f 6c 6c 53 tsdPtr->pollS
7200: 74 61 74 65 20 3d 20 30 3b 0a 09 09 7d 0a 09 09 tate = 0;...}...
7210: 54 63 6c 5f 43 6f 6e 64 69 74 69 6f 6e 4e 6f 74 Tcl_ConditionNot
7220: 69 66 79 28 26 74 73 64 50 74 72 2d 3e 77 61 69 ify(&tsdPtr->wai
7230: 74 43 56 29 3b 0a 20 20 20 20 20 20 20 20 20 20 tCV);.
7240: 20 20 7d 0a 20 20 20 20 20 20 20 20 7d 0a 09 54 }. }..T
7250: 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 26 cl_MutexUnlock(&
7260: 6e 6f 74 69 66 69 65 72 4d 75 74 65 78 29 3b 0a notifierMutex);.
7270: 0a 09 2f 2a 0a 09 20 2a 20 43 6f 6e 73 75 6d 65 ../*.. * Consume
7280: 20 74 68 65 20 6e 65 78 74 20 62 79 74 65 20 66 the next byte f
7290: 72 6f 6d 20 74 68 65 20 6e 6f 74 69 66 69 65 72 rom the notifier
72a0: 20 70 69 70 65 20 69 66 20 74 68 65 20 70 69 70 pipe if the pip
72b0: 65 20 77 61 73 0a 09 20 2a 20 72 65 61 64 61 62 e was.. * readab
72c0: 6c 65 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 74 le. Note that t
72d0: 68 65 72 65 20 6d 61 79 20 62 65 20 6d 75 6c 74 here may be mult
72e0: 69 70 6c 65 20 62 79 74 65 73 20 70 65 6e 64 69 iple bytes pendi
72f0: 6e 67 2c 20 62 75 74 0a 09 20 2a 20 74 6f 20 61 ng, but.. * to a
7300: 76 6f 69 64 20 61 20 72 61 63 65 20 63 6f 6e 64 void a race cond
7310: 69 74 69 6f 6e 20 77 65 20 6f 6e 6c 79 20 72 65 ition we only re
7320: 61 64 20 6f 6e 65 20 61 74 20 61 20 74 69 6d 65 ad one at a time
7330: 2e 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 20 46 44 ... */...if ( FD
7340: 5f 49 53 53 45 54 28 20 72 65 63 65 69 76 65 50 _ISSET( receiveP
7350: 69 70 65 2c 20 26 72 65 61 64 61 62 6c 65 4d 61 ipe, &readableMa
7360: 73 6b 20 29 20 29 20 7b 0a 09 20 20 20 20 69 20 sk ) ) {.. i
7370: 3d 20 72 65 61 64 28 72 65 63 65 69 76 65 50 69 = read(receivePi
7380: 70 65 2c 20 62 75 66 2c 20 31 29 3b 0a 0a 09 20 pe, buf, 1);...
7390: 20 20 20 69 66 20 28 28 69 20 3d 3d 20 30 29 20 if ((i == 0)
73a0: 7c 7c 20 28 28 69 20 3d 3d 20 31 29 20 26 26 20 || ((i == 1) &&
73b0: 28 62 75 66 5b 30 5d 20 3d 3d 20 27 71 27 29 29 (buf[0] == 'q'))
73c0: 29 20 7b 0a 09 09 2f 2a 0a 09 09 20 2a 20 53 6f ) {.../*... * So
73d0: 6d 65 6f 6e 65 20 63 6c 6f 73 65 64 20 74 68 65 meone closed the
73e0: 20 77 72 69 74 65 20 65 6e 64 20 6f 66 20 74 68 write end of th
73f0: 65 20 70 69 70 65 20 6f 72 20 73 65 6e 74 20 75 e pipe or sent u
7400: 73 20 61 0a 09 09 20 2a 20 51 75 69 74 20 6d 65 s a... * Quit me
7410: 73 73 61 67 65 20 5b 42 75 67 3a 20 34 31 33 39 ssage [Bug: 4139
7420: 5d 20 61 6e 64 20 74 68 65 6e 20 63 6c 6f 73 65 ] and then close
7430: 64 20 74 68 65 20 77 72 69 74 65 20 65 6e 64 0a d the write end.
7440: 09 09 20 2a 20 6f 66 20 74 68 65 20 70 69 70 65 .. * of the pipe
7450: 20 73 6f 20 77 65 20 6e 65 65 64 20 74 6f 20 73 so we need to s
7460: 68 75 74 20 64 6f 77 6e 20 74 68 65 20 6e 6f 74 hut down the not
7470: 69 66 69 65 72 20 74 68 72 65 61 64 2e 0a 09 09 ifier thread....
7480: 20 2a 2f 0a 0a 09 09 62 72 65 61 6b 3b 0a 09 20 */....break;..
7490: 20 20 20 7d 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 }..}. }..
74a0: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 65 /*. * Cle
74b0: 61 6e 20 75 70 20 74 68 65 20 72 65 61 64 20 65 an up the read e
74c0: 6e 64 20 6f 66 20 74 68 65 20 70 69 70 65 20 61 nd of the pipe a
74d0: 6e 64 20 73 69 67 6e 61 6c 20 61 6e 79 20 74 68 nd signal any th
74e0: 72 65 61 64 73 20 77 61 69 74 69 6e 67 20 6f 6e reads waiting on
74f0: 0a 20 20 20 20 20 2a 20 74 65 72 6d 69 6e 61 74 . * terminat
7500: 69 6f 6e 20 6f 66 20 74 68 65 20 6e 6f 74 69 66 ion of the notif
7510: 69 65 72 20 74 68 72 65 61 64 2e 0a 20 20 20 20 ier thread..
7520: 20 2a 2f 0a 0a 20 20 20 20 63 6c 6f 73 65 28 72 */.. close(r
7530: 65 63 65 69 76 65 50 69 70 65 29 3b 0a 20 20 20 eceivePipe);.
7540: 20 54 63 6c 5f 4d 75 74 65 78 4c 6f 63 6b 28 26 Tcl_MutexLock(&
7550: 6e 6f 74 69 66 69 65 72 4d 75 74 65 78 29 3b 0a notifierMutex);.
7560: 20 20 20 20 74 72 69 67 67 65 72 50 69 70 65 20 triggerPipe
7570: 3d 20 2d 31 3b 0a 20 20 20 20 54 63 6c 5f 43 6f = -1;. Tcl_Co
7580: 6e 64 69 74 69 6f 6e 4e 6f 74 69 66 79 28 26 6e nditionNotify(&n
7590: 6f 74 69 66 69 65 72 43 56 29 3b 0a 20 20 20 20 otifierCV);.
75a0: 54 63 6c 5f 4d 75 74 65 78 55 6e 6c 6f 63 6b 28 Tcl_MutexUnlock(
75b0: 26 6e 6f 74 69 66 69 65 72 4d 75 74 65 78 29 3b ¬ifierMutex);
75c0: 0a 0a 20 20 20 20 54 63 6c 70 54 68 72 65 61 64 .. TclpThread
75d0: 45 78 69 74 20 28 30 29 3b 0a 7d 0a 23 65 6e 64 Exit (0);.}.#end
75e0: 69 66 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 48 41 if..#endif /* HA
75f0: 56 45 5f 43 4f 52 45 46 4f 55 4e 44 41 54 49 4f VE_COREFOUNDATIO
7600: 4e 20 2a 2f 0a N */.