Tcl Source Code

Hex Artifact Content
Login

Artifact b5119e6e6b0213a3a399e1a73a4178e9c6d1eb8d:

Attachment "731356.patch" to ticket [731356ffff] added by dgp 2003-11-15 04:15:01.
0000: 49 6e 64 65 78 3a 20 67 65 6e 65 72 69 63 2f 74  Index: generic/t
0010: 63 6c 2e 68 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  cl.h.===========
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0050: 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c  ========.RCS fil
0060: 65 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f  e: /cvsroot/tcl/
0070: 74 63 6c 2f 67 65 6e 65 72 69 63 2f 74 63 6c 2e  tcl/generic/tcl.
0080: 68 2c 76 0a 72 65 74 72 69 65 76 69 6e 67 20 72  h,v.retrieving r
0090: 65 76 69 73 69 6f 6e 20 31 2e 31 36 37 0a 64 69  evision 1.167.di
00a0: 66 66 20 2d 75 20 2d 72 31 2e 31 36 37 20 74 63  ff -u -r1.167 tc
00b0: 6c 2e 68 0a 2d 2d 2d 20 67 65 6e 65 72 69 63 2f  l.h.--- generic/
00c0: 74 63 6c 2e 68 09 31 34 20 4e 6f 76 20 32 30 30  tcl.h.14 Nov 200
00d0: 33 20 32 30 3a 34 34 3a 34 34 20 2d 30 30 30 30  3 20:44:44 -0000
00e0: 09 31 2e 31 36 37 0a 2b 2b 2b 20 67 65 6e 65 72  .1.167.+++ gener
00f0: 69 63 2f 74 63 6c 2e 68 09 31 34 20 4e 6f 76 20  ic/tcl.h.14 Nov 
0100: 32 30 30 33 20 32 31 3a 31 33 3a 31 39 20 2d 30  2003 21:13:19 -0
0110: 30 30 30 0a 40 40 20 2d 31 31 36 39 2c 38 20 2b  000.@@ -1169,8 +
0120: 31 31 36 39 2c 31 33 20 40 40 0a 20 20 2a 09 09  1169,13 @@.  *..
0130: 09 09 68 61 73 68 20 74 61 62 6c 65 20 77 69 6c  ..hash table wil
0140: 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 72 65 63  l attempt to rec
0150: 74 69 66 79 20 74 68 69 73 20 62 79 0a 20 20 2a  tify this by.  *
0160: 09 09 09 09 72 61 6e 64 6f 6d 69 73 69 6e 67 20  ....randomising 
0170: 74 68 65 20 62 69 74 73 20 61 6e 64 20 74 68 65  the bits and the
0180: 6e 20 75 73 69 6e 67 20 74 68 65 20 75 70 70 65  n using the uppe
0190: 72 0a 20 20 2a 09 09 09 09 4e 20 62 69 74 73 20  r.  *....N bits 
01a0: 61 73 20 74 68 65 20 69 6e 64 65 78 20 69 6e 74  as the index int
01b0: 6f 20 74 68 65 20 74 61 62 6c 65 2e 0a 2b 20 2a  o the table..+ *
01c0: 20 54 43 4c 5f 48 41 53 48 5f 4b 45 59 5f 53 59   TCL_HASH_KEY_SY
01d0: 53 54 45 4d 5f 48 41 53 48 3a 0a 2b 20 2a 09 09  STEM_HASH:.+ *..
01e0: 09 09 49 66 20 74 68 69 73 20 66 6c 61 67 20 69  ..If this flag i
01f0: 73 20 73 65 74 20 74 68 65 6e 20 61 6c 6c 20 6d  s set then all m
0200: 65 6d 6f 72 79 20 69 6e 74 65 72 6e 61 6c 6c 79  emory internally
0210: 0a 2b 20 2a 20 20 20 20 20 20 20 20 20 20 20 20  .+ *            
0220: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0230: 20 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20    allocated for 
0240: 74 68 65 20 68 61 73 68 20 74 61 62 6c 65 20 74  the hash table t
0250: 68 61 74 20 69 73 20 6e 6f 74 20 66 6f 72 20 61  hat is not for a
0260: 6e 0a 2b 20 2a 20 20 20 20 20 20 20 20 20 20 20  n.+ *           
0270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0280: 20 20 20 65 6e 74 72 79 20 77 69 6c 6c 20 75 73     entry will us
0290: 65 20 74 68 65 20 73 79 73 74 65 6d 20 68 65 61  e the system hea
02a0: 70 2e 0a 20 20 2a 2f 0a 20 23 64 65 66 69 6e 65  p..  */. #define
02b0: 20 54 43 4c 5f 48 41 53 48 5f 4b 45 59 5f 52 41   TCL_HASH_KEY_RA
02c0: 4e 44 4f 4d 49 5a 45 5f 48 41 53 48 20 30 78 31  NDOMIZE_HASH 0x1
02d0: 0a 2b 23 64 65 66 69 6e 65 20 54 43 4c 5f 48 41  .+#define TCL_HA
02e0: 53 48 5f 4b 45 59 5f 53 59 53 54 45 4d 5f 48 41  SH_KEY_SYSTEM_HA
02f0: 53 48 20 20 20 20 30 78 32 0a 20 0a 20 2f 2a 0a  SH    0x2. . /*.
0300: 20 20 2a 20 53 74 72 75 63 74 75 72 65 20 64 65    * Structure de
0310: 66 69 6e 69 74 69 6f 6e 20 66 6f 72 20 74 68 65  finition for the
0320: 20 6d 65 74 68 6f 64 73 20 61 73 73 6f 63 69 61   methods associa
0330: 74 65 64 20 77 69 74 68 20 61 20 68 61 73 68 20  ted with a hash 
0340: 74 61 62 6c 65 0a 49 6e 64 65 78 3a 20 67 65 6e  table.Index: gen
0350: 65 72 69 63 2f 74 63 6c 43 6b 61 6c 6c 6f 63 2e  eric/tclCkalloc.
0360: 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  c.==============
0370: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0380: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0390: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
03a0: 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 3a 20  =====.RCS file: 
03b0: 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 63 6c  /cvsroot/tcl/tcl
03c0: 2f 67 65 6e 65 72 69 63 2f 74 63 6c 43 6b 61 6c  /generic/tclCkal
03d0: 6c 6f 63 2e 63 2c 76 0a 72 65 74 72 69 65 76 69  loc.c,v.retrievi
03e0: 6e 67 20 72 65 76 69 73 69 6f 6e 20 31 2e 31 39  ng revision 1.19
03f0: 0a 64 69 66 66 20 2d 75 20 2d 72 31 2e 31 39 20  .diff -u -r1.19 
0400: 74 63 6c 43 6b 61 6c 6c 6f 63 2e 63 0a 2d 2d 2d  tclCkalloc.c.---
0410: 20 67 65 6e 65 72 69 63 2f 74 63 6c 43 6b 61 6c   generic/tclCkal
0420: 6c 6f 63 2e 63 09 31 39 20 4a 61 6e 20 32 30 30  loc.c.19 Jan 200
0430: 33 20 30 37 3a 32 31 3a 31 38 20 2d 30 30 30 30  3 07:21:18 -0000
0440: 09 31 2e 31 39 0a 2b 2b 2b 20 67 65 6e 65 72 69  .1.19.+++ generi
0450: 63 2f 74 63 6c 43 6b 61 6c 6c 6f 63 2e 63 09 31  c/tclCkalloc.c.1
0460: 34 20 4e 6f 76 20 32 30 30 33 20 32 31 3a 31 33  4 Nov 2003 21:13
0470: 3a 31 39 20 2d 30 30 30 30 0a 40 40 20 2d 31 32  :19 -0000.@@ -12
0480: 34 39 2c 34 20 2b 31 32 34 39 2c 38 20 40 40 0a  49,4 +1249,8 @@.
0490: 20 23 69 66 20 55 53 45 5f 54 43 4c 41 4c 4c 4f   #if USE_TCLALLO
04a0: 43 0a 20 20 20 20 20 54 63 6c 46 69 6e 61 6c 69  C.     TclFinali
04b0: 7a 65 41 6c 6c 6f 63 53 75 62 73 79 73 74 65 6d  zeAllocSubsystem
04c0: 28 29 3b 20 0a 20 23 65 6e 64 69 66 0a 2b 0a 2b  (); . #endif.+.+
04d0: 23 69 66 20 64 65 66 69 6e 65 64 28 54 43 4c 5f  #if defined(TCL_
04e0: 54 48 52 45 41 44 53 29 20 26 26 20 64 65 66 69  THREADS) && defi
04f0: 6e 65 64 28 55 53 45 5f 54 48 52 45 41 44 5f 41  ned(USE_THREAD_A
0500: 4c 4c 4f 43 29 0a 2b 20 20 20 20 54 63 6c 70 46  LLOC).+    TclpF
0510: 69 6e 61 6c 69 7a 65 54 68 72 65 61 64 41 6c 6c  inalizeThreadAll
0520: 6f 63 53 75 62 73 79 73 74 65 6d 28 29 3b 0a 2b  ocSubsystem();.+
0530: 23 65 6e 64 69 66 0a 20 7d 0a 49 6e 64 65 78 3a  #endif. }.Index:
0540: 20 67 65 6e 65 72 69 63 2f 74 63 6c 48 61 73 68   generic/tclHash
0550: 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  .c.=============
0560: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0570: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0580: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
0590: 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 3a  ======.RCS file:
05a0: 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 63   /cvsroot/tcl/tc
05b0: 6c 2f 67 65 6e 65 72 69 63 2f 74 63 6c 48 61 73  l/generic/tclHas
05c0: 68 2e 63 2c 76 0a 72 65 74 72 69 65 76 69 6e 67  h.c,v.retrieving
05d0: 20 72 65 76 69 73 69 6f 6e 20 31 2e 31 33 0a 64   revision 1.13.d
05e0: 69 66 66 20 2d 75 20 2d 72 31 2e 31 33 20 74 63  iff -u -r1.13 tc
05f0: 6c 48 61 73 68 2e 63 0a 2d 2d 2d 20 67 65 6e 65  lHash.c.--- gene
0600: 72 69 63 2f 74 63 6c 48 61 73 68 2e 63 09 32 34  ric/tclHash.c.24
0610: 20 4a 75 6e 20 32 30 30 33 20 31 39 3a 35 36 3a   Jun 2003 19:56:
0620: 31 32 20 2d 30 30 30 30 09 31 2e 31 33 0a 2b 2b  12 -0000.1.13.++
0630: 2b 20 67 65 6e 65 72 69 63 2f 74 63 6c 48 61 73  + generic/tclHas
0640: 68 2e 63 09 31 34 20 4e 6f 76 20 32 30 30 33 20  h.c.14 Nov 2003 
0650: 32 31 3a 31 33 3a 31 39 20 2d 30 30 30 30 0a 40  21:13:19 -0000.@
0660: 40 20 2d 31 34 2c 36 20 2b 31 34 2c 37 20 40 40  @ -14,6 +14,7 @@
0670: 0a 20 20 2a 2f 0a 20 0a 20 23 69 6e 63 6c 75 64  .  */. . #includ
0680: 65 20 22 74 63 6c 49 6e 74 2e 68 22 0a 2b 23 69  e "tclInt.h".+#i
0690: 6e 63 6c 75 64 65 20 22 74 63 6c 50 6f 72 74 2e  nclude "tclPort.
06a0: 68 22 0a 20 0a 20 2f 2a 0a 20 20 2a 20 50 72 65  h". . /*.  * Pre
06b0: 76 65 6e 74 20 6d 61 63 72 6f 73 20 66 72 6f 6d  vent macros from
06c0: 20 63 6c 61 73 68 69 6e 67 20 77 69 74 68 20 66   clashing with f
06d0: 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69  unction definiti
06e0: 6f 6e 73 2e 0a 40 40 20 2d 36 32 36 2c 38 20 2b  ons..@@ -626,8 +
06f0: 36 32 37 2c 31 32 20 40 40 0a 20 20 20 20 20 20  627,12 @@.      
0700: 2a 2f 0a 20 0a 20 20 20 20 20 69 66 20 28 74 61  */. .     if (ta
0710: 62 6c 65 50 74 72 2d 3e 62 75 63 6b 65 74 73 20  blePtr->buckets 
0720: 21 3d 20 74 61 62 6c 65 50 74 72 2d 3e 73 74 61  != tablePtr->sta
0730: 74 69 63 42 75 63 6b 65 74 73 29 20 7b 0a 2b 20  ticBuckets) {.+ 
0740: 20 20 20 20 20 20 20 69 66 20 28 74 79 70 65 50         if (typeP
0750: 74 72 2d 3e 66 6c 61 67 73 20 26 20 54 43 4c 5f  tr->flags & TCL_
0760: 48 41 53 48 5f 4b 45 59 5f 53 59 53 54 45 4d 5f  HASH_KEY_SYSTEM_
0770: 48 41 53 48 29 20 7b 0a 2b 09 20 20 20 20 54 63  HASH) {.+.    Tc
0780: 6c 70 53 79 73 46 72 65 65 28 28 63 68 61 72 20  lpSysFree((char 
0790: 2a 29 20 74 61 62 6c 65 50 74 72 2d 3e 62 75 63  *) tablePtr->buc
07a0: 6b 65 74 73 29 3b 0a 2b 20 20 20 20 20 20 20 20  kets);.+        
07b0: 7d 20 65 6c 73 65 20 7b 0a 20 09 63 6b 66 72 65  } else {. .ckfre
07c0: 65 28 28 63 68 61 72 20 2a 29 20 74 61 62 6c 65  e((char *) table
07d0: 50 74 72 2d 3e 62 75 63 6b 65 74 73 29 3b 0a 20  Ptr->buckets);. 
07e0: 20 20 20 20 7d 0a 2b 20 20 20 20 7d 0a 20 0a 20      }.+    }. . 
07f0: 20 20 20 20 2f 2a 0a 20 20 20 20 20 20 2a 20 41      /*.      * A
0800: 72 72 61 6e 67 65 20 66 6f 72 20 70 61 6e 69 63  rrange for panic
0810: 73 20 69 66 20 74 68 65 20 74 61 62 6c 65 20 69  s if the table i
0820: 73 20 75 73 65 64 20 61 67 61 69 6e 20 77 69 74  s used again wit
0830: 68 6f 75 74 0a 40 40 20 2d 37 34 35 2c 36 20 2b  hout.@@ -745,6 +
0840: 37 35 30 2c 32 36 20 40 40 0a 20 20 20 20 20 64  750,26 @@.     d
0850: 6f 75 62 6c 65 20 61 76 65 72 61 67 65 2c 20 74  ouble average, t
0860: 6d 70 3b 0a 20 20 20 20 20 72 65 67 69 73 74 65  mp;.     registe
0870: 72 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20  r Tcl_HashEntry 
0880: 2a 68 50 74 72 3b 0a 20 20 20 20 20 63 68 61 72  *hPtr;.     char
0890: 20 2a 72 65 73 75 6c 74 2c 20 2a 70 3b 0a 2b 20   *result, *p;.+ 
08a0: 20 20 20 54 63 6c 5f 48 61 73 68 4b 65 79 54 79     Tcl_HashKeyTy
08b0: 70 65 20 2a 74 79 70 65 50 74 72 3b 0a 2b 0a 2b  pe *typePtr;.+.+
08c0: 23 69 66 20 54 43 4c 5f 50 52 45 53 45 52 56 45  #if TCL_PRESERVE
08d0: 5f 42 49 4e 41 52 59 5f 43 4f 4d 50 41 54 41 42  _BINARY_COMPATAB
08e0: 49 4c 49 54 59 0a 2b 20 20 20 20 69 66 20 28 74  ILITY.+    if (t
08f0: 61 62 6c 65 50 74 72 2d 3e 6b 65 79 54 79 70 65  ablePtr->keyType
0900: 20 3d 3d 20 54 43 4c 5f 53 54 52 49 4e 47 5f 4b   == TCL_STRING_K
0910: 45 59 53 29 20 7b 0a 2b 09 74 79 70 65 50 74 72  EYS) {.+.typePtr
0920: 20 3d 20 26 74 63 6c 53 74 72 69 6e 67 48 61 73   = &tclStringHas
0930: 68 4b 65 79 54 79 70 65 3b 0a 2b 20 20 20 20 7d  hKeyType;.+    }
0940: 20 65 6c 73 65 20 69 66 20 28 74 61 62 6c 65 50   else if (tableP
0950: 74 72 2d 3e 6b 65 79 54 79 70 65 20 3d 3d 20 54  tr->keyType == T
0960: 43 4c 5f 4f 4e 45 5f 57 4f 52 44 5f 4b 45 59 53  CL_ONE_WORD_KEYS
0970: 29 20 7b 0a 2b 09 74 79 70 65 50 74 72 20 3d 20  ) {.+.typePtr = 
0980: 26 74 63 6c 4f 6e 65 57 6f 72 64 48 61 73 68 4b  &tclOneWordHashK
0990: 65 79 54 79 70 65 3b 0a 2b 20 20 20 20 7d 20 65  eyType;.+    } e
09a0: 6c 73 65 20 69 66 20 28 74 61 62 6c 65 50 74 72  lse if (tablePtr
09b0: 2d 3e 6b 65 79 54 79 70 65 20 3d 3d 20 54 43 4c  ->keyType == TCL
09c0: 5f 43 55 53 54 4f 4d 5f 54 59 50 45 5f 4b 45 59  _CUSTOM_TYPE_KEY
09d0: 53 0a 2b 09 20 20 20 20 20 20 20 7c 7c 20 74 61  S.+.       || ta
09e0: 62 6c 65 50 74 72 2d 3e 6b 65 79 54 79 70 65 20  blePtr->keyType 
09f0: 3d 3d 20 54 43 4c 5f 43 55 53 54 4f 4d 5f 50 54  == TCL_CUSTOM_PT
0a00: 52 5f 4b 45 59 53 29 20 7b 0a 2b 09 74 79 70 65  R_KEYS) {.+.type
0a10: 50 74 72 20 3d 20 74 61 62 6c 65 50 74 72 2d 3e  Ptr = tablePtr->
0a20: 74 79 70 65 50 74 72 3b 0a 2b 20 20 20 20 7d 20  typePtr;.+    } 
0a30: 65 6c 73 65 20 7b 0a 2b 09 74 79 70 65 50 74 72  else {.+.typePtr
0a40: 20 3d 20 26 74 63 6c 41 72 72 61 79 48 61 73 68   = &tclArrayHash
0a50: 4b 65 79 54 79 70 65 3b 0a 2b 20 20 20 20 7d 0a  KeyType;.+    }.
0a60: 2b 23 65 6c 73 65 0a 2b 20 20 20 20 74 79 70 65  +#else.+    type
0a70: 50 74 72 20 3d 20 74 61 62 6c 65 50 74 72 2d 3e  Ptr = tablePtr->
0a80: 74 79 70 65 50 74 72 3b 0a 2b 20 20 20 20 69 66  typePtr;.+    if
0a90: 20 28 74 79 70 65 50 74 72 20 3d 3d 20 4e 55 4c   (typePtr == NUL
0aa0: 4c 29 20 7b 0a 2b 09 54 63 6c 5f 50 61 6e 69 63  L) {.+.Tcl_Panic
0ab0: 28 22 63 61 6c 6c 65 64 20 54 63 6c 5f 48 61 73  ("called Tcl_Has
0ac0: 68 53 74 61 74 73 20 6f 6e 20 64 65 6c 65 74 65  hStats on delete
0ad0: 64 20 74 61 62 6c 65 22 29 3b 0a 2b 09 72 65 74  d table");.+.ret
0ae0: 75 72 6e 20 4e 55 4c 4c 3b 0a 2b 20 20 20 20 7d  urn NULL;.+    }
0af0: 0a 2b 23 65 6e 64 69 66 0a 20 0a 20 20 20 20 20  .+#endif. .     
0b00: 2f 2a 0a 20 20 20 20 20 20 2a 20 43 6f 6d 70 75  /*.      * Compu
0b10: 74 65 20 61 20 68 69 73 74 6f 67 72 61 6d 20 6f  te a histogram o
0b20: 66 20 62 75 63 6b 65 74 20 75 73 61 67 65 2e 0a  f bucket usage..
0b30: 40 40 20 2d 37 37 34 2c 38 20 2b 37 39 39 2c 31  @@ -774,8 +799,1
0b40: 31 20 40 40 0a 20 20 20 20 20 2f 2a 0a 20 20 20  1 @@.     /*.   
0b50: 20 20 20 2a 20 50 72 69 6e 74 20 6f 75 74 20 74     * Print out t
0b60: 68 65 20 68 69 73 74 6f 67 72 61 6d 20 61 6e 64  he histogram and
0b70: 20 61 20 66 65 77 20 6f 74 68 65 72 20 70 69 65   a few other pie
0b80: 63 65 73 20 6f 66 20 69 6e 66 6f 72 6d 61 74 69  ces of informati
0b90: 6f 6e 2e 0a 20 20 20 20 20 20 2a 2f 0a 2d 0a 2b  on..      */.-.+
0ba0: 20 20 20 20 69 66 20 28 74 79 70 65 50 74 72 2d      if (typePtr-
0bb0: 3e 66 6c 61 67 73 20 26 20 54 43 4c 5f 48 41 53  >flags & TCL_HAS
0bc0: 48 5f 4b 45 59 5f 53 59 53 54 45 4d 5f 48 41 53  H_KEY_SYSTEM_HAS
0bd0: 48 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 72 65  H) {.+        re
0be0: 73 75 6c 74 20 3d 20 28 63 68 61 72 20 2a 29 20  sult = (char *) 
0bf0: 54 63 6c 70 53 79 73 41 6c 6c 6f 63 28 28 75 6e  TclpSysAlloc((un
0c00: 73 69 67 6e 65 64 29 20 28 28 4e 55 4d 5f 43 4f  signed) ((NUM_CO
0c10: 55 4e 54 45 52 53 2a 36 30 29 20 2b 20 33 30 30  UNTERS*60) + 300
0c20: 29 2c 20 30 29 3b 0a 2b 20 20 20 20 7d 20 65 6c  ), 0);.+    } el
0c30: 73 65 20 7b 0a 20 20 20 20 20 72 65 73 75 6c 74  se {.     result
0c40: 20 3d 20 28 63 68 61 72 20 2a 29 20 63 6b 61 6c   = (char *) ckal
0c50: 6c 6f 63 28 28 75 6e 73 69 67 6e 65 64 29 20 28  loc((unsigned) (
0c60: 28 4e 55 4d 5f 43 4f 55 4e 54 45 52 53 2a 36 30  (NUM_COUNTERS*60
0c70: 29 20 2b 20 33 30 30 29 29 3b 0a 2b 20 20 20 20  ) + 300));.+    
0c80: 7d 0a 20 20 20 20 20 73 70 72 69 6e 74 66 28 72  }.     sprintf(r
0c90: 65 73 75 6c 74 2c 20 22 25 64 20 65 6e 74 72 69  esult, "%d entri
0ca0: 65 73 20 69 6e 20 74 61 62 6c 65 2c 20 25 64 20  es in table, %d 
0cb0: 62 75 63 6b 65 74 73 5c 6e 22 2c 0a 20 09 20 20  buckets\n",. .  
0cc0: 20 20 74 61 62 6c 65 50 74 72 2d 3e 6e 75 6d 45    tablePtr->numE
0cd0: 6e 74 72 69 65 73 2c 20 74 61 62 6c 65 50 74 72  ntries, tablePtr
0ce0: 2d 3e 6e 75 6d 42 75 63 6b 65 74 73 29 3b 0a 20  ->numBuckets);. 
0cf0: 20 20 20 20 70 20 3d 20 72 65 73 75 6c 74 20 2b      p = result +
0d00: 20 73 74 72 6c 65 6e 28 72 65 73 75 6c 74 29 3b   strlen(result);
0d10: 0a 40 40 20 2d 31 31 32 32 2c 36 20 2b 31 31 35  .@@ -1122,6 +115
0d20: 30 2c 32 31 20 40 40 0a 20 20 20 20 20 54 63 6c  0,21 @@.     Tcl
0d30: 5f 48 61 73 68 4b 65 79 54 79 70 65 20 2a 74 79  _HashKeyType *ty
0d40: 70 65 50 74 72 3b 0a 20 20 20 20 20 56 4f 49 44  pePtr;.     VOID
0d50: 20 2a 6b 65 79 3b 0a 20 0a 2b 23 69 66 20 54 43   *key;. .+#if TC
0d60: 4c 5f 50 52 45 53 45 52 56 45 5f 42 49 4e 41 52  L_PRESERVE_BINAR
0d70: 59 5f 43 4f 4d 50 41 54 41 42 49 4c 49 54 59 0a  Y_COMPATABILITY.
0d80: 2b 20 20 20 20 69 66 20 28 74 61 62 6c 65 50 74  +    if (tablePt
0d90: 72 2d 3e 6b 65 79 54 79 70 65 20 3d 3d 20 54 43  r->keyType == TC
0da0: 4c 5f 53 54 52 49 4e 47 5f 4b 45 59 53 29 20 7b  L_STRING_KEYS) {
0db0: 0a 2b 09 74 79 70 65 50 74 72 20 3d 20 26 74 63  .+.typePtr = &tc
0dc0: 6c 53 74 72 69 6e 67 48 61 73 68 4b 65 79 54 79  lStringHashKeyTy
0dd0: 70 65 3b 0a 2b 20 20 20 20 7d 20 65 6c 73 65 20  pe;.+    } else 
0de0: 69 66 20 28 74 61 62 6c 65 50 74 72 2d 3e 6b 65  if (tablePtr->ke
0df0: 79 54 79 70 65 20 3d 3d 20 54 43 4c 5f 4f 4e 45  yType == TCL_ONE
0e00: 5f 57 4f 52 44 5f 4b 45 59 53 29 20 7b 0a 2b 09  _WORD_KEYS) {.+.
0e10: 74 79 70 65 50 74 72 20 3d 20 26 74 63 6c 4f 6e  typePtr = &tclOn
0e20: 65 57 6f 72 64 48 61 73 68 4b 65 79 54 79 70 65  eWordHashKeyType
0e30: 3b 0a 2b 20 20 20 20 7d 20 65 6c 73 65 20 69 66  ;.+    } else if
0e40: 20 28 74 61 62 6c 65 50 74 72 2d 3e 6b 65 79 54   (tablePtr->keyT
0e50: 79 70 65 20 3d 3d 20 54 43 4c 5f 43 55 53 54 4f  ype == TCL_CUSTO
0e60: 4d 5f 54 59 50 45 5f 4b 45 59 53 0a 2b 09 20 20  M_TYPE_KEYS.+.  
0e70: 20 20 20 20 20 7c 7c 20 74 61 62 6c 65 50 74 72       || tablePtr
0e80: 2d 3e 6b 65 79 54 79 70 65 20 3d 3d 20 54 43 4c  ->keyType == TCL
0e90: 5f 43 55 53 54 4f 4d 5f 50 54 52 5f 4b 45 59 53  _CUSTOM_PTR_KEYS
0ea0: 29 20 7b 0a 2b 09 74 79 70 65 50 74 72 20 3d 20  ) {.+.typePtr = 
0eb0: 74 61 62 6c 65 50 74 72 2d 3e 74 79 70 65 50 74  tablePtr->typePt
0ec0: 72 3b 0a 2b 20 20 20 20 7d 20 65 6c 73 65 20 7b  r;.+    } else {
0ed0: 0a 2b 09 74 79 70 65 50 74 72 20 3d 20 26 74 63  .+.typePtr = &tc
0ee0: 6c 41 72 72 61 79 48 61 73 68 4b 65 79 54 79 70  lArrayHashKeyTyp
0ef0: 65 3b 0a 2b 20 20 20 20 7d 0a 2b 23 65 6c 73 65  e;.+    }.+#else
0f00: 0a 2b 20 20 20 20 74 79 70 65 50 74 72 20 3d 20  .+    typePtr = 
0f10: 74 61 62 6c 65 50 74 72 2d 3e 74 79 70 65 50 74  tablePtr->typePt
0f20: 72 3b 0a 2b 23 65 6e 64 69 66 0a 2b 0a 20 20 20  r;.+#endif.+.   
0f30: 20 20 6f 6c 64 53 69 7a 65 20 3d 20 74 61 62 6c    oldSize = tabl
0f40: 65 50 74 72 2d 3e 6e 75 6d 42 75 63 6b 65 74 73  ePtr->numBuckets
0f50: 3b 0a 20 20 20 20 20 6f 6c 64 42 75 63 6b 65 74  ;.     oldBucket
0f60: 73 20 3d 20 74 61 62 6c 65 50 74 72 2d 3e 62 75  s = tablePtr->bu
0f70: 63 6b 65 74 73 3b 0a 20 0a 40 40 20 2d 31 31 33  ckets;. .@@ -113
0f80: 31 2c 38 20 2b 31 31 37 34 2c 31 33 20 40 40 0a  1,8 +1174,13 @@.
0f90: 20 20 20 20 20 20 2a 2f 0a 20 0a 20 20 20 20 20        */. .     
0fa0: 74 61 62 6c 65 50 74 72 2d 3e 6e 75 6d 42 75 63  tablePtr->numBuc
0fb0: 6b 65 74 73 20 2a 3d 20 34 3b 0a 2b 20 20 20 20  kets *= 4;.+    
0fc0: 69 66 20 28 74 79 70 65 50 74 72 2d 3e 66 6c 61  if (typePtr->fla
0fd0: 67 73 20 26 20 54 43 4c 5f 48 41 53 48 5f 4b 45  gs & TCL_HASH_KE
0fe0: 59 5f 53 59 53 54 45 4d 5f 48 41 53 48 29 20 7b  Y_SYSTEM_HASH) {
0ff0: 0a 2b 20 20 20 20 20 20 20 20 74 61 62 6c 65 50  .+        tableP
1000: 74 72 2d 3e 62 75 63 6b 65 74 73 20 3d 20 28 54  tr->buckets = (T
1010: 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 2a 2a 29  cl_HashEntry **)
1020: 20 54 63 6c 70 53 79 73 41 6c 6c 6f 63 28 28 75   TclpSysAlloc((u
1030: 6e 73 69 67 6e 65 64 29 0a 2b 20 20 20 20 09 20  nsigned).+    . 
1040: 20 20 20 20 20 20 20 28 74 61 62 6c 65 50 74 72         (tablePtr
1050: 2d 3e 6e 75 6d 42 75 63 6b 65 74 73 20 2a 20 73  ->numBuckets * s
1060: 69 7a 65 6f 66 28 54 63 6c 5f 48 61 73 68 45 6e  izeof(Tcl_HashEn
1070: 74 72 79 20 2a 29 29 2c 20 30 29 3b 0a 2b 20 20  try *)), 0);.+  
1080: 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20 20    } else {.     
1090: 74 61 62 6c 65 50 74 72 2d 3e 62 75 63 6b 65 74  tablePtr->bucket
10a0: 73 20 3d 20 28 54 63 6c 5f 48 61 73 68 45 6e 74  s = (Tcl_HashEnt
10b0: 72 79 20 2a 2a 29 20 63 6b 61 6c 6c 6f 63 28 28  ry **) ckalloc((
10c0: 75 6e 73 69 67 6e 65 64 29 0a 20 09 20 20 20 20  unsigned). .    
10d0: 28 74 61 62 6c 65 50 74 72 2d 3e 6e 75 6d 42 75  (tablePtr->numBu
10e0: 63 6b 65 74 73 20 2a 20 73 69 7a 65 6f 66 28 54  ckets * sizeof(T
10f0: 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 2a 29 29  cl_HashEntry *))
1100: 29 3b 0a 2b 20 20 20 20 7d 0a 20 20 20 20 20 66  );.+    }.     f
1110: 6f 72 20 28 63 6f 75 6e 74 20 3d 20 74 61 62 6c  or (count = tabl
1120: 65 50 74 72 2d 3e 6e 75 6d 42 75 63 6b 65 74 73  ePtr->numBuckets
1130: 2c 20 6e 65 77 43 68 61 69 6e 50 74 72 20 3d 20  , newChainPtr = 
1140: 74 61 62 6c 65 50 74 72 2d 3e 62 75 63 6b 65 74  tablePtr->bucket
1150: 73 3b 0a 20 09 20 20 20 20 63 6f 75 6e 74 20 3e  s;. .    count >
1160: 20 30 3b 20 63 6f 75 6e 74 2d 2d 2c 20 6e 65 77   0; count--, new
1170: 43 68 61 69 6e 50 74 72 2b 2b 29 20 7b 0a 20 09  ChainPtr++) {. .
1180: 2a 6e 65 77 43 68 61 69 6e 50 74 72 20 3d 20 4e  *newChainPtr = N
1190: 55 4c 4c 3b 0a 40 40 20 2d 31 31 34 31 2c 32 31  ULL;.@@ -1141,21
11a0: 20 2b 31 31 38 39 2c 36 20 40 40 0a 20 20 20 20   +1189,6 @@.    
11b0: 20 74 61 62 6c 65 50 74 72 2d 3e 64 6f 77 6e 53   tablePtr->downS
11c0: 68 69 66 74 20 2d 3d 20 32 3b 0a 20 20 20 20 20  hift -= 2;.     
11d0: 74 61 62 6c 65 50 74 72 2d 3e 6d 61 73 6b 20 3d  tablePtr->mask =
11e0: 20 28 74 61 62 6c 65 50 74 72 2d 3e 6d 61 73 6b   (tablePtr->mask
11f0: 20 3c 3c 20 32 29 20 2b 20 33 3b 0a 20 0a 2d 23   << 2) + 3;. .-#
1200: 69 66 20 54 43 4c 5f 50 52 45 53 45 52 56 45 5f  if TCL_PRESERVE_
1210: 42 49 4e 41 52 59 5f 43 4f 4d 50 41 54 41 42 49  BINARY_COMPATABI
1220: 4c 49 54 59 0a 2d 20 20 20 20 69 66 20 28 74 61  LITY.-    if (ta
1230: 62 6c 65 50 74 72 2d 3e 6b 65 79 54 79 70 65 20  blePtr->keyType 
1240: 3d 3d 20 54 43 4c 5f 53 54 52 49 4e 47 5f 4b 45  == TCL_STRING_KE
1250: 59 53 29 20 7b 0a 2d 09 74 79 70 65 50 74 72 20  YS) {.-.typePtr 
1260: 3d 20 26 74 63 6c 53 74 72 69 6e 67 48 61 73 68  = &tclStringHash
1270: 4b 65 79 54 79 70 65 3b 0a 2d 20 20 20 20 7d 20  KeyType;.-    } 
1280: 65 6c 73 65 20 69 66 20 28 74 61 62 6c 65 50 74  else if (tablePt
1290: 72 2d 3e 6b 65 79 54 79 70 65 20 3d 3d 20 54 43  r->keyType == TC
12a0: 4c 5f 4f 4e 45 5f 57 4f 52 44 5f 4b 45 59 53 29  L_ONE_WORD_KEYS)
12b0: 20 7b 0a 2d 09 74 79 70 65 50 74 72 20 3d 20 26   {.-.typePtr = &
12c0: 74 63 6c 4f 6e 65 57 6f 72 64 48 61 73 68 4b 65  tclOneWordHashKe
12d0: 79 54 79 70 65 3b 0a 2d 20 20 20 20 7d 20 65 6c  yType;.-    } el
12e0: 73 65 20 69 66 20 28 74 61 62 6c 65 50 74 72 2d  se if (tablePtr-
12f0: 3e 6b 65 79 54 79 70 65 20 3d 3d 20 54 43 4c 5f  >keyType == TCL_
1300: 43 55 53 54 4f 4d 5f 54 59 50 45 5f 4b 45 59 53  CUSTOM_TYPE_KEYS
1310: 0a 2d 09 20 20 20 20 20 20 20 7c 7c 20 74 61 62  .-.       || tab
1320: 6c 65 50 74 72 2d 3e 6b 65 79 54 79 70 65 20 3d  lePtr->keyType =
1330: 3d 20 54 43 4c 5f 43 55 53 54 4f 4d 5f 50 54 52  = TCL_CUSTOM_PTR
1340: 5f 4b 45 59 53 29 20 7b 0a 2d 09 74 79 70 65 50  _KEYS) {.-.typeP
1350: 74 72 20 3d 20 74 61 62 6c 65 50 74 72 2d 3e 74  tr = tablePtr->t
1360: 79 70 65 50 74 72 3b 0a 2d 20 20 20 20 7d 20 65  ypePtr;.-    } e
1370: 6c 73 65 20 7b 0a 2d 09 74 79 70 65 50 74 72 20  lse {.-.typePtr 
1380: 3d 20 26 74 63 6c 41 72 72 61 79 48 61 73 68 4b  = &tclArrayHashK
1390: 65 79 54 79 70 65 3b 0a 2d 20 20 20 20 7d 0a 2d  eyType;.-    }.-
13a0: 23 65 6c 73 65 0a 2d 20 20 20 20 74 79 70 65 50  #else.-    typeP
13b0: 74 72 20 3d 20 74 61 62 6c 65 50 74 72 2d 3e 74  tr = tablePtr->t
13c0: 79 70 65 50 74 72 3b 0a 2d 23 65 6e 64 69 66 0a  ypePtr;.-#endif.
13d0: 2d 0a 20 20 20 20 20 2f 2a 0a 20 20 20 20 20 20  -.     /*.      
13e0: 2a 20 52 65 68 61 73 68 20 61 6c 6c 20 6f 66 20  * Rehash all of 
13f0: 74 68 65 20 65 78 69 73 74 69 6e 67 20 65 6e 74  the existing ent
1400: 72 69 65 73 20 69 6e 74 6f 20 74 68 65 20 6e 65  ries into the ne
1410: 77 20 62 75 63 6b 65 74 20 61 72 72 61 79 2e 0a  w bucket array..
1420: 20 20 20 20 20 20 2a 2f 0a 40 40 20 2d 31 32 30        */.@@ -120
1430: 30 2c 36 20 2b 31 32 33 33 2c 31 30 20 40 40 0a  0,6 +1233,10 @@.
1440: 20 20 20 20 20 20 2a 2f 0a 20 0a 20 20 20 20 20        */. .     
1450: 69 66 20 28 6f 6c 64 42 75 63 6b 65 74 73 20 21  if (oldBuckets !
1460: 3d 20 74 61 62 6c 65 50 74 72 2d 3e 73 74 61 74  = tablePtr->stat
1470: 69 63 42 75 63 6b 65 74 73 29 20 7b 0a 2b 20 20  icBuckets) {.+  
1480: 20 20 20 20 20 20 69 66 20 28 74 79 70 65 50 74        if (typePt
1490: 72 2d 3e 66 6c 61 67 73 20 26 20 54 43 4c 5f 48  r->flags & TCL_H
14a0: 41 53 48 5f 4b 45 59 5f 53 59 53 54 45 4d 5f 48  ASH_KEY_SYSTEM_H
14b0: 41 53 48 29 20 7b 0a 2b 09 20 20 20 20 54 63 6c  ASH) {.+.    Tcl
14c0: 70 53 79 73 46 72 65 65 28 28 63 68 61 72 20 2a  pSysFree((char *
14d0: 29 20 6f 6c 64 42 75 63 6b 65 74 73 29 3b 0a 2b  ) oldBuckets);.+
14e0: 20 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b          } else {
14f0: 0a 20 09 63 6b 66 72 65 65 28 28 63 68 61 72 20  . .ckfree((char 
1500: 2a 29 20 6f 6c 64 42 75 63 6b 65 74 73 29 3b 0a  *) oldBuckets);.
1510: 2b 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20  +        }.     
1520: 7d 0a 20 7d 0a 49 6e 64 65 78 3a 20 67 65 6e 65  }. }.Index: gene
1530: 72 69 63 2f 74 63 6c 49 6e 74 2e 68 0a 3d 3d 3d  ric/tclInt.h.===
1540: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1550: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1560: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1570: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1580: 0a 52 43 53 20 66 69 6c 65 3a 20 2f 63 76 73 72  .RCS file: /cvsr
1590: 6f 6f 74 2f 74 63 6c 2f 74 63 6c 2f 67 65 6e 65  oot/tcl/tcl/gene
15a0: 72 69 63 2f 74 63 6c 49 6e 74 2e 68 2c 76 0a 72  ric/tclInt.h,v.r
15b0: 65 74 72 69 65 76 69 6e 67 20 72 65 76 69 73 69  etrieving revisi
15c0: 6f 6e 20 31 2e 31 33 38 0a 64 69 66 66 20 2d 75  on 1.138.diff -u
15d0: 20 2d 72 31 2e 31 33 38 20 74 63 6c 49 6e 74 2e   -r1.138 tclInt.
15e0: 68 0a 2d 2d 2d 20 67 65 6e 65 72 69 63 2f 74 63  h.--- generic/tc
15f0: 6c 49 6e 74 2e 68 09 33 20 4e 6f 76 20 32 30 30  lInt.h.3 Nov 200
1600: 33 20 31 32 3a 34 39 3a 33 31 20 2d 30 30 30 30  3 12:49:31 -0000
1610: 09 31 2e 31 33 38 0a 2b 2b 2b 20 67 65 6e 65 72  .1.138.+++ gener
1620: 69 63 2f 74 63 6c 49 6e 74 2e 68 09 31 34 20 4e  ic/tclInt.h.14 N
1630: 6f 76 20 32 30 30 33 20 32 31 3a 31 33 3a 32 30  ov 2003 21:13:20
1640: 20 2d 30 30 30 30 0a 40 40 20 2d 31 37 32 32 2c   -0000.@@ -1722,
1650: 36 20 2b 31 37 32 32 2c 38 20 40 40 0a 20 45 58  6 +1722,8 @@. EX
1660: 54 45 52 4e 20 76 6f 69 64 09 09 54 63 6c 70 46  TERN void..TclpF
1670: 69 6e 61 6c 69 7a 65 43 6f 6e 64 69 74 69 6f 6e  inalizeCondition
1680: 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 0a 20   _ANSI_ARGS_((. 
1690: 09 09 09 20 20 20 20 54 63 6c 5f 43 6f 6e 64 69  ...    Tcl_Condi
16a0: 74 69 6f 6e 20 2a 63 6f 6e 64 50 74 72 29 29 3b  tion *condPtr));
16b0: 0a 20 45 58 54 45 52 4e 20 76 6f 69 64 09 09 54  . EXTERN void..T
16c0: 63 6c 70 46 69 6e 61 6c 69 7a 65 4d 75 74 65 78  clpFinalizeMutex
16d0: 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 54 63   _ANSI_ARGS_((Tc
16e0: 6c 5f 4d 75 74 65 78 20 2a 6d 75 74 65 78 50 74  l_Mutex *mutexPt
16f0: 72 29 29 3b 0a 2b 45 58 54 45 52 4e 20 76 6f 69  r));.+EXTERN voi
1700: 64 20 20 20 20 20 20 20 20 20 20 20 20 20 54 63  d             Tc
1710: 6c 70 46 69 6e 61 6c 69 7a 65 54 68 72 65 61 64  lpFinalizeThread
1720: 53 74 6f 72 61 67 65 20 5f 41 4e 53 49 5f 41 52  Storage _ANSI_AR
1730: 47 53 5f 28 28 76 6f 69 64 29 29 3b 0a 2b 45 58  GS_((void));.+EX
1740: 54 45 52 4e 20 76 6f 69 64 20 20 20 20 20 20 20  TERN void       
1750: 20 20 20 20 20 20 54 63 6c 70 46 69 6e 61 6c 69        TclpFinali
1760: 7a 65 54 68 72 65 61 64 41 6c 6c 6f 63 53 75 62  zeThreadAllocSub
1770: 73 79 73 74 65 6d 20 5f 41 4e 53 49 5f 41 52 47  system _ANSI_ARG
1780: 53 5f 28 28 76 6f 69 64 29 29 3b 0a 20 45 58 54  S_((void));. EXT
1790: 45 52 4e 20 76 6f 69 64 09 09 54 63 6c 70 46 69  ERN void..TclpFi
17a0: 6e 61 6c 69 7a 65 54 68 72 65 61 64 44 61 74 61  nalizeThreadData
17b0: 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 0a 20   _ANSI_ARGS_((. 
17c0: 09 09 09 20 20 20 20 54 63 6c 5f 54 68 72 65 61  ...    Tcl_Threa
17d0: 64 44 61 74 61 4b 65 79 20 2a 6b 65 79 50 74 72  dDataKey *keyPtr
17e0: 29 29 3b 0a 20 45 58 54 45 52 4e 20 76 6f 69 64  ));. EXTERN void
17f0: 09 09 54 63 6c 70 46 69 6e 61 6c 69 7a 65 54 68  ..TclpFinalizeTh
1800: 72 65 61 64 44 61 74 61 4b 65 79 20 5f 41 4e 53  readDataKey _ANS
1810: 49 5f 41 52 47 53 5f 28 28 0a 40 40 20 2d 31 37  I_ARGS_((.@@ -17
1820: 34 34 2c 36 20 2b 31 37 34 36 2c 39 20 40 40 0a  44,6 +1746,9 @@.
1830: 20 45 58 54 45 52 4e 20 54 63 6c 5f 4f 62 6a 2a   EXTERN Tcl_Obj*
1840: 09 09 54 63 6c 70 4f 62 6a 4c 69 73 74 56 6f 6c  ..TclpObjListVol
1850: 75 6d 65 73 20 5f 41 4e 53 49 5f 41 52 47 53 5f  umes _ANSI_ARGS_
1860: 28 28 76 6f 69 64 29 29 3b 0a 20 45 58 54 45 52  ((void));. EXTER
1870: 4e 20 76 6f 69 64 09 09 54 63 6c 70 4d 61 73 74  N void..TclpMast
1880: 65 72 4c 6f 63 6b 20 5f 41 4e 53 49 5f 41 52 47  erLock _ANSI_ARG
1890: 53 5f 28 28 76 6f 69 64 29 29 3b 0a 20 45 58 54  S_((void));. EXT
18a0: 45 52 4e 20 76 6f 69 64 09 09 54 63 6c 70 4d 61  ERN void..TclpMa
18b0: 73 74 65 72 55 6e 6c 6f 63 6b 20 5f 41 4e 53 49  sterUnlock _ANSI
18c0: 5f 41 52 47 53 5f 28 28 76 6f 69 64 29 29 3b 0a  _ARGS_((void));.
18d0: 2b 45 58 54 45 52 4e 20 76 6f 69 64 20 20 20 20  +EXTERN void    
18e0: 20 20 20 20 20 20 20 20 20 54 63 6c 70 54 68 72           TclpThr
18f0: 65 61 64 53 74 6f 72 61 67 65 4c 6f 63 6b 49 6e  eadStorageLockIn
1900: 69 74 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28  it _ANSI_ARGS_((
1910: 76 6f 69 64 29 29 3b 0a 2b 45 58 54 45 52 4e 20  void));.+EXTERN 
1920: 76 6f 69 64 20 20 20 20 20 20 20 20 20 20 20 20  void            
1930: 20 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61   TclpThreadStora
1940: 67 65 4c 6f 63 6b 20 5f 41 4e 53 49 5f 41 52 47  geLock _ANSI_ARG
1950: 53 5f 28 28 76 6f 69 64 29 29 3b 0a 2b 45 58 54  S_((void));.+EXT
1960: 45 52 4e 20 76 6f 69 64 20 20 20 20 20 20 20 20  ERN void        
1970: 20 20 20 20 20 54 63 6c 70 54 68 72 65 61 64 53       TclpThreadS
1980: 74 6f 72 61 67 65 55 6e 6c 6f 63 6b 20 5f 41 4e  torageUnlock _AN
1990: 53 49 5f 41 52 47 53 5f 28 28 76 6f 69 64 29 29  SI_ARGS_((void))
19a0: 3b 0a 20 45 58 54 45 52 4e 20 69 6e 74 09 09 54  ;. EXTERN int..T
19b0: 63 6c 70 4d 61 74 63 68 46 69 6c 65 73 20 5f 41  clpMatchFiles _A
19c0: 4e 53 49 5f 41 52 47 53 5f 28 28 54 63 6c 5f 49  NSI_ARGS_((Tcl_I
19d0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 0a 20  nterp *interp,. 
19e0: 09 09 09 20 20 20 20 63 68 61 72 20 2a 73 65 70  ...    char *sep
19f0: 61 72 61 74 6f 72 73 2c 20 54 63 6c 5f 44 53 74  arators, Tcl_DSt
1a00: 72 69 6e 67 20 2a 64 69 72 50 74 72 2c 0a 20 09  ring *dirPtr,. .
1a10: 09 09 20 20 20 20 63 68 61 72 20 2a 70 61 74 74  ..    char *patt
1a20: 65 72 6e 2c 20 63 68 61 72 20 2a 74 61 69 6c 29  ern, char *tail)
1a30: 29 3b 0a 40 40 20 2d 31 37 39 31 2c 36 20 2b 31  );.@@ -1791,6 +1
1a40: 37 39 36 2c 31 31 20 40 40 0a 20 45 58 54 45 52  796,11 @@. EXTER
1a50: 4e 20 76 6f 69 64 09 09 54 63 6c 70 52 65 6c 65  N void..TclpRele
1a60: 61 73 65 46 69 6c 65 20 5f 41 4e 53 49 5f 41 52  aseFile _ANSI_AR
1a70: 47 53 5f 28 28 54 63 6c 46 69 6c 65 20 66 69 6c  GS_((TclFile fil
1a80: 65 29 29 3b 0a 20 45 58 54 45 52 4e 20 76 6f 69  e));. EXTERN voi
1a90: 64 09 09 54 63 6c 70 53 65 74 56 61 72 69 61 62  d..TclpSetVariab
1aa0: 6c 65 73 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28  les _ANSI_ARGS_(
1ab0: 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74  (Tcl_Interp *int
1ac0: 65 72 70 29 29 3b 0a 20 45 58 54 45 52 4e 20 76  erp));. EXTERN v
1ad0: 6f 69 64 09 09 54 63 6c 70 55 6e 6c 6f 61 64 46  oid..TclpUnloadF
1ae0: 69 6c 65 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28  ile _ANSI_ARGS_(
1af0: 28 54 63 6c 5f 4c 6f 61 64 48 61 6e 64 6c 65 20  (Tcl_LoadHandle 
1b00: 6c 6f 61 64 48 61 6e 64 6c 65 29 29 3b 0a 2b 45  loadHandle));.+E
1b10: 58 54 45 52 4e 20 54 63 6c 5f 48 61 73 68 54 61  XTERN Tcl_HashTa
1b20: 62 6c 65 20 2a 20 20 54 63 6c 70 54 68 72 65 61  ble *  TclpThrea
1b30: 64 53 74 6f 72 61 67 65 49 6e 69 74 20 5f 41 4e  dStorageInit _AN
1b40: 53 49 5f 41 52 47 53 5f 28 28 54 63 6c 5f 54 68  SI_ARGS_((Tcl_Th
1b50: 72 65 61 64 49 64 20 69 64 29 29 3b 0a 2b 45 58  readId id));.+EX
1b60: 54 45 52 4e 20 54 63 6c 5f 48 61 73 68 54 61 62  TERN Tcl_HashTab
1b70: 6c 65 20 2a 20 20 54 63 6c 70 54 68 72 65 61 64  le *  TclpThread
1b80: 53 74 6f 72 61 67 65 47 65 74 48 61 73 68 54 61  StorageGetHashTa
1b90: 62 6c 65 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28  ble _ANSI_ARGS_(
1ba0: 28 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  (.+             
1bb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54                 T
1bc0: 63 6c 5f 54 68 72 65 61 64 49 64 20 69 64 29 29  cl_ThreadId id))
1bd0: 3b 0a 2b 45 58 54 45 52 4e 20 76 6f 69 64 20 20  ;.+EXTERN void  
1be0: 20 20 20 20 20 20 20 20 20 20 20 54 63 6c 70 54             TclpT
1bf0: 68 72 65 61 64 53 74 6f 72 61 67 65 50 72 69 6e  hreadStoragePrin
1c00: 74 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 46  t _ANSI_ARGS_((F
1c10: 49 4c 45 20 2a 6f 75 74 46 69 6c 65 2c 0a 2b 20  ILE *outFile,.+ 
1c20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1c30: 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 66             int f
1c40: 6c 61 67 73 29 29 3b 0a 20 45 58 54 45 52 4e 20  lags));. EXTERN 
1c50: 56 4f 49 44 20 2a 09 09 54 63 6c 70 54 68 72 65  VOID *..TclpThre
1c60: 61 64 44 61 74 61 4b 65 79 47 65 74 20 5f 41 4e  adDataKeyGet _AN
1c70: 53 49 5f 41 52 47 53 5f 28 28 0a 20 09 09 09 20  SI_ARGS_((. ... 
1c80: 20 20 20 54 63 6c 5f 54 68 72 65 61 64 44 61 74     Tcl_ThreadDat
1c90: 61 4b 65 79 20 2a 6b 65 79 50 74 72 29 29 3b 0a  aKey *keyPtr));.
1ca0: 20 45 58 54 45 52 4e 20 76 6f 69 64 09 09 54 63   EXTERN void..Tc
1cb0: 6c 70 54 68 72 65 61 64 44 61 74 61 4b 65 79 49  lpThreadDataKeyI
1cc0: 6e 69 74 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28  nit _ANSI_ARGS_(
1cd0: 28 0a 49 6e 64 65 78 3a 20 67 65 6e 65 72 69 63  (.Index: generic
1ce0: 2f 74 63 6c 54 68 72 65 61 64 2e 63 0a 3d 3d 3d  /tclThread.c.===
1cf0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1d00: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1d10: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1d20: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1d30: 0a 52 43 53 20 66 69 6c 65 3a 20 2f 63 76 73 72  .RCS file: /cvsr
1d40: 6f 6f 74 2f 74 63 6c 2f 74 63 6c 2f 67 65 6e 65  oot/tcl/tcl/gene
1d50: 72 69 63 2f 74 63 6c 54 68 72 65 61 64 2e 63 2c  ric/tclThread.c,
1d60: 76 0a 72 65 74 72 69 65 76 69 6e 67 20 72 65 76  v.retrieving rev
1d70: 69 73 69 6f 6e 20 31 2e 36 0a 64 69 66 66 20 2d  ision 1.6.diff -
1d80: 75 20 2d 72 31 2e 36 20 74 63 6c 54 68 72 65 61  u -r1.6 tclThrea
1d90: 64 2e 63 0a 2d 2d 2d 20 67 65 6e 65 72 69 63 2f  d.c.--- generic/
1da0: 74 63 6c 54 68 72 65 61 64 2e 63 09 31 30 20 44  tclThread.c.10 D
1db0: 65 63 20 32 30 30 32 20 30 30 3a 33 34 3a 31 35  ec 2002 00:34:15
1dc0: 20 2d 30 30 30 30 09 31 2e 36 0a 2b 2b 2b 20 67   -0000.1.6.+++ g
1dd0: 65 6e 65 72 69 63 2f 74 63 6c 54 68 72 65 61 64  eneric/tclThread
1de0: 2e 63 09 31 34 20 4e 6f 76 20 32 30 30 33 20 32  .c.14 Nov 2003 2
1df0: 31 3a 31 33 3a 32 30 20 2d 30 30 30 30 0a 40 40  1:13:20 -0000.@@
1e00: 20 2d 34 38 34 2c 36 20 2b 34 38 34 2c 39 20 40   -484,6 +484,9 @
1e10: 40 0a 20 20 20 20 20 63 6f 6e 64 52 65 63 6f 72  @.     condRecor
1e20: 64 2e 6d 61 78 20 3d 20 30 3b 0a 20 20 20 20 20  d.max = 0;.     
1e30: 63 6f 6e 64 52 65 63 6f 72 64 2e 6e 75 6d 20 3d  condRecord.num =
1e40: 20 30 3b 0a 20 0a 2b 20 20 20 20 2f 2a 20 63 61   0;. .+    /* ca
1e50: 6c 6c 20 70 6c 61 74 66 6f 72 6d 20 73 70 65 63  ll platform spec
1e60: 69 66 69 63 20 74 68 72 65 61 64 20 73 74 6f 72  ific thread stor
1e70: 61 67 65 20 6d 61 73 74 65 72 20 63 6c 65 61 6e  age master clean
1e80: 75 70 20 2a 2f 0a 2b 20 20 20 20 54 63 6c 70 46  up */.+    TclpF
1e90: 69 6e 61 6c 69 7a 65 54 68 72 65 61 64 53 74 6f  inalizeThreadSto
1ea0: 72 61 67 65 28 29 3b 0a 2b 0a 20 20 20 20 20 54  rage();.+.     T
1eb0: 63 6c 70 4d 61 73 74 65 72 55 6e 6c 6f 63 6b 28  clpMasterUnlock(
1ec0: 29 3b 0a 20 23 65 6c 73 65 0a 20 20 20 20 20 69  );. #else.     i
1ed0: 66 20 28 6b 65 79 52 65 63 6f 72 64 2e 6c 69 73  f (keyRecord.lis
1ee0: 74 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 49 6e 64  t != NULL) {.Ind
1ef0: 65 78 3a 20 77 69 6e 2f 74 63 6c 57 69 6e 33 32  ex: win/tclWin32
1f00: 44 6c 6c 2e 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  Dll.c.==========
1f10: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1f20: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1f30: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1f40: 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69  =========.RCS fi
1f50: 6c 65 3a 20 2f 63 76 73 72 6f 6f 74 2f 74 63 6c  le: /cvsroot/tcl
1f60: 2f 74 63 6c 2f 77 69 6e 2f 74 63 6c 57 69 6e 33  /tcl/win/tclWin3
1f70: 32 44 6c 6c 2e 63 2c 76 0a 72 65 74 72 69 65 76  2Dll.c,v.retriev
1f80: 69 6e 67 20 72 65 76 69 73 69 6f 6e 20 31 2e 32  ing revision 1.2
1f90: 38 0a 64 69 66 66 20 2d 75 20 2d 72 31 2e 32 38  8.diff -u -r1.28
1fa0: 20 74 63 6c 57 69 6e 33 32 44 6c 6c 2e 63 0a 2d   tclWin32Dll.c.-
1fb0: 2d 2d 20 77 69 6e 2f 74 63 6c 57 69 6e 33 32 44  -- win/tclWin32D
1fc0: 6c 6c 2e 63 09 31 33 20 4f 63 74 20 32 30 30 33  ll.c.13 Oct 2003
1fd0: 20 31 36 3a 34 38 3a 30 37 20 2d 30 30 30 30 09   16:48:07 -0000.
1fe0: 31 2e 32 38 0a 2b 2b 2b 20 77 69 6e 2f 74 63 6c  1.28.+++ win/tcl
1ff0: 57 69 6e 33 32 44 6c 6c 2e 63 09 31 34 20 4e 6f  Win32Dll.c.14 No
2000: 76 20 32 30 30 33 20 32 31 3a 31 33 3a 32 31 20  v 2003 21:13:21 
2010: 2d 30 30 30 30 0a 40 40 20 2d 32 34 34 2c 38 20  -0000.@@ -244,8 
2020: 2b 32 34 34 2c 31 32 20 40 40 0a 20 20 20 20 20  +244,12 @@.     
2030: 73 77 69 74 63 68 20 28 72 65 61 73 6f 6e 29 20  switch (reason) 
2040: 7b 0a 20 20 20 20 20 63 61 73 65 20 44 4c 4c 5f  {.     case DLL_
2050: 50 52 4f 43 45 53 53 5f 41 54 54 41 43 48 3a 0a  PROCESS_ATTACH:.
2060: 20 09 54 63 6c 57 69 6e 49 6e 69 74 28 68 49 6e   .TclWinInit(hIn
2070: 73 74 29 3b 0a 2b 20 20 20 20 20 20 20 20 54 63  st);.+        Tc
2080: 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67 65 4c  lpThreadStorageL
2090: 6f 63 6b 49 6e 69 74 28 29 3b 20 2f 2a 0a 2b 20  ockInit(); /*.+ 
20a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
20b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
20c0: 20 20 20 20 20 2a 20 45 6c 69 6d 69 6e 61 74 65       * Eliminate
20d0: 20 70 6f 74 65 6e 74 69 61 6c 20 72 61 63 65 20   potential race 
20e0: 63 6f 6e 64 69 74 69 6f 6e 20 62 79 0a 2b 20 20  condition by.+  
20f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2110: 20 20 20 20 2a 20 64 6f 69 6e 67 20 74 68 69 73      * doing this
2120: 20 68 65 72 65 20 69 6e 20 63 61 73 65 20 6d 75   here in case mu
2130: 6c 74 69 70 6c 65 20 74 68 72 65 61 64 73 0a 2b  ltiple threads.+
2140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2150: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2160: 20 20 20 20 20 20 2a 20 6e 65 65 64 20 74 6f 20        * need to 
2170: 61 6c 6c 6f 63 61 74 65 20 6d 65 6d 6f 72 79 20  allocate memory 
2180: 73 74 72 61 69 67 68 74 20 61 77 61 79 2e 0a 2b  straight away..+
2190: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
21a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
21b0: 20 20 20 20 20 20 2a 2f 0a 20 09 72 65 74 75 72        */. .retur
21c0: 6e 20 54 52 55 45 3b 0a 2d 0a 20 20 20 20 20 63  n TRUE;.-.     c
21d0: 61 73 65 20 44 4c 4c 5f 50 52 4f 43 45 53 53 5f  ase DLL_PROCESS_
21e0: 44 45 54 41 43 48 3a 0a 20 09 69 66 20 28 68 49  DETACH:. .if (hI
21f0: 6e 73 74 20 3d 3d 20 68 49 6e 73 74 61 6e 63 65  nst == hInstance
2200: 29 20 7b 0a 20 09 20 20 20 20 54 63 6c 5f 46 69  ) {. .    Tcl_Fi
2210: 6e 61 6c 69 7a 65 28 29 3b 0a 49 6e 64 65 78 3a  nalize();.Index:
2220: 20 77 69 6e 2f 74 63 6c 57 69 6e 54 68 72 64 2e   win/tclWinThrd.
2230: 63 0a 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  c.==============
2240: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
2250: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
2260: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
2270: 3d 3d 3d 3d 3d 0a 52 43 53 20 66 69 6c 65 3a 20  =====.RCS file: 
2280: 2f 63 76 73 72 6f 6f 74 2f 74 63 6c 2f 74 63 6c  /cvsroot/tcl/tcl
2290: 2f 77 69 6e 2f 74 63 6c 57 69 6e 54 68 72 64 2e  /win/tclWinThrd.
22a0: 63 2c 76 0a 72 65 74 72 69 65 76 69 6e 67 20 72  c,v.retrieving r
22b0: 65 76 69 73 69 6f 6e 20 31 2e 32 36 0a 64 69 66  evision 1.26.dif
22c0: 66 20 2d 75 20 2d 72 31 2e 32 36 20 74 63 6c 57  f -u -r1.26 tclW
22d0: 69 6e 54 68 72 64 2e 63 0a 2d 2d 2d 20 77 69 6e  inThrd.c.--- win
22e0: 2f 74 63 6c 57 69 6e 54 68 72 64 2e 63 09 31 33  /tclWinThrd.c.13
22f0: 20 4d 61 79 20 32 30 30 33 20 31 30 3a 31 36 3a   May 2003 10:16:
2300: 31 37 20 2d 30 30 30 30 09 31 2e 32 36 0a 2b 2b  17 -0000.1.26.++
2310: 2b 20 77 69 6e 2f 74 63 6c 57 69 6e 54 68 72 64  + win/tclWinThrd
2320: 2e 63 09 31 34 20 4e 6f 76 20 32 30 30 33 20 32  .c.14 Nov 2003 2
2330: 31 3a 31 33 3a 32 31 20 2d 30 30 30 30 0a 40 40  1:13:21 -0000.@@
2340: 20 2d 31 34 2c 36 20 2b 31 34 2c 31 32 20 40 40   -14,6 +14,12 @@
2350: 0a 20 0a 20 23 69 6e 63 6c 75 64 65 20 22 74 63  . . #include "tc
2360: 6c 57 69 6e 49 6e 74 2e 68 22 0a 20 0a 2b 2f 2a  lWinInt.h". .+/*
2370: 20 54 4f 44 4f 3a 20 70 75 74 20 74 68 65 73 65   TODO: put these
2380: 20 69 6e 20 74 68 65 20 22 73 74 61 6e 64 61 72   in the "standar
2390: 64 22 20 6c 6f 63 61 74 69 6f 6e 28 73 29 2e 20  d" location(s). 
23a0: 2a 2f 0a 2b 23 64 65 66 69 6e 65 20 54 43 4c 5f  */.+#define TCL_
23b0: 4e 4f 5f 54 4c 53 0a 2b 23 64 65 66 69 6e 65 20  NO_TLS.+#define 
23c0: 54 43 4c 5f 54 48 52 45 41 44 5f 41 4c 4c 4f 43  TCL_THREAD_ALLOC
23d0: 5f 4e 4f 5f 54 4c 53 0a 2b 2f 2a 20 57 41 52 4e  _NO_TLS.+/* WARN
23e0: 49 4e 47 3a 20 70 72 6f 64 75 63 65 73 20 61 20  ING: produces a 
23f0: 6c 6f 74 20 6f 66 20 6f 75 74 70 75 74 2e 20 2a  lot of output. *
2400: 2f 0a 2b 2f 2a 20 23 64 65 66 69 6e 65 20 54 43  /.+/* #define TC
2410: 4c 5f 54 48 52 45 41 44 5f 53 54 4f 52 41 47 45  L_THREAD_STORAGE
2420: 5f 44 45 42 55 47 20 2a 2f 0a 2b 0a 20 23 69 6e  _DEBUG */.+. #in
2430: 63 6c 75 64 65 20 3c 66 63 6e 74 6c 2e 68 3e 0a  clude <fcntl.h>.
2440: 20 23 69 6e 63 6c 75 64 65 20 3c 69 6f 2e 68 3e   #include <io.h>
2450: 0a 20 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 2f  . #include <sys/
2460: 73 74 61 74 2e 68 3e 0a 40 40 20 2d 31 31 30 2c  stat.h>.@@ -110,
2470: 36 20 2b 31 31 36 2c 39 36 20 40 40 0a 20 20 20  6 +116,96 @@.   
2480: 20 20 73 74 72 75 63 74 20 54 68 72 65 61 64 53    struct ThreadS
2490: 70 65 63 69 66 69 63 44 61 74 61 20 2a 6c 61 73  pecificData *las
24a0: 74 50 74 72 3b 0a 20 7d 20 57 69 6e 43 6f 6e 64  tPtr;. } WinCond
24b0: 69 74 69 6f 6e 3b 0a 20 0a 2b 2f 2a 0a 2b 20 2a  ition;. .+/*.+ *
24c0: 20 54 68 69 73 20 69 73 20 74 68 65 20 74 68 72   This is the thr
24d0: 65 61 64 20 73 74 6f 72 61 67 65 20 63 61 63 68  ead storage cach
24e0: 65 20 61 72 72 61 79 20 61 6e 64 20 69 74 27 73  e array and it's
24f0: 20 61 63 63 6f 6d 70 61 6e 79 69 6e 67 20 6d 75   accompanying mu
2500: 74 65 78 2e 0a 2b 20 2a 20 54 68 65 20 65 6c 65  tex..+ * The ele
2510: 6d 65 6e 74 73 20 61 72 65 20 70 61 69 72 73 20  ments are pairs 
2520: 6f 66 20 74 68 72 65 61 64 20 49 64 20 61 6e 64  of thread Id and
2530: 20 61 6e 20 61 73 73 6f 63 69 61 74 65 64 20 68   an associated h
2540: 61 73 68 20 74 61 62 6c 65 0a 2b 20 2a 20 70 6f  ash table.+ * po
2550: 69 6e 74 65 72 3b 20 74 68 65 20 68 61 73 68 20  inter; the hash 
2560: 74 61 62 6c 65 20 62 65 69 6e 67 20 70 6f 69 6e  table being poin
2570: 74 65 64 20 74 6f 20 63 6f 6e 74 61 69 6e 73 20  ted to contains 
2580: 74 68 65 20 74 68 72 65 61 64 20 73 74 6f 72 61  the thread stora
2590: 67 65 0a 2b 20 2a 20 66 6f 72 20 69 74 27 73 20  ge.+ * for it's 
25a0: 61 73 73 6f 63 69 61 74 65 64 20 74 68 72 65 61  associated threa
25b0: 64 2e 20 54 68 65 20 70 75 72 70 6f 73 65 20 6f  d. The purpose o
25c0: 66 20 74 68 69 73 20 63 61 63 68 65 20 69 73 20  f this cache is 
25d0: 74 6f 20 6d 69 6e 69 6d 69 7a 65 0a 2b 20 2a 0a  to minimize.+ *.
25e0: 2b 20 2a 2f 0a 2b 73 74 61 74 69 63 20 43 52 49  + */.+static CRI
25f0: 54 49 43 41 4c 5f 53 45 43 54 49 4f 4e 20 74 68  TICAL_SECTION th
2600: 72 65 61 64 53 74 6f 72 61 67 65 4c 6f 63 6b 3b  readStorageLock;
2610: 0a 2b 23 64 65 66 69 6e 65 20 53 54 4f 52 41 47  .+#define STORAG
2620: 45 5f 4c 4f 43 4b 20 20 54 63 6c 70 54 68 72 65  E_LOCK  TclpThre
2630: 61 64 53 74 6f 72 61 67 65 4c 6f 63 6b 28 29 0a  adStorageLock().
2640: 2b 23 64 65 66 69 6e 65 20 53 54 4f 52 41 47 45  +#define STORAGE
2650: 5f 55 4e 4c 4f 43 4b 20 20 54 63 6c 70 54 68 72  _UNLOCK  TclpThr
2660: 65 61 64 53 74 6f 72 61 67 65 55 6e 6c 6f 63 6b  eadStorageUnlock
2670: 28 29 0a 2b 0a 2b 2f 2a 0a 2b 20 2a 20 54 68 69  ().+.+/*.+ * Thi
2680: 73 20 69 73 20 74 68 65 20 73 74 72 75 63 74 20  s is the struct 
2690: 75 73 65 64 20 66 6f 72 20 61 20 74 68 72 65 61  used for a threa
26a0: 64 20 73 74 6f 72 61 67 65 20 63 61 63 68 65 20  d storage cache 
26b0: 73 6c 6f 74 2e 20 49 74 0a 2b 20 2a 20 63 6f 6e  slot. It.+ * con
26c0: 74 61 69 6e 73 20 74 68 65 20 6f 77 6e 69 6e 67  tains the owning
26d0: 20 74 68 72 65 61 64 20 49 64 20 61 6e 64 20 74   thread Id and t
26e0: 68 65 20 61 73 73 6f 63 69 61 74 65 64 20 68 61  he associated ha
26f0: 73 68 20 74 61 62 6c 65 0a 2b 20 2a 20 70 6f 69  sh table.+ * poi
2700: 6e 74 65 72 2e 0a 2b 20 2a 2f 0a 2b 74 79 70 65  nter..+ */.+type
2710: 64 65 66 20 73 74 72 75 63 74 20 57 69 6e 54 68  def struct WinTh
2720: 72 65 61 64 53 74 6f 72 61 67 65 20 7b 0a 2b 20  readStorage {.+ 
2730: 20 54 63 6c 5f 54 68 72 65 61 64 49 64 20 69 64   Tcl_ThreadId id
2740: 3b 20 2f 2a 20 74 68 65 20 6f 77 6e 69 6e 67 20  ; /* the owning 
2750: 74 68 72 65 61 64 20 69 64 20 2a 2f 0a 2b 20 20  thread id */.+  
2760: 54 63 6c 5f 48 61 73 68 54 61 62 6c 65 20 2a 68  Tcl_HashTable *h
2770: 61 73 68 54 61 62 6c 65 50 74 72 3b 20 2f 2a 20  ashTablePtr; /* 
2780: 74 68 65 20 68 61 73 68 20 74 61 62 6c 65 20 66  the hash table f
2790: 6f 72 20 74 68 65 20 74 68 72 65 61 64 20 2a 2f  or the thread */
27a0: 0a 2b 7d 20 57 69 6e 54 68 72 65 61 64 53 74 6f  .+} WinThreadSto
27b0: 72 61 67 65 3b 0a 2b 0a 2b 2f 2a 0a 2b 20 2a 20  rage;.+.+/*.+ * 
27c0: 54 68 65 73 65 20 61 72 65 20 74 68 65 20 70 72  These are the pr
27d0: 6f 74 6f 74 79 70 65 73 20 66 6f 72 20 74 68 65  ototypes for the
27e0: 20 63 75 73 74 6f 6d 20 68 61 73 68 20 74 61 62   custom hash tab
27f0: 6c 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 0a 2b 20  le allocation.+ 
2800: 2a 20 66 75 6e 63 74 69 6f 6e 73 20 75 73 65 64  * functions used
2810: 20 62 79 20 74 68 65 20 74 68 72 65 61 64 20 73   by the thread s
2820: 74 6f 72 61 67 65 20 73 75 62 73 79 73 74 65 6d  torage subsystem
2830: 2e 0a 2b 20 2a 2f 0a 2b 73 74 61 74 69 63 20 54  ..+ */.+static T
2840: 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 2a 09 41  cl_HashEntry *.A
2850: 6c 6c 6f 63 54 68 72 65 61 64 53 74 6f 72 61 67  llocThreadStorag
2860: 65 45 6e 74 72 79 20 5f 41 4e 53 49 5f 41 52 47  eEntry _ANSI_ARG
2870: 53 5f 28 28 0a 2b 09 09 09 20 20 20 20 54 63 6c  S_((.+...    Tcl
2880: 5f 48 61 73 68 54 61 62 6c 65 20 2a 74 61 62 6c  _HashTable *tabl
2890: 65 50 74 72 2c 20 56 4f 49 44 20 2a 6b 65 79 50  ePtr, VOID *keyP
28a0: 74 72 29 29 3b 0a 2b 73 74 61 74 69 63 20 76 6f  tr));.+static vo
28b0: 69 64 09 09 46 72 65 65 54 68 72 65 61 64 53 74  id..FreeThreadSt
28c0: 6f 72 61 67 65 45 6e 74 72 79 20 5f 41 4e 53 49  orageEntry _ANSI
28d0: 5f 41 52 47 53 5f 28 28 0a 2b 09 09 09 20 20 20  _ARGS_((.+...   
28e0: 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 2a   Tcl_HashEntry *
28f0: 68 50 74 72 29 29 3b 0a 2b 0a 2b 2f 2a 0a 2b 20  hPtr));.+.+/*.+ 
2900: 2a 20 54 68 69 73 20 69 73 20 74 68 65 20 68 61  * This is the ha
2910: 73 68 20 6b 65 79 20 74 79 70 65 20 66 6f 72 20  sh key type for 
2920: 74 68 72 65 61 64 20 73 74 6f 72 61 67 65 2e 20  thread storage. 
2930: 57 65 20 4d 55 53 54 20 75 73 65 0a 2b 20 2a 20  We MUST use.+ * 
2940: 74 68 69 73 20 62 65 63 61 75 73 65 20 74 68 65  this because the
2950: 73 65 20 68 61 73 68 20 74 61 62 6c 65 73 20 61  se hash tables a
2960: 72 65 20 75 73 65 64 20 62 79 20 74 68 65 20 74  re used by the t
2970: 68 72 65 61 64 65 64 20 6d 65 6d 6f 72 79 0a 2b  hreaded memory.+
2980: 20 2a 20 61 6c 6c 6f 63 61 74 6f 72 2e 0a 2b 20   * allocator..+ 
2990: 2a 2f 0a 2b 54 63 6c 5f 48 61 73 68 4b 65 79 54  */.+Tcl_HashKeyT
29a0: 79 70 65 20 74 63 6c 54 68 72 65 61 64 53 74 6f  ype tclThreadSto
29b0: 72 61 67 65 48 61 73 68 4b 65 79 54 79 70 65 20  rageHashKeyType 
29c0: 3d 20 7b 0a 2b 20 20 20 20 54 43 4c 5f 48 41 53  = {.+    TCL_HAS
29d0: 48 5f 4b 45 59 5f 54 59 50 45 5f 56 45 52 53 49  H_KEY_TYPE_VERSI
29e0: 4f 4e 2c 20 20 20 20 20 20 20 20 20 20 2f 2a 20  ON,          /* 
29f0: 76 65 72 73 69 6f 6e 20 2a 2f 0a 2b 20 20 20 20  version */.+    
2a00: 54 43 4c 5f 48 41 53 48 5f 4b 45 59 5f 53 59 53  TCL_HASH_KEY_SYS
2a10: 54 45 4d 5f 48 41 53 48 2c 20 20 20 20 20 20 20  TEM_HASH,       
2a20: 20 20 20 20 2f 2a 20 66 6c 61 67 73 20 2a 2f 0a      /* flags */.
2a30: 2b 20 20 20 20 4e 55 4c 4c 2c 20 20 20 20 20 20  +    NULL,      
2a40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2a50: 20 20 20 20 20 20 20 20 20 2f 2a 20 68 61 73 68           /* hash
2a60: 4b 65 79 50 72 6f 63 20 2a 2f 0a 2b 20 20 20 20  KeyProc */.+    
2a70: 4e 55 4c 4c 2c 20 20 20 20 20 20 20 20 20 20 20  NULL,           
2a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2a90: 20 20 20 20 2f 2a 20 63 6f 6d 70 61 72 65 4b 65      /* compareKe
2aa0: 79 73 50 72 6f 63 20 2a 2f 0a 2b 20 20 20 20 41  ysProc */.+    A
2ab0: 6c 6c 6f 63 54 68 72 65 61 64 53 74 6f 72 61 67  llocThreadStorag
2ac0: 65 45 6e 74 72 79 2c 20 20 20 20 20 20 20 20 20  eEntry,         
2ad0: 20 20 20 2f 2a 20 61 6c 6c 6f 63 45 6e 74 72 79     /* allocEntry
2ae0: 50 72 6f 63 20 2a 2f 0a 2b 20 20 20 20 46 72 65  Proc */.+    Fre
2af0: 65 54 68 72 65 61 64 53 74 6f 72 61 67 65 45 6e  eThreadStorageEn
2b00: 74 72 79 20 20 20 20 20 20 20 20 20 20 20 20 20  try             
2b10: 20 2f 2a 20 66 72 65 65 45 6e 74 72 79 50 72 6f   /* freeEntryPro
2b20: 63 20 2a 2f 0a 2b 7d 3b 0a 2b 0a 2b 2f 2a 0a 2b  c */.+};.+.+/*.+
2b30: 20 2a 20 54 68 69 73 20 69 73 20 61 6e 20 69 6e   * This is an in
2b40: 76 61 6c 69 64 20 74 68 72 65 61 64 20 76 61 6c  valid thread val
2b50: 75 65 2e 0a 2b 20 2a 2f 0a 2b 23 64 65 66 69 6e  ue..+ */.+#defin
2b60: 65 20 53 54 4f 52 41 47 45 5f 49 4e 56 41 4c 49  e STORAGE_INVALI
2b70: 44 5f 54 48 52 45 41 44 20 20 30 0a 2b 0a 2b 2f  D_THREAD  0.+.+/
2b80: 2a 0a 2b 20 2a 20 54 68 69 73 20 69 73 20 74 68  *.+ * This is th
2b90: 65 20 76 61 6c 75 65 20 66 6f 72 20 61 6e 20 69  e value for an i
2ba0: 6e 76 61 6c 69 64 20 74 68 72 65 61 64 20 73 74  nvalid thread st
2bb0: 6f 72 61 67 65 20 6b 65 79 2e 0a 2b 20 2a 2f 0a  orage key..+ */.
2bc0: 2b 23 64 65 66 69 6e 65 20 53 54 4f 52 41 47 45  +#define STORAGE
2bd0: 5f 49 4e 56 41 4c 49 44 5f 4b 45 59 20 20 20 20  _INVALID_KEY    
2be0: 20 30 0a 2b 0a 2b 2f 2a 0a 2b 20 2a 20 54 68 69   0.+.+/*.+ * Thi
2bf0: 73 20 69 73 20 74 68 65 20 66 69 72 73 74 20 76  s is the first v
2c00: 61 6c 69 64 20 6b 65 79 20 66 6f 72 20 75 73 65  alid key for use
2c10: 20 62 79 20 65 78 74 65 72 6e 61 6c 20 63 61 6c   by external cal
2c20: 6c 65 72 73 2e 0a 2b 20 2a 2f 0a 2b 23 64 65 66  lers..+ */.+#def
2c30: 69 6e 65 20 53 54 4f 52 41 47 45 5f 46 49 52 53  ine STORAGE_FIRS
2c40: 54 5f 4b 45 59 20 20 20 20 20 20 20 31 0a 2b 0a  T_KEY       1.+.
2c50: 2b 2f 2a 0a 2b 20 2a 20 54 68 69 73 20 64 65 66  +/*.+ * This def
2c60: 69 6e 65 20 6d 61 79 20 6e 65 65 64 20 74 6f 20  ine may need to 
2c70: 62 65 20 66 69 6e 65 20 74 75 6e 65 64 20 66 6f  be fine tuned fo
2c80: 72 20 6d 61 78 69 6d 75 6d 20 70 65 72 66 6f 72  r maximum perfor
2c90: 6d 61 6e 63 65 2e 0a 2b 20 2a 2f 0a 2b 23 64 65  mance..+ */.+#de
2ca0: 66 69 6e 65 20 53 54 4f 52 41 47 45 5f 43 41 43  fine STORAGE_CAC
2cb0: 48 45 5f 53 4c 4f 54 53 20 20 20 20 20 31 30 30  HE_SLOTS     100
2cc0: 0a 2b 0a 2b 2f 2a 0a 2b 20 2a 20 54 68 69 73 20  .+.+/*.+ * This 
2cd0: 69 73 20 74 68 65 20 6d 61 73 74 65 72 20 74 68  is the master th
2ce0: 72 65 61 64 20 73 74 6f 72 61 67 65 20 68 61 73  read storage has
2cf0: 68 20 74 61 62 6c 65 2e 20 49 74 20 69 73 20 6b  h table. It is k
2d00: 65 79 65 64 20 6f 6e 0a 2b 20 2a 20 74 68 72 65  eyed on.+ * thre
2d10: 61 64 20 49 64 20 61 6e 64 20 63 6f 6e 74 61 69  ad Id and contai
2d20: 6e 73 20 76 61 6c 75 65 73 20 74 68 61 74 20 61  ns values that a
2d30: 72 65 20 68 61 73 68 20 74 61 62 6c 65 73 20 66  re hash tables f
2d40: 6f 72 20 65 61 63 68 20 74 68 72 65 61 64 2e 0a  or each thread..
2d50: 2b 20 2a 20 54 68 65 20 74 68 72 65 61 64 20 73  + * The thread s
2d60: 70 65 63 69 66 69 63 20 68 61 73 68 20 74 61 62  pecific hash tab
2d70: 6c 65 73 20 63 6f 6e 74 61 69 6e 20 74 68 65 20  les contain the 
2d80: 61 63 74 75 61 6c 20 74 68 72 65 61 64 20 73 74  actual thread st
2d90: 6f 72 61 67 65 2e 0a 2b 20 2a 2f 0a 2b 73 74 61  orage..+ */.+sta
2da0: 74 69 63 20 54 63 6c 5f 48 61 73 68 54 61 62 6c  tic Tcl_HashTabl
2db0: 65 20 2a 74 68 72 65 61 64 53 74 6f 72 61 67 65  e *threadStorage
2dc0: 48 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20 4e  HashTablePtr = N
2dd0: 55 4c 4c 3b 0a 2b 0a 2b 2f 2a 0a 2b 20 2a 20 54  ULL;.+.+/*.+ * T
2de0: 68 69 73 20 69 73 20 74 68 65 20 6e 65 78 74 20  his is the next 
2df0: 74 68 72 65 61 64 20 64 61 74 61 20 6b 65 79 20  thread data key 
2e00: 76 61 6c 75 65 20 74 6f 20 75 73 65 2e 20 57 65  value to use. We
2e10: 20 69 6e 63 72 65 6d 65 6e 74 20 74 68 69 73 0a   increment this.
2e20: 2b 20 2a 20 65 76 65 72 79 74 69 6d 65 20 77 65  + * everytime we
2e30: 20 22 61 6c 6c 6f 63 61 74 65 22 20 6f 6e 65 2e   "allocate" one.
2e40: 20 49 74 20 69 73 20 69 6e 69 74 69 61 6c 6c 79   It is initially
2e50: 20 73 65 74 20 74 6f 20 31 20 69 6e 0a 2b 20 2a   set to 1 in.+ *
2e60: 20 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61   TclpThreadStora
2e70: 67 65 49 6e 69 74 2e 0a 2b 20 2a 2f 0a 2b 73 74  geInit..+ */.+st
2e80: 61 74 69 63 20 44 57 4f 52 44 20 6e 65 78 74 54  atic DWORD nextT
2e90: 68 72 65 61 64 53 74 6f 72 61 67 65 4b 65 79 20  hreadStorageKey 
2ea0: 3d 20 53 54 4f 52 41 47 45 5f 49 4e 56 41 4c 49  = STORAGE_INVALI
2eb0: 44 5f 4b 45 59 3b 0a 2b 0a 2b 2f 2a 0a 2b 20 2a  D_KEY;.+.+/*.+ *
2ec0: 20 48 61 76 65 20 77 65 20 69 6e 69 74 69 61 6c   Have we initial
2ed0: 69 7a 65 64 20 74 68 65 20 74 68 72 65 61 64 20  ized the thread 
2ee0: 73 74 6f 72 61 67 65 20 63 72 69 74 69 63 61 6c  storage critical
2ef0: 20 73 65 63 74 69 6f 6e 20 79 65 74 3f 0a 2b 20   section yet?.+ 
2f00: 2a 2f 0a 2b 73 74 61 74 69 63 20 69 6e 74 20 69  */.+static int i
2f10: 6e 69 74 54 68 72 65 61 64 53 74 6f 72 61 67 65  nitThreadStorage
2f20: 20 3d 20 30 3b 0a 2b 0a 2b 2f 2a 0a 2b 20 2a 20   = 0;.+.+/*.+ * 
2f30: 54 68 69 73 20 69 73 20 74 68 65 20 6d 61 73 74  This is the mast
2f40: 65 72 20 74 68 72 65 61 64 20 73 74 6f 72 61 67  er thread storag
2f50: 65 20 63 61 63 68 65 2e 20 50 65 72 20 6b 65 6e  e cache. Per ken
2f60: 6e 79 6b 62 27 73 20 69 64 65 61 2c 20 74 68 69  nykb's idea, thi
2f70: 73 0a 2b 20 2a 20 70 72 65 76 65 6e 74 73 20 75  s.+ * prevents u
2f80: 6e 6e 65 63 65 73 73 61 72 79 20 6c 6f 6f 6b 75  nnecessary looku
2f90: 70 73 20 66 6f 72 20 74 68 72 65 61 64 73 20 74  ps for threads t
2fa0: 68 61 74 20 75 73 65 20 61 20 6c 6f 74 20 6f 66  hat use a lot of
2fb0: 20 74 68 72 65 61 64 0a 2b 20 2a 20 73 74 6f 72   thread.+ * stor
2fc0: 61 67 65 2e 0a 2b 20 2a 2f 0a 2b 76 6f 6c 61 74  age..+ */.+volat
2fd0: 69 6c 65 20 57 69 6e 54 68 72 65 61 64 53 74 6f  ile WinThreadSto
2fe0: 72 61 67 65 20 74 68 72 65 61 64 53 74 6f 72 61  rage threadStora
2ff0: 67 65 43 61 63 68 65 5b 53 54 4f 52 41 47 45 5f  geCache[STORAGE_
3000: 43 41 43 48 45 5f 53 4c 4f 54 53 5d 3b 0a 2b 0a  CACHE_SLOTS];.+.
3010: 20 0c 0a 20 2f 2a 0a 20 20 2a 2d 2d 2d 2d 2d 2d   .. /*.  *------
3020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3050: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3060: 0a 40 40 20 2d 33 37 33 2c 36 20 2b 34 36 39 2c  .@@ -373,6 +469,
3070: 38 38 20 40 40 0a 20 2f 2a 0a 20 20 2a 2d 2d 2d  88 @@. /*.  *---
3080: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3090: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
30a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
30b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
30c0: 2d 2d 2d 0a 20 20 2a 0a 2b 20 2a 20 54 63 6c 70  ---.  *.+ * Tclp
30d0: 54 68 72 65 61 64 53 74 6f 72 61 67 65 4c 6f 63  ThreadStorageLoc
30e0: 6b 49 6e 69 74 0a 2b 20 2a 0a 2b 20 2a 20 20 20  kInit.+ *.+ *   
30f0: 20 20 20 54 68 69 73 20 70 72 6f 63 65 64 75 72     This procedur
3100: 65 20 69 73 20 75 73 65 64 20 74 6f 20 69 6e 69  e is used to ini
3110: 74 69 61 6c 69 7a 65 20 74 68 65 20 6c 6f 63 6b  tialize the lock
3120: 20 74 68 61 74 20 73 65 72 69 61 6c 69 7a 65 73   that serializes
3130: 0a 2b 20 2a 20 20 20 20 20 20 63 72 65 61 74 69  .+ *      creati
3140: 6f 6e 20 6f 66 20 74 68 72 65 61 64 20 73 74 6f  on of thread sto
3150: 72 61 67 65 2e 0a 2b 20 2a 0a 2b 20 2a 20 52 65  rage..+ *.+ * Re
3160: 73 75 6c 74 73 3a 0a 2b 20 2a 20 20 20 20 20 20  sults:.+ *      
3170: 4e 6f 6e 65 2e 0a 2b 20 2a 0a 2b 20 2a 20 53 69  None..+ *.+ * Si
3180: 64 65 20 65 66 66 65 63 74 73 3a 0a 2b 20 2a 20  de effects:.+ * 
3190: 20 20 20 20 20 4e 6f 6e 65 2e 0a 2b 20 2a 0a 2b       None..+ *.+
31a0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
31b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31e0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 2f 0a 2b 0a  --------.+ */.+.
31f0: 2b 76 6f 69 64 0a 2b 54 63 6c 70 54 68 72 65 61  +void.+TclpThrea
3200: 64 53 74 6f 72 61 67 65 4c 6f 63 6b 49 6e 69 74  dStorageLockInit
3210: 28 29 0a 2b 7b 0a 2b 20 20 20 20 69 66 20 28 21  ().+{.+    if (!
3220: 69 6e 69 74 54 68 72 65 61 64 53 74 6f 72 61 67  initThreadStorag
3230: 65 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 2f 2a  e) {.+        /*
3240: 0a 2b 20 20 20 20 20 20 20 20 20 2a 20 54 68 65  .+         * The
3250: 72 65 20 69 73 20 61 20 66 75 6e 64 61 6d 65 6e  re is a fundamen
3260: 74 61 6c 20 72 61 63 65 20 68 65 72 65 20 74 68  tal race here th
3270: 61 74 20 69 73 20 73 6f 6c 76 65 64 20 62 79 20  at is solved by 
3280: 63 72 65 61 74 69 6e 67 0a 2b 20 20 20 20 20 20  creating.+      
3290: 20 20 20 2a 20 74 68 65 20 66 69 72 73 74 20 54     * the first T
32a0: 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 20 69  cl interpreter i
32b0: 6e 20 61 20 73 69 6e 67 6c 65 20 74 68 72 65 61  n a single threa
32c0: 64 65 64 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 2e  ded environment.
32d0: 0a 2b 20 20 20 20 20 20 20 20 20 2a 20 4f 6e 63  .+         * Onc
32e0: 65 20 74 68 65 20 69 6e 74 65 72 70 72 65 74 65  e the interprete
32f0: 72 20 68 61 73 20 62 65 65 6e 20 63 72 65 61 74  r has been creat
3300: 65 64 2c 20 69 74 20 69 73 20 73 61 66 65 20 74  ed, it is safe t
3310: 6f 20 63 72 65 61 74 65 0a 2b 20 20 20 20 20 20  o create.+      
3320: 20 20 20 2a 20 6d 6f 72 65 20 74 68 72 65 61 64     * more thread
3330: 73 20 74 68 61 74 20 63 72 65 61 74 65 20 69 6e  s that create in
3340: 74 65 72 70 72 65 74 65 72 73 20 69 6e 20 70 61  terpreters in pa
3350: 72 61 6c 6c 65 6c 2e 0a 2b 20 20 20 20 20 20 20  rallel..+       
3360: 20 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 69 6e    */.+        in
3370: 69 74 54 68 72 65 61 64 53 74 6f 72 61 67 65 20  itThreadStorage 
3380: 3d 20 31 3b 0a 2b 20 20 20 20 20 20 20 20 49 6e  = 1;.+        In
3390: 69 74 69 61 6c 69 7a 65 43 72 69 74 69 63 61 6c  itializeCritical
33a0: 53 65 63 74 69 6f 6e 28 26 74 68 72 65 61 64 53  Section(&threadS
33b0: 74 6f 72 61 67 65 4c 6f 63 6b 29 3b 0a 2b 20 20  torageLock);.+  
33c0: 20 20 7d 0a 2b 7d 0a 2b 0c 0a 2b 2f 2a 0a 2b 20    }.+}.+..+/*.+ 
33d0: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *---------------
33e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
33f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3410: 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 0a 2b 20 2a 20  -------.+ *.+ * 
3420: 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67  TclpThreadStorag
3430: 65 4c 6f 63 6b 0a 2b 20 2a 0a 2b 20 2a 20 20 20  eLock.+ *.+ *   
3440: 20 20 20 54 68 69 73 20 70 72 6f 63 65 64 75 72     This procedur
3450: 65 20 69 73 20 75 73 65 64 20 74 6f 20 67 72 61  e is used to gra
3460: 62 20 61 20 6c 6f 63 6b 20 74 68 61 74 20 73 65  b a lock that se
3470: 72 69 61 6c 69 7a 65 73 20 63 72 65 61 74 69 6f  rializes creatio
3480: 6e 0a 2b 20 2a 20 20 20 20 20 20 6f 66 20 74 68  n.+ *      of th
3490: 72 65 61 64 20 73 74 6f 72 61 67 65 2e 0a 2b 20  read storage..+ 
34a0: 2a 0a 2b 20 2a 20 20 20 20 20 20 54 68 69 73 20  *.+ *      This 
34b0: 6c 6f 63 6b 20 6d 75 73 74 20 62 65 20 64 69 66  lock must be dif
34c0: 66 65 72 65 6e 74 20 74 68 61 6e 20 74 68 65 20  ferent than the 
34d0: 69 6e 69 74 4c 6f 63 6b 20 62 65 63 61 75 73 65  initLock because
34e0: 20 74 68 65 0a 2b 20 2a 20 20 20 20 20 20 69 6e   the.+ *      in
34f0: 69 74 4c 6f 63 6b 20 69 73 20 68 65 6c 64 20 64  itLock is held d
3500: 75 72 69 6e 67 20 63 72 65 61 74 69 6f 6e 20 6f  uring creation o
3510: 66 20 73 79 6e 63 72 6f 6e 69 7a 61 74 69 6f 6e  f syncronization
3520: 20 6f 62 6a 65 63 74 73 2e 0a 2b 20 2a 0a 2b 20   objects..+ *.+ 
3530: 2a 20 52 65 73 75 6c 74 73 3a 0a 2b 20 2a 20 20  * Results:.+ *  
3540: 20 20 20 20 4e 6f 6e 65 2e 0a 2b 20 2a 0a 2b 20      None..+ *.+ 
3550: 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a  * Side effects:.
3560: 2b 20 2a 20 20 20 20 20 20 41 63 71 75 69 72 65  + *      Acquire
3570: 20 74 68 65 20 74 68 72 65 61 64 20 73 74 6f 72   the thread stor
3580: 61 67 65 20 6d 75 74 65 78 2e 0a 2b 20 2a 0a 2b  age mutex..+ *.+
3590: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
35a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
35b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
35c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
35d0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 2f 0a 2b 0a  --------.+ */.+.
35e0: 2b 76 6f 69 64 0a 2b 54 63 6c 70 54 68 72 65 61  +void.+TclpThrea
35f0: 64 53 74 6f 72 61 67 65 4c 6f 63 6b 28 29 0a 2b  dStorageLock().+
3600: 7b 0a 2b 20 20 20 20 54 63 6c 70 54 68 72 65 61  {.+    TclpThrea
3610: 64 53 74 6f 72 61 67 65 4c 6f 63 6b 49 6e 69 74  dStorageLockInit
3620: 28 29 3b 0a 2b 20 20 20 20 45 6e 74 65 72 43 72  ();.+    EnterCr
3630: 69 74 69 63 61 6c 53 65 63 74 69 6f 6e 28 26 74  iticalSection(&t
3640: 68 72 65 61 64 53 74 6f 72 61 67 65 4c 6f 63 6b  hreadStorageLock
3650: 29 3b 0a 2b 7d 0a 2b 0c 0a 2b 2f 2a 0a 2b 20 2a  );.+}.+..+/*.+ *
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 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3690: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
36a0: 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 0a 2b 20 2a 20 54  ------.+ *.+ * T
36b0: 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67 65  clpThreadStorage
36c0: 55 6e 6c 6f 63 6b 0a 2b 20 2a 0a 2b 20 2a 20 20  Unlock.+ *.+ *  
36d0: 20 20 20 20 54 68 69 73 20 70 72 6f 63 65 64 75      This procedu
36e0: 72 65 20 69 73 20 75 73 65 64 20 74 6f 20 72 65  re is used to re
36f0: 6c 65 61 73 65 20 61 20 6c 6f 63 6b 20 74 68 61  lease a lock tha
3700: 74 20 73 65 72 69 61 6c 69 7a 65 73 20 63 72 65  t serializes cre
3710: 61 74 69 6f 6e 0a 2b 20 2a 20 20 20 20 20 20 6f  ation.+ *      o
3720: 66 20 74 68 72 65 61 64 20 73 74 6f 72 61 67 65  f thread storage
3730: 2e 0a 2b 20 2a 0a 2b 20 2a 20 52 65 73 75 6c 74  ..+ *.+ * Result
3740: 73 3a 0a 2b 20 2a 20 20 20 20 20 20 4e 6f 6e 65  s:.+ *      None
3750: 2e 0a 2b 20 2a 0a 2b 20 2a 20 53 69 64 65 20 65  ..+ *.+ * Side e
3760: 66 66 65 63 74 73 3a 0a 2b 20 2a 20 20 20 20 20  ffects:.+ *     
3770: 20 52 65 6c 65 61 73 65 20 74 68 65 20 74 68 72   Release the thr
3780: 65 61 64 20 73 74 6f 72 61 67 65 20 6d 75 74 65  ead storage mute
3790: 78 2e 0a 2b 20 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d  x..+ *.+ *------
37a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
37b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
37c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
37d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
37e0: 0a 2b 20 2a 2f 0a 2b 0a 2b 76 6f 69 64 0a 2b 54  .+ */.+.+void.+T
37f0: 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67 65  clpThreadStorage
3800: 55 6e 6c 6f 63 6b 28 29 0a 2b 7b 0a 2b 20 20 20  Unlock().+{.+   
3810: 20 4c 65 61 76 65 43 72 69 74 69 63 61 6c 53 65   LeaveCriticalSe
3820: 63 74 69 6f 6e 28 26 74 68 72 65 61 64 53 74 6f  ction(&threadSto
3830: 72 61 67 65 4c 6f 63 6b 29 3b 0a 2b 7d 0a 2b 0c  rageLock);.+}.+.
3840: 0a 2b 2f 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d 2d 2d  .+/*.+ *--------
3850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b  --------------.+
3890: 20 2a 0a 20 20 2a 20 54 63 6c 5f 47 65 74 41 6c   *.  * Tcl_GetAl
38a0: 6c 6f 63 4d 75 74 65 78 0a 20 20 2a 0a 20 20 2a  locMutex.  *.  *
38b0: 09 54 68 69 73 20 70 72 6f 63 65 64 75 72 65 20  .This procedure 
38c0: 72 65 74 75 72 6e 73 20 61 20 70 6f 69 6e 74 65  returns a pointe
38d0: 72 20 74 6f 20 61 20 73 74 61 74 69 63 61 6c 6c  r to a staticall
38e0: 79 20 69 6e 69 74 69 61 6c 69 7a 65 64 0a 40 40  y initialized.@@
38f0: 20 2d 35 31 31 2c 36 20 2b 36 38 39 2c 33 30 34   -511,6 +689,304
3900: 20 40 40 0a 20 2f 2a 0a 20 20 2a 2d 2d 2d 2d 2d   @@. /*.  *-----
3910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3920: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3950: 2d 0a 20 20 2a 0a 2b 20 2a 20 41 6c 6c 6f 63 54  -.  *.+ * AllocT
3960: 68 72 65 61 64 53 74 6f 72 61 67 65 45 6e 74 72  hreadStorageEntr
3970: 79 20 2d 2d 0a 2b 20 2a 0a 2b 20 2a 09 41 6c 6c  y --.+ *.+ *.All
3980: 6f 63 61 74 65 20 73 70 61 63 65 20 66 6f 72 20  ocate space for 
3990: 61 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20  a Tcl_HashEntry 
39a0: 75 73 69 6e 67 20 54 63 6c 70 53 79 73 41 6c 6c  using TclpSysAll
39b0: 6f 63 20 28 6e 6f 74 20 63 6b 61 6c 6c 6f 63 29  oc (not ckalloc)
39c0: 2e 0a 2b 20 2a 20 20 20 20 20 20 57 65 20 64 6f  ..+ *      We do
39d0: 20 74 68 69 73 20 62 65 63 61 75 73 65 20 74 68   this because th
39e0: 65 20 74 68 72 65 61 64 65 64 20 6d 65 6d 6f 72  e threaded memor
39f0: 79 20 61 6c 6c 6f 63 61 74 6f 72 20 75 73 65 73  y allocator uses
3a00: 20 74 68 65 20 74 68 72 65 61 64 0a 2b 20 2a 20   the thread.+ * 
3a10: 20 20 20 20 20 73 74 6f 72 61 67 65 20 68 61 73       storage has
3a20: 68 20 74 61 62 6c 65 73 2e 0a 2b 20 2a 0a 2b 20  h tables..+ *.+ 
3a30: 2a 20 52 65 73 75 6c 74 73 3a 0a 2b 20 2a 09 54  * Results:.+ *.T
3a40: 68 65 20 72 65 74 75 72 6e 20 76 61 6c 75 65 20  he return value 
3a50: 69 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20  is a pointer to 
3a60: 74 68 65 20 63 72 65 61 74 65 64 20 65 6e 74 72  the created entr
3a70: 79 2e 0a 2b 20 2a 0a 2b 20 2a 20 53 69 64 65 20  y..+ *.+ * Side 
3a80: 65 66 66 65 63 74 73 3a 0a 2b 20 2a 09 4e 6f 6e  effects:.+ *.Non
3a90: 65 2e 0a 2b 20 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d  e..+ *.+ *------
3aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3ae0: 0a 2b 20 2a 2f 0a 2b 0a 2b 73 74 61 74 69 63 20  .+ */.+.+static 
3af0: 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 2a 0a  Tcl_HashEntry *.
3b00: 2b 41 6c 6c 6f 63 54 68 72 65 61 64 53 74 6f 72  +AllocThreadStor
3b10: 61 67 65 45 6e 74 72 79 28 74 61 62 6c 65 50 74  ageEntry(tablePt
3b20: 72 2c 20 6b 65 79 50 74 72 29 0a 2b 20 20 20 20  r, keyPtr).+    
3b30: 54 63 6c 5f 48 61 73 68 54 61 62 6c 65 20 2a 74  Tcl_HashTable *t
3b40: 61 62 6c 65 50 74 72 3b 09 2f 2a 20 48 61 73 68  ablePtr;./* Hash
3b50: 20 74 61 62 6c 65 2e 20 2a 2f 0a 2b 20 20 20 20   table. */.+    
3b60: 56 4f 49 44 20 2a 6b 65 79 50 74 72 3b 09 09 2f  VOID *keyPtr;../
3b70: 2a 20 4b 65 79 20 74 6f 20 73 74 6f 72 65 20 69  * Key to store i
3b80: 6e 20 74 68 65 20 68 61 73 68 20 74 61 62 6c 65  n the hash table
3b90: 20 65 6e 74 72 79 2e 20 2a 2f 0a 2b 7b 0a 2b 20   entry. */.+{.+ 
3ba0: 20 20 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79     Tcl_HashEntry
3bb0: 20 2a 68 50 74 72 3b 0a 2b 0a 2b 20 20 20 20 68   *hPtr;.+.+    h
3bc0: 50 74 72 20 3d 20 28 54 63 6c 5f 48 61 73 68 45  Ptr = (Tcl_HashE
3bd0: 6e 74 72 79 20 2a 29 54 63 6c 70 53 79 73 41 6c  ntry *)TclpSysAl
3be0: 6c 6f 63 28 73 69 7a 65 6f 66 28 54 63 6c 5f 48  loc(sizeof(Tcl_H
3bf0: 61 73 68 45 6e 74 72 79 29 2c 20 30 29 3b 0a 2b  ashEntry), 0);.+
3c00: 20 20 20 20 68 50 74 72 2d 3e 6b 65 79 2e 6f 6e      hPtr->key.on
3c10: 65 57 6f 72 64 56 61 6c 75 65 20 3d 20 28 63 68  eWordValue = (ch
3c20: 61 72 20 2a 29 6b 65 79 50 74 72 3b 0a 2b 0a 2b  ar *)keyPtr;.+.+
3c30: 20 20 20 20 72 65 74 75 72 6e 20 68 50 74 72 3b      return hPtr;
3c40: 0a 2b 7d 0a 2b 0c 0a 2b 2f 2a 0a 2b 20 2a 2d 2d  .+}.+..+/*.+ *--
3c50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c90: 2d 2d 2d 2d 0a 2b 20 2a 0a 2b 20 2a 20 46 72 65  ----.+ *.+ * Fre
3ca0: 65 54 68 72 65 61 64 53 74 6f 72 61 67 65 45 6e  eThreadStorageEn
3cb0: 74 72 79 20 2d 2d 0a 2b 20 2a 0a 2b 20 2a 09 46  try --.+ *.+ *.F
3cc0: 72 65 65 73 20 73 70 61 63 65 20 66 6f 72 20 61  rees space for a
3cd0: 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 75   Tcl_HashEntry u
3ce0: 73 69 6e 67 20 54 63 6c 70 53 79 73 46 72 65 65  sing TclpSysFree
3cf0: 20 28 6e 6f 74 20 63 6b 66 72 65 65 29 2e 0a 2b   (not ckfree)..+
3d00: 20 2a 20 20 20 20 20 20 57 65 20 64 6f 20 74 68   *      We do th
3d10: 69 73 20 62 65 63 61 75 73 65 20 74 68 65 20 74  is because the t
3d20: 68 72 65 61 64 65 64 20 6d 65 6d 6f 72 79 20 61  hreaded memory a
3d30: 6c 6c 6f 63 61 74 6f 72 20 75 73 65 73 20 74 68  llocator uses th
3d40: 65 20 74 68 72 65 61 64 0a 2b 20 2a 20 20 20 20  e thread.+ *    
3d50: 20 20 73 74 6f 72 61 67 65 20 68 61 73 68 20 74    storage hash t
3d60: 61 62 6c 65 73 2e 0a 2b 20 2a 0a 2b 20 2a 20 52  ables..+ *.+ * R
3d70: 65 73 75 6c 74 73 3a 0a 2b 20 2a 09 4e 6f 6e 65  esults:.+ *.None
3d80: 2e 0a 2b 20 2a 0a 2b 20 2a 20 53 69 64 65 20 65  ..+ *.+ * Side e
3d90: 66 66 65 63 74 73 3a 0a 2b 20 2a 09 4e 6f 6e 65  ffects:.+ *.None
3da0: 2e 0a 2b 20 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d 2d  ..+ *.+ *-------
3db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3de0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
3df0: 2b 20 2a 2f 0a 2b 0a 2b 73 74 61 74 69 63 20 76  + */.+.+static v
3e00: 6f 69 64 0a 2b 46 72 65 65 54 68 72 65 61 64 53  oid.+FreeThreadS
3e10: 74 6f 72 61 67 65 45 6e 74 72 79 28 68 50 74 72  torageEntry(hPtr
3e20: 29 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68 45  ).+    Tcl_HashE
3e30: 6e 74 72 79 20 2a 68 50 74 72 3b 09 2f 2a 20 48  ntry *hPtr;./* H
3e40: 61 73 68 20 65 6e 74 72 79 20 74 6f 20 66 72 65  ash entry to fre
3e50: 65 2e 20 2a 2f 0a 2b 7b 0a 2b 20 20 20 20 54 63  e. */.+{.+    Tc
3e60: 6c 70 53 79 73 46 72 65 65 28 28 63 68 61 72 20  lpSysFree((char 
3e70: 2a 29 68 50 74 72 29 3b 0a 2b 7d 0a 2b 0c 0a 2b  *)hPtr);.+}.+..+
3e80: 2f 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  /*.+ *----------
3e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3ea0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3ec0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a  ------------.+ *
3ed0: 0a 2b 20 2a 20 20 54 63 6c 70 54 68 72 65 61 64  .+ *  TclpThread
3ee0: 53 74 6f 72 61 67 65 50 72 69 6e 74 20 2d 2d 0a  StoragePrint --.
3ef0: 2b 20 2a 0a 2b 20 2a 20 20 20 20 20 20 54 68 69  + *.+ *      Thi
3f00: 73 20 70 72 6f 63 65 64 75 72 65 20 70 72 69 6e  s procedure prin
3f10: 74 73 20 6f 75 74 20 74 68 65 20 63 6f 6e 74 65  ts out the conte
3f20: 6e 74 73 20 6f 66 20 74 68 65 20 6d 61 73 74 65  nts of the maste
3f30: 72 20 74 68 72 65 61 64 0a 2b 20 2a 20 20 20 20  r thread.+ *    
3f40: 20 20 73 74 6f 72 61 67 65 20 68 61 73 68 20 74    storage hash t
3f50: 61 62 6c 65 2c 20 74 68 65 20 74 68 72 65 61 64  able, the thread
3f60: 20 73 74 6f 72 61 67 65 20 63 61 63 68 65 2c 20   storage cache, 
3f70: 61 6e 64 20 74 68 65 20 6e 65 78 74 20 6b 65 79  and the next key
3f80: 0a 2b 20 2a 20 20 20 20 20 20 76 61 6c 75 65 20  .+ *      value 
3f90: 74 6f 20 74 68 65 20 73 70 65 63 69 66 69 65 64  to the specified
3fa0: 20 66 69 6c 65 2e 0a 2b 20 2a 0a 2b 20 2a 20 52   file..+ *.+ * R
3fb0: 65 73 75 6c 74 73 3a 0a 2b 20 2a 20 20 20 20 20  esults:.+ *     
3fc0: 20 4e 6f 6e 65 2e 0a 2b 20 2a 0a 2b 20 2a 20 53   None..+ *.+ * S
3fd0: 69 64 65 20 65 66 66 65 63 74 73 3a 0a 2b 20 2a  ide effects:.+ *
3fe0: 20 20 20 20 20 20 4e 6f 6e 65 2e 0a 2b 20 2a 0a        None..+ *.
3ff0: 2b 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  + *-------------
4000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 2f 0a 2b  ---------.+ */.+
4040: 0a 2b 76 6f 69 64 0a 2b 54 63 6c 70 54 68 72 65  .+void.+TclpThre
4050: 61 64 53 74 6f 72 61 67 65 50 72 69 6e 74 28 6f  adStoragePrint(o
4060: 75 74 46 69 6c 65 2c 20 66 6c 61 67 73 29 0a 2b  utFile, flags).+
4070: 20 20 20 20 46 49 4c 45 20 2a 6f 75 74 46 69 6c      FILE *outFil
4080: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  e;              
4090: 2f 2a 20 54 68 65 20 66 69 6c 65 20 74 6f 20 70  /* The file to p
40a0: 72 69 6e 74 20 74 68 65 20 69 6e 66 6f 72 6d 61  rint the informa
40b0: 74 69 6f 6e 20 74 6f 2e 20 2a 2f 0a 2b 20 20 20  tion to. */.+   
40c0: 20 69 6e 74 20 66 6c 61 67 73 3b 20 20 20 20 20   int flags;     
40d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
40e0: 52 65 73 65 72 76 65 64 20 66 6f 72 20 66 75 74  Reserved for fut
40f0: 75 72 65 20 75 73 65 2e 20 2a 2f 0a 2b 7b 0a 2b  ure use. */.+{.+
4100: 20 20 20 20 54 63 6c 5f 48 61 73 68 45 6e 74 72      Tcl_HashEntr
4110: 79 20 2a 68 50 74 72 3b 0a 2b 20 20 20 20 54 63  y *hPtr;.+    Tc
4120: 6c 5f 48 61 73 68 53 65 61 72 63 68 20 73 65 61  l_HashSearch sea
4130: 72 63 68 3b 0a 2b 23 69 66 20 30 0a 2b 20 20 20  rch;.+#if 0.+   
4140: 20 2f 2a 20 50 6c 65 61 73 65 20 73 65 65 20 63   /* Please see c
4150: 6f 6d 6d 65 6e 74 20 72 65 67 61 72 64 69 6e 67  omment regarding
4160: 20 54 63 6c 5f 48 61 73 68 53 74 61 74 73 20 62   Tcl_HashStats b
4170: 65 6c 6f 77 2e 20 2a 2f 0a 2b 20 20 20 20 43 4f  elow. */.+    CO
4180: 4e 53 54 20 63 68 61 72 20 2a 73 74 61 74 73 3b  NST char *stats;
4190: 0a 2b 23 65 6e 64 69 66 0a 2b 20 20 20 20 69 6e  .+#endif.+    in
41a0: 74 20 68 65 61 64 65 72 3b 0a 2b 20 20 20 20 69  t header;.+    i
41b0: 6e 74 20 69 6e 64 65 78 3b 0a 2b 0a 2b 20 20 20  nt index;.+.+   
41c0: 20 53 54 4f 52 41 47 45 5f 4c 4f 43 4b 3b 0a 2b   STORAGE_LOCK;.+
41d0: 20 20 20 20 69 66 20 28 74 68 72 65 61 64 53 74      if (threadSt
41e0: 6f 72 61 67 65 48 61 73 68 54 61 62 6c 65 50 74  orageHashTablePt
41f0: 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20  r != NULL) {.+  
4200: 20 20 20 20 20 20 68 50 74 72 20 3d 20 54 63 6c        hPtr = Tcl
4210: 5f 46 69 72 73 74 48 61 73 68 45 6e 74 72 79 28  _FirstHashEntry(
4220: 74 68 72 65 61 64 53 74 6f 72 61 67 65 48 61 73  threadStorageHas
4230: 68 54 61 62 6c 65 50 74 72 2c 20 26 73 65 61 72  hTablePtr, &sear
4240: 63 68 29 3b 0a 2b 0a 2b 20 20 20 20 20 20 20 20  ch);.+.+        
4250: 69 66 20 28 68 50 74 72 20 21 3d 20 4e 55 4c 4c  if (hPtr != NULL
4260: 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20  ) {.+           
4270: 20 66 70 72 69 6e 74 66 28 6f 75 74 46 69 6c 65   fprintf(outFile
4280: 2c 20 22 6d 61 73 74 65 72 20 74 68 72 65 61 64  , "master thread
4290: 20 73 74 6f 72 61 67 65 20 68 61 73 68 20 74 61   storage hash ta
42a0: 62 6c 65 3a 5c 6e 22 29 3b 0a 2b 20 20 20 20 20  ble:\n");.+     
42b0: 20 20 20 20 20 20 20 66 6f 72 20 28 3b 20 68 50         for (; hP
42c0: 74 72 20 21 3d 20 4e 55 4c 4c 3b 20 68 50 74 72  tr != NULL; hPtr
42d0: 20 3d 20 54 63 6c 5f 4e 65 78 74 48 61 73 68 45   = Tcl_NextHashE
42e0: 6e 74 72 79 28 26 73 65 61 72 63 68 29 29 20 7b  ntry(&search)) {
42f0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .+              
4300: 20 20 66 70 72 69 6e 74 66 28 6f 75 74 46 69 6c    fprintf(outFil
4310: 65 2c 20 22 6d 61 73 74 65 72 20 65 6e 74 72 79  e, "master entry
4320: 20 70 74 72 20 30 78 25 30 38 6c 78 2c 20 74 68   ptr 0x%08lx, th
4330: 72 65 61 64 20 25 6c 64 2c 20 74 68 72 65 61 64  read %ld, thread
4340: 20 74 61 62 6c 65 20 70 74 72 20 30 78 25 30 38   table ptr 0x%08
4350: 6c 78 5c 6e 22 2c 0a 2b 20 20 20 20 20 20 20 20  lx\n",.+        
4360: 20 20 20 20 20 20 20 20 20 20 20 20 68 50 74 72              hPtr
4370: 2c 20 54 63 6c 5f 47 65 74 48 61 73 68 4b 65 79  , Tcl_GetHashKey
4380: 28 74 68 72 65 61 64 53 74 6f 72 61 67 65 48 61  (threadStorageHa
4390: 73 68 54 61 62 6c 65 50 74 72 2c 20 68 50 74 72  shTablePtr, hPtr
43a0: 29 2c 20 54 63 6c 5f 47 65 74 48 61 73 68 56 61  ), Tcl_GetHashVa
43b0: 6c 75 65 28 68 50 74 72 29 29 3b 0a 2b 20 20 20  lue(hPtr));.+   
43c0: 20 20 20 20 20 20 20 20 20 7d 0a 2b 20 20 20 20           }.+    
43d0: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20      } else {.+  
43e0: 20 20 20 20 20 20 20 20 20 20 66 70 72 69 6e 74            fprint
43f0: 66 28 6f 75 74 46 69 6c 65 2c 20 22 6d 61 73 74  f(outFile, "mast
4400: 65 72 20 74 68 72 65 61 64 20 73 74 6f 72 61 67  er thread storag
4410: 65 20 68 61 73 68 20 74 61 62 6c 65 20 68 61 73  e hash table has
4420: 20 6e 6f 20 65 6e 74 72 69 65 73 5c 6e 22 29 3b   no entries\n");
4430: 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 20 20 20  .+        }.+   
4440: 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20   } else {.+     
4450: 20 20 20 66 70 72 69 6e 74 66 28 6f 75 74 46 69     fprintf(outFi
4460: 6c 65 2c 20 22 6d 61 73 74 65 72 20 74 68 72 65  le, "master thre
4470: 61 64 20 73 74 6f 72 61 67 65 20 68 61 73 68 20  ad storage hash 
4480: 74 61 62 6c 65 20 6e 6f 74 20 69 6e 69 74 69 61  table not initia
4490: 6c 69 7a 65 64 5c 6e 22 29 3b 0a 2b 20 20 20 20  lized\n");.+    
44a0: 7d 0a 2b 0a 2b 20 20 20 20 68 65 61 64 65 72 20  }.+.+    header 
44b0: 3d 20 30 3b 20 2f 2a 20 77 65 20 68 61 76 65 20  = 0; /* we have 
44c0: 6e 6f 74 20 6f 75 74 70 75 74 20 74 68 65 20 68  not output the h
44d0: 65 61 64 65 72 20 79 65 74 2e 20 2a 2f 0a 2b 20  eader yet. */.+ 
44e0: 20 20 20 66 6f 72 20 28 69 6e 64 65 78 20 3d 20     for (index = 
44f0: 30 3b 20 69 6e 64 65 78 20 3c 20 53 54 4f 52 41  0; index < STORA
4500: 47 45 5f 43 41 43 48 45 5f 53 4c 4f 54 53 3b 20  GE_CACHE_SLOTS; 
4510: 69 6e 64 65 78 2b 2b 29 20 7b 0a 2b 20 20 20 20  index++) {.+    
4520: 20 20 20 20 69 66 20 28 74 68 72 65 61 64 53 74      if (threadSt
4530: 6f 72 61 67 65 43 61 63 68 65 5b 69 6e 64 65 78  orageCache[index
4540: 5d 2e 69 64 20 21 3d 20 53 54 4f 52 41 47 45 5f  ].id != STORAGE_
4550: 49 4e 56 41 4c 49 44 5f 54 48 52 45 41 44 29 20  INVALID_THREAD) 
4560: 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 69  {.+            i
4570: 66 20 28 21 68 65 61 64 65 72 29 20 7b 0a 2b 20  f (!header) {.+ 
4580: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 66                 f
4590: 70 72 69 6e 74 66 28 6f 75 74 46 69 6c 65 2c 20  printf(outFile, 
45a0: 22 74 68 72 65 61 64 20 73 74 6f 72 61 67 65 20  "thread storage 
45b0: 63 61 63 68 65 20 28 25 64 20 74 6f 74 61 6c 20  cache (%d total 
45c0: 73 6c 6f 74 73 29 3a 5c 6e 22 2c 20 53 54 4f 52  slots):\n", STOR
45d0: 41 47 45 5f 43 41 43 48 45 5f 53 4c 4f 54 53 29  AGE_CACHE_SLOTS)
45e0: 3b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  ;.+             
45f0: 20 20 20 68 65 61 64 65 72 20 3d 20 31 3b 0a 2b     header = 1;.+
4600: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b 0a              }.+.
4610: 2b 20 20 20 20 20 20 20 20 20 20 20 20 66 70 72  +            fpr
4620: 69 6e 74 66 28 6f 75 74 46 69 6c 65 2c 20 22 73  intf(outFile, "s
4630: 6c 6f 74 20 25 64 2c 20 74 68 72 65 61 64 20 25  lot %d, thread %
4640: 64 2c 20 74 68 72 65 61 64 20 74 61 62 6c 65 20  d, thread table 
4650: 70 74 72 20 30 78 25 30 38 6c 78 5c 6e 22 2c 0a  ptr 0x%08lx\n",.
4660: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
4670: 20 69 6e 64 65 78 2c 20 74 68 72 65 61 64 53 74   index, threadSt
4680: 6f 72 61 67 65 43 61 63 68 65 5b 69 6e 64 65 78  orageCache[index
4690: 5d 2e 69 64 2c 0a 2b 20 20 20 20 20 20 20 20 20  ].id,.+         
46a0: 20 20 20 20 20 20 20 74 68 72 65 61 64 53 74 6f         threadSto
46b0: 72 61 67 65 43 61 63 68 65 5b 69 6e 64 65 78 5d  rageCache[index]
46c0: 2e 68 61 73 68 54 61 62 6c 65 50 74 72 29 3b 0a  .hashTablePtr);.
46d0: 2b 23 69 66 20 30 0a 2b 20 20 20 20 20 20 20 20  +#if 0.+        
46e0: 20 20 20 20 2f 2a 0a 2b 20 20 20 20 20 20 20 20      /*.+        
46f0: 20 20 20 20 20 2a 20 43 75 72 72 65 6e 74 6c 79       * Currently
4700: 20 64 69 73 61 62 6c 65 64 20 64 75 65 20 74 6f   disabled due to
4710: 20 54 63 6c 5f 48 61 73 68 53 74 61 74 73 20 75   Tcl_HashStats u
4720: 73 65 20 6f 66 20 63 6b 61 6c 6c 6f 63 20 61 6e  se of ckalloc an
4730: 64 20 63 6b 66 72 65 65 2e 0a 2b 20 20 20 20 20  d ckfree..+     
4740: 20 20 20 20 20 20 20 20 2a 2f 0a 2b 20 20 20 20          */.+    
4750: 20 20 20 20 20 20 20 20 69 66 20 28 74 68 72 65          if (thre
4760: 61 64 53 74 6f 72 61 67 65 43 61 63 68 65 5b 69  adStorageCache[i
4770: 6e 64 65 78 5d 2e 68 61 73 68 54 61 62 6c 65 50  ndex].hashTableP
4780: 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20  tr != NULL) {.+ 
4790: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73                 s
47a0: 74 61 74 73 20 3d 20 54 63 6c 5f 48 61 73 68 53  tats = Tcl_HashS
47b0: 74 61 74 73 28 74 68 72 65 61 64 53 74 6f 72 61  tats(threadStora
47c0: 67 65 43 61 63 68 65 5b 69 6e 64 65 78 5d 2e 68  geCache[index].h
47d0: 61 73 68 54 61 62 6c 65 50 74 72 29 3b 0a 2b 20  ashTablePtr);.+ 
47e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69                 i
47f0: 66 20 28 73 74 61 74 73 20 21 3d 20 4e 55 4c 4c  f (stats != NULL
4800: 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20  ) {.+           
4810: 20 20 20 20 20 20 20 20 20 66 70 72 69 6e 74 66           fprintf
4820: 28 6f 75 74 46 69 6c 65 2c 20 22 25 73 5c 6e 22  (outFile, "%s\n"
4830: 2c 20 73 74 61 74 73 29 3b 0a 2b 20 20 20 20 20  , stats);.+     
4840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63                 c
4850: 6b 66 72 65 65 28 28 76 6f 69 64 20 2a 29 73 74  kfree((void *)st
4860: 61 74 73 29 3b 0a 2b 20 20 20 20 20 20 20 20 20  ats);.+         
4870: 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a         } else {.
4880: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
4890: 20 20 20 20 20 66 70 72 69 6e 74 66 28 6f 75 74       fprintf(out
48a0: 46 69 6c 65 2c 20 22 63 6f 75 6c 64 20 6e 6f 74  File, "could not
48b0: 20 67 65 74 20 74 61 62 6c 65 20 73 74 61 74 69   get table stati
48c0: 73 74 69 63 73 20 66 6f 72 20 73 6c 6f 74 20 25  stics for slot %
48d0: 64 5c 6e 22 2c 20 69 6e 64 65 78 29 3b 0a 2b 20  d\n", index);.+ 
48e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d                 }
48f0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a  .+            }.
4900: 2b 23 65 6e 64 69 66 0a 2b 20 20 20 20 20 20 20  +#endif.+       
4910: 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20   } else {.+     
4920: 20 20 20 20 20 20 20 2f 2a 20 66 70 72 69 6e 74         /* fprint
4930: 66 28 6f 75 74 46 69 6c 65 2c 20 22 63 61 63 68  f(outFile, "cach
4940: 65 20 73 6c 6f 74 20 25 64 20 6e 6f 74 20 75 73  e slot %d not us
4950: 65 64 5c 6e 22 2c 20 69 6e 64 65 78 29 3b 20 2a  ed\n", index); *
4960: 2f 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 20 20  /.+        }.+  
4970: 20 20 7d 0a 2b 0a 2b 20 20 20 20 69 66 20 28 21    }.+.+    if (!
4980: 68 65 61 64 65 72 29 20 7b 0a 2b 20 20 20 20 20  header) {.+     
4990: 20 20 20 66 70 72 69 6e 74 66 28 6f 75 74 46 69     fprintf(outFi
49a0: 6c 65 2c 20 22 74 68 72 65 61 64 20 73 74 6f 72  le, "thread stor
49b0: 61 67 65 20 63 61 63 68 65 20 69 73 20 65 6d 70  age cache is emp
49c0: 74 79 20 28 25 64 20 74 6f 74 61 6c 20 73 6c 6f  ty (%d total slo
49d0: 74 73 29 5c 6e 22 2c 20 53 54 4f 52 41 47 45 5f  ts)\n", STORAGE_
49e0: 43 41 43 48 45 5f 53 4c 4f 54 53 29 3b 0a 2b 20  CACHE_SLOTS);.+ 
49f0: 20 20 20 20 20 20 20 68 65 61 64 65 72 20 3d 20         header = 
4a00: 31 3b 0a 2b 20 20 20 20 7d 0a 2b 0a 2b 20 20 20  1;.+    }.+.+   
4a10: 20 2f 2a 20 53 68 6f 77 20 74 68 65 20 6e 65 78   /* Show the nex
4a20: 74 20 64 61 74 61 20 6b 65 79 20 76 61 6c 75 65  t data key value
4a30: 2e 20 2a 2f 0a 2b 20 20 20 20 66 70 72 69 6e 74  . */.+    fprint
4a40: 66 28 6f 75 74 46 69 6c 65 2c 20 22 6e 65 78 74  f(outFile, "next
4a50: 20 64 61 74 61 20 6b 65 79 20 76 61 6c 75 65 20   data key value 
4a60: 69 73 3a 20 25 6c 64 5c 6e 22 2c 20 6e 65 78 74  is: %ld\n", next
4a70: 54 68 72 65 61 64 53 74 6f 72 61 67 65 4b 65 79  ThreadStorageKey
4a80: 29 3b 0a 2b 20 20 20 20 53 54 4f 52 41 47 45 5f  );.+    STORAGE_
4a90: 55 4e 4c 4f 43 4b 3b 0a 2b 7d 0a 2b 0c 0a 2b 2f  UNLOCK;.+}.+..+/
4aa0: 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *.+ *-----------
4ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 0a  -----------.+ *.
4af0: 2b 20 2a 20 54 63 6c 70 54 68 72 65 61 64 53 74  + * TclpThreadSt
4b00: 6f 72 61 67 65 47 65 74 48 61 73 68 54 61 62 6c  orageGetHashTabl
4b10: 65 20 2d 2d 0a 2b 20 2a 0a 2b 20 2a 20 20 20 20  e --.+ *.+ *    
4b20: 20 20 54 68 69 73 20 70 72 6f 63 65 64 75 72 65    This procedure
4b30: 20 72 65 74 75 72 6e 73 20 61 20 68 61 73 68 20   returns a hash 
4b40: 74 61 62 6c 65 20 70 6f 69 6e 74 65 72 20 74 6f  table pointer to
4b50: 20 62 65 20 75 73 65 64 20 66 6f 72 20 74 68 72   be used for thr
4b60: 65 61 64 0a 2b 20 2a 20 20 20 20 20 20 73 74 6f  ead.+ *      sto
4b70: 72 61 67 65 20 66 6f 72 20 74 68 65 20 73 70 65  rage for the spe
4b80: 63 69 66 69 65 64 20 74 68 72 65 61 64 2e 0a 2b  cified thread..+
4b90: 20 2a 0a 2b 20 2a 20 52 65 73 75 6c 74 73 3a 0a   *.+ * Results:.
4ba0: 2b 20 2a 20 20 20 20 20 20 41 20 68 61 73 68 20  + *      A hash 
4bb0: 74 61 62 6c 65 20 70 6f 69 6e 74 65 72 20 66 6f  table pointer fo
4bc0: 72 20 74 68 65 20 73 70 65 63 69 66 69 65 64 20  r the specified 
4bd0: 74 68 72 65 61 64 2c 20 6f 72 20 4e 55 4c 4c 0a  thread, or NULL.
4be0: 2b 20 2a 20 20 20 20 20 20 69 66 20 74 68 65 20  + *      if the 
4bf0: 68 61 73 68 20 74 61 62 6c 65 20 68 61 73 20 6e  hash table has n
4c00: 6f 74 20 62 65 65 6e 20 63 72 65 61 74 65 64 20  ot been created 
4c10: 79 65 74 2e 0a 2b 20 2a 0a 2b 20 2a 20 53 69 64  yet..+ *.+ * Sid
4c20: 65 20 65 66 66 65 63 74 73 3a 0a 2b 20 2a 20 20  e effects:.+ *  
4c30: 20 20 20 20 4d 61 79 20 63 68 61 6e 67 65 20 61      May change a
4c40: 6e 20 65 6e 74 72 79 20 69 6e 20 74 68 65 20 6d  n entry in the m
4c50: 61 73 74 65 72 20 74 68 72 65 61 64 20 73 74 6f  aster thread sto
4c60: 72 61 67 65 20 63 61 63 68 65 20 74 6f 20 70 6f  rage cache to po
4c70: 69 6e 74 0a 2b 20 2a 20 20 20 20 20 20 74 6f 20  int.+ *      to 
4c80: 74 68 65 20 73 70 65 63 69 66 69 65 64 20 74 68  the specified th
4c90: 72 65 61 64 20 61 6e 64 20 69 74 27 73 20 61 73  read and it's as
4ca0: 73 6f 63 69 61 74 65 64 20 68 61 73 68 20 74 61  sociated hash ta
4cb0: 62 6c 65 2e 0a 2b 20 2a 0a 2b 20 2a 2d 2d 2d 2d  ble..+ *.+ *----
4cc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4cd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4ce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4cf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4d00: 2d 2d 0a 2b 20 2a 2f 0a 2b 0a 2b 54 63 6c 5f 48  --.+ */.+.+Tcl_H
4d10: 61 73 68 54 61 62 6c 65 20 2a 0a 2b 54 63 6c 70  ashTable *.+Tclp
4d20: 54 68 72 65 61 64 53 74 6f 72 61 67 65 47 65 74  ThreadStorageGet
4d30: 48 61 73 68 54 61 62 6c 65 28 69 64 29 0a 2b 20  HashTable(id).+ 
4d40: 20 20 20 54 63 6c 5f 54 68 72 65 61 64 49 64 20     Tcl_ThreadId 
4d50: 69 64 3b 20 20 20 20 2f 2a 20 49 64 20 6f 66 20  id;    /* Id of 
4d60: 74 68 65 20 74 68 72 65 61 64 20 74 6f 20 67 65  the thread to ge
4d70: 74 20 74 68 65 20 68 61 73 68 20 74 61 62 6c 65  t the hash table
4d80: 20 66 6f 72 20 2a 2f 0a 2b 7b 0a 2b 20 20 20 20   for */.+{.+    
4d90: 69 6e 74 20 69 6e 64 65 78 20 3d 20 28 44 57 4f  int index = (DWO
4da0: 52 44 29 69 64 20 25 20 53 54 4f 52 41 47 45 5f  RD)id % STORAGE_
4db0: 43 41 43 48 45 5f 53 4c 4f 54 53 3b 0a 2b 20 20  CACHE_SLOTS;.+  
4dc0: 20 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20    Tcl_HashEntry 
4dd0: 2a 68 50 74 72 3b 0a 2b 0a 2b 20 20 20 20 2f 2a  *hPtr;.+.+    /*
4de0: 0a 2b 20 20 20 20 20 2a 20 49 74 27 73 20 69 6d  .+     * It's im
4df0: 70 6f 72 74 61 6e 74 20 74 68 61 74 20 77 65 20  portant that we 
4e00: 70 69 63 6b 20 75 70 20 74 68 65 20 68 61 73 68  pick up the hash
4e10: 20 74 61 62 6c 65 20 70 6f 69 6e 74 65 72 20 42   table pointer B
4e20: 45 46 4f 52 45 0a 2b 20 20 20 20 20 2a 20 63 6f  EFORE.+     * co
4e30: 6d 70 61 72 69 6e 67 20 74 68 72 65 61 64 20 49  mparing thread I
4e40: 64 20 69 6e 20 63 61 73 65 20 61 6e 6f 74 68 65  d in case anothe
4e50: 72 20 74 68 72 65 61 64 20 69 73 20 69 6e 20 74  r thread is in t
4e60: 68 65 20 63 72 69 74 69 63 61 6c 0a 2b 20 20 20  he critical.+   
4e70: 20 20 2a 20 72 65 67 69 6f 6e 20 63 68 61 6e 67    * region chang
4e80: 69 6e 67 20 74 68 69 6e 67 73 20 6f 75 74 20 66  ing things out f
4e90: 72 6f 6d 20 75 6e 64 65 72 20 79 6f 75 2e 0a 2b  rom under you..+
4ea0: 20 20 20 20 20 2a 2f 0a 2b 20 20 20 20 54 63 6c       */.+    Tcl
4eb0: 5f 48 61 73 68 54 61 62 6c 65 20 2a 68 61 73 68  _HashTable *hash
4ec0: 54 61 62 6c 65 50 74 72 20 3d 20 74 68 72 65 61  TablePtr = threa
4ed0: 64 53 74 6f 72 61 67 65 43 61 63 68 65 5b 69 6e  dStorageCache[in
4ee0: 64 65 78 5d 2e 68 61 73 68 54 61 62 6c 65 50 74  dex].hashTablePt
4ef0: 72 3b 0a 2b 0a 2b 20 20 20 20 69 66 20 28 74 68  r;.+.+    if (th
4f00: 72 65 61 64 53 74 6f 72 61 67 65 43 61 63 68 65  readStorageCache
4f10: 5b 69 6e 64 65 78 5d 2e 69 64 20 21 3d 20 69 64  [index].id != id
4f20: 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 53 54 4f  ) {.+        STO
4f30: 52 41 47 45 5f 4c 4f 43 4b 3b 0a 2b 20 20 20 20  RAGE_LOCK;.+    
4f40: 20 20 20 20 69 66 20 28 74 68 72 65 61 64 53 74      if (threadSt
4f50: 6f 72 61 67 65 48 61 73 68 54 61 62 6c 65 50 74  orageHashTablePt
4f60: 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20  r != NULL) {.+  
4f70: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 74 27            /* it'
4f80: 73 20 6e 6f 74 20 69 6e 20 74 68 65 20 63 61 63  s not in the cac
4f90: 68 65 2c 20 73 6f 20 77 65 20 6c 6f 6f 6b 20 69  he, so we look i
4fa0: 74 20 75 70 2e 2e 2e 20 2a 2f 0a 2b 20 20 20 20  t up... */.+    
4fb0: 20 20 20 20 20 20 20 20 68 50 74 72 20 3d 20 54          hPtr = T
4fc0: 63 6c 5f 46 69 6e 64 48 61 73 68 45 6e 74 72 79  cl_FindHashEntry
4fd0: 28 74 68 72 65 61 64 53 74 6f 72 61 67 65 48 61  (threadStorageHa
4fe0: 73 68 54 61 62 6c 65 50 74 72 2c 20 28 63 68 61  shTablePtr, (cha
4ff0: 72 20 2a 29 69 64 29 3b 0a 2b 0a 2b 20 20 20 20  r *)id);.+.+    
5000: 20 20 20 20 20 20 20 20 69 66 20 28 68 50 74 72          if (hPtr
5010: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20   != NULL) {.+   
5020: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20               /* 
5030: 77 65 20 66 6f 75 6e 64 20 69 74 2c 20 65 78 74  we found it, ext
5040: 72 61 63 74 20 74 68 65 20 68 61 73 68 20 74 61  ract the hash ta
5050: 62 6c 65 20 70 6f 69 6e 74 65 72 2e 20 2a 2f 0a  ble pointer. */.
5060: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
5070: 20 68 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20   hashTablePtr = 
5080: 54 63 6c 5f 47 65 74 48 61 73 68 56 61 6c 75 65  Tcl_GetHashValue
5090: 28 68 50 74 72 29 3b 0a 2b 20 20 20 20 20 20 20  (hPtr);.+       
50a0: 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20       } else {.+ 
50b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f                 /
50c0: 2a 20 74 68 65 20 74 68 72 65 61 64 20 73 70 65  * the thread spe
50d0: 63 69 66 69 63 20 68 61 73 68 20 74 61 62 6c 65  cific hash table
50e0: 20 69 73 20 6e 6f 74 20 66 6f 75 6e 64 2e 20 2a   is not found. *
50f0: 2f 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  /.+             
5100: 20 20 20 68 61 73 68 54 61 62 6c 65 50 74 72 20     hashTablePtr 
5110: 3d 20 4e 55 4c 4c 3b 0a 2b 20 20 20 20 20 20 20  = NULL;.+       
5120: 20 20 20 20 20 7d 0a 2b 20 20 20 20 20 20 20 20       }.+        
5130: 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20  } else {.+      
5140: 20 20 20 20 20 20 2f 2a 20 77 65 20 63 61 6e 6e        /* we cann
5150: 6f 74 20 6c 6f 6f 6b 20 69 74 20 75 70 2c 20 74  ot look it up, t
5160: 68 65 20 6d 61 73 74 65 72 20 68 61 73 68 20 74  he master hash t
5170: 61 62 6c 65 20 68 61 73 20 6e 6f 74 20 62 65 65  able has not bee
5180: 6e 20 69 6e 69 74 69 61 6c 69 7a 65 64 2e 20 2a  n initialized. *
5190: 2f 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 68  /.+            h
51a0: 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20 4e 55  ashTablePtr = NU
51b0: 4c 4c 3b 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b  LL;.+        }.+
51c0: 0a 2b 20 20 20 20 20 20 20 20 2f 2a 20 66 6f 72  .+        /* for
51d0: 20 74 68 72 65 61 64 73 20 74 68 61 74 20 68 61   threads that ha
51e0: 76 65 20 6e 6f 74 20 63 72 65 61 74 65 64 20 74  ve not created t
51f0: 68 65 69 72 20 68 61 73 68 20 74 61 62 6c 65 20  heir hash table 
5200: 79 65 74 2c 20 77 65 20 6e 65 65 64 20 74 6f 20  yet, we need to 
5210: 73 6b 69 70 0a 2b 20 20 20 20 20 20 20 20 20 20  skip.+          
5220: 20 70 75 74 74 69 6e 67 20 74 68 61 74 20 74 68   putting that th
5230: 72 65 61 64 20 69 6e 20 74 68 65 20 63 61 63 68  read in the cach
5240: 65 2e 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 69  e. */.+        i
5250: 66 20 28 68 61 73 68 54 61 62 6c 65 50 74 72 20  f (hashTablePtr 
5260: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20  != NULL) {.+    
5270: 20 20 20 20 20 20 20 20 2f 2a 20 6e 6f 77 2c 20          /* now, 
5280: 77 65 20 70 75 74 20 69 74 20 69 6e 20 74 68 65  we put it in the
5290: 20 63 61 63 68 65 20 73 69 6e 63 65 20 69 74 20   cache since it 
52a0: 69 73 20 68 69 67 68 6c 79 20 6c 69 6b 65 6c 79  is highly likely
52b0: 20 69 74 20 77 69 6c 6c 0a 2b 20 20 20 20 20 20   it will.+      
52c0: 20 20 20 20 20 20 20 20 20 62 65 20 6e 65 65 64           be need
52d0: 65 64 20 61 67 61 69 6e 20 73 68 6f 72 74 6c 79  ed again shortly
52e0: 2e 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 20 20  . */.+          
52f0: 20 20 74 68 72 65 61 64 53 74 6f 72 61 67 65 43    threadStorageC
5300: 61 63 68 65 5b 69 6e 64 65 78 5d 2e 69 64 20 3d  ache[index].id =
5310: 20 69 64 3b 0a 2b 20 20 20 20 20 20 20 20 20 20   id;.+          
5320: 20 20 74 68 72 65 61 64 53 74 6f 72 61 67 65 43    threadStorageC
5330: 61 63 68 65 5b 69 6e 64 65 78 5d 2e 68 61 73 68  ache[index].hash
5340: 54 61 62 6c 65 50 74 72 20 3d 20 68 61 73 68 54  TablePtr = hashT
5350: 61 62 6c 65 50 74 72 3b 0a 2b 20 20 20 20 20 20  ablePtr;.+      
5360: 20 20 7d 0a 2b 20 20 20 20 20 20 20 20 53 54 4f    }.+        STO
5370: 52 41 47 45 5f 55 4e 4c 4f 43 4b 3b 0a 2b 20 20  RAGE_UNLOCK;.+  
5380: 20 20 7d 0a 2b 0a 2b 20 20 20 20 72 65 74 75 72    }.+.+    retur
5390: 6e 20 68 61 73 68 54 61 62 6c 65 50 74 72 3b 0a  n hashTablePtr;.
53a0: 2b 7d 0a 2b 0c 0a 2b 2f 2a 0a 2b 20 2a 2d 2d 2d  +}.+..+/*.+ *---
53b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
53c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
53d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
53e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
53f0: 2d 2d 2d 0a 2b 20 2a 0a 2b 20 2a 20 54 63 6c 70  ---.+ *.+ * Tclp
5400: 54 68 72 65 61 64 53 74 6f 72 61 67 65 49 6e 69  ThreadStorageIni
5410: 74 20 2d 2d 0a 2b 20 2a 0a 2b 20 2a 20 20 20 20  t --.+ *.+ *    
5420: 20 20 54 68 69 73 20 70 72 6f 63 65 64 75 72 65    This procedure
5430: 20 69 6e 69 74 69 61 6c 69 7a 65 73 20 61 20 74   initializes a t
5440: 68 72 65 61 64 20 73 70 65 63 69 66 69 63 20 68  hread specific h
5450: 61 73 68 20 74 61 62 6c 65 20 66 6f 72 20 74 68  ash table for th
5460: 65 0a 2b 20 2a 20 20 20 20 20 20 63 75 72 72 65  e.+ *      curre
5470: 6e 74 20 74 68 72 65 61 64 2e 20 49 74 20 6d 61  nt thread. It ma
5480: 79 20 61 6c 73 6f 20 69 6e 69 74 69 61 6c 69 7a  y also initializ
5490: 65 20 74 68 65 20 6d 61 73 74 65 72 20 68 61 73  e the master has
54a0: 68 20 74 61 62 6c 65 20 77 68 69 63 68 0a 2b 20  h table which.+ 
54b0: 2a 20 20 20 20 20 20 73 74 6f 72 65 73 20 61 6c  *      stores al
54c0: 6c 20 74 68 65 20 74 68 72 65 61 64 20 73 70 65  l the thread spe
54d0: 63 69 66 69 63 20 68 61 73 68 20 74 61 62 6c 65  cific hash table
54e0: 73 2e 0a 2b 20 2a 0a 2b 20 2a 20 52 65 73 75 6c  s..+ *.+ * Resul
54f0: 74 73 3a 0a 2b 20 2a 20 20 20 20 20 20 41 20 68  ts:.+ *      A h
5500: 61 73 68 20 74 61 62 6c 65 20 70 6f 69 6e 74 65  ash table pointe
5510: 72 20 66 6f 72 20 74 68 65 20 73 70 65 63 69 66  r for the specif
5520: 69 65 64 20 74 68 72 65 61 64 2c 20 6f 72 20 4e  ied thread, or N
5530: 55 4c 4c 20 69 66 20 77 65 20 61 72 65 0a 2b 20  ULL if we are.+ 
5540: 2a 20 20 20 20 20 20 62 65 20 63 61 6c 6c 65 64  *      be called
5550: 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 74   to initialize t
5560: 68 65 20 6d 61 73 74 65 72 20 68 61 73 68 20 74  he master hash t
5570: 61 62 6c 65 20 6f 6e 6c 79 2e 0a 2b 20 2a 0a 2b  able only..+ *.+
5580: 20 2a 20 53 69 64 65 20 65 66 66 65 63 74 73 3a   * Side effects:
5590: 0a 2b 20 2a 20 20 20 20 20 20 54 68 65 20 74 68  .+ *      The th
55a0: 72 65 61 64 20 73 70 65 63 69 66 69 63 20 68 61  read specific ha
55b0: 73 68 20 74 61 62 6c 65 20 6d 61 79 20 62 65 20  sh table may be 
55c0: 69 6e 69 74 69 61 6c 69 7a 65 64 20 61 6e 64 20  initialized and 
55d0: 61 64 64 65 64 20 74 6f 20 74 68 65 0a 2b 20 2a  added to the.+ *
55e0: 20 20 20 20 20 20 6d 61 73 74 65 72 20 68 61 73        master has
55f0: 68 20 74 61 62 6c 65 2e 0a 2b 20 2a 0a 2b 20 2a  h table..+ *.+ *
5600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5610: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5620: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5630: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
5640: 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 2f 0a 2b 0a 2b 54  ------.+ */.+.+T
5650: 63 6c 5f 48 61 73 68 54 61 62 6c 65 20 2a 0a 2b  cl_HashTable *.+
5660: 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67  TclpThreadStorag
5670: 65 49 6e 69 74 28 69 64 29 0a 2b 20 20 20 20 54  eInit(id).+    T
5680: 63 6c 5f 54 68 72 65 61 64 49 64 20 69 64 3b 20  cl_ThreadId id; 
5690: 20 20 20 2f 2a 20 49 64 20 6f 66 20 74 68 65 20     /* Id of the 
56a0: 74 68 72 65 61 64 20 74 6f 20 67 65 74 20 74 68  thread to get th
56b0: 65 20 68 61 73 68 20 74 61 62 6c 65 20 66 6f 72  e hash table for
56c0: 20 2a 2f 0a 2b 7b 0a 2b 20 20 20 20 54 63 6c 5f   */.+{.+    Tcl_
56d0: 48 61 73 68 54 61 62 6c 65 20 2a 68 61 73 68 54  HashTable *hashT
56e0: 61 62 6c 65 50 74 72 3b 20 2f 2a 20 68 61 73 68  ablePtr; /* hash
56f0: 20 74 61 62 6c 65 20 66 6f 72 20 63 75 72 72 65   table for curre
5700: 6e 74 20 74 68 72 65 61 64 20 2a 2f 0a 2b 20 20  nt thread */.+  
5710: 20 20 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20    Tcl_HashEntry 
5720: 2a 68 50 74 72 3b 20 2f 2a 20 68 61 73 68 20 65  *hPtr; /* hash e
5730: 6e 74 72 79 20 66 6f 72 20 63 75 72 72 65 6e 74  ntry for current
5740: 20 74 68 72 65 61 64 20 69 6e 20 6d 61 73 74 65   thread in maste
5750: 72 20 74 61 62 6c 65 20 2a 2f 0a 2b 20 20 20 20  r table */.+    
5760: 69 6e 74 20 6e 65 77 3b 0a 2b 0a 2b 23 69 66 64  int new;.+.+#ifd
5770: 65 66 20 54 43 4c 5f 54 48 52 45 41 44 5f 53 54  ef TCL_THREAD_ST
5780: 4f 52 41 47 45 5f 44 45 42 55 47 0a 2b 20 20 20  ORAGE_DEBUG.+   
5790: 20 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61   TclpThreadStora
57a0: 67 65 50 72 69 6e 74 28 73 74 64 65 72 72 2c 20  gePrint(stderr, 
57b0: 30 29 3b 0a 2b 23 65 6e 64 69 66 0a 2b 0a 2b 20  0);.+#endif.+.+ 
57c0: 20 20 20 53 54 4f 52 41 47 45 5f 4c 4f 43 4b 3b     STORAGE_LOCK;
57d0: 0a 2b 20 20 20 20 69 66 20 28 74 68 72 65 61 64  .+    if (thread
57e0: 53 74 6f 72 61 67 65 48 61 73 68 54 61 62 6c 65  StorageHashTable
57f0: 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 2b  Ptr == NULL) {.+
5800: 20 20 20 20 20 20 20 20 2f 2a 20 6c 6f 6f 6b 73          /* looks
5810: 20 6c 69 6b 65 20 77 65 20 68 61 76 65 6e 27 74   like we haven't
5820: 20 63 72 65 61 74 65 64 20 74 68 65 20 6f 75 74   created the out
5830: 65 72 20 68 61 73 68 20 74 61 62 6c 65 20 79 65  er hash table ye
5840: 74 0a 2b 20 20 20 20 20 20 20 20 20 20 20 77 65  t.+           we
5850: 20 63 61 6e 20 6a 75 73 74 20 64 6f 20 74 68 61   can just do tha
5860: 74 20 6e 6f 77 2e 20 2a 2f 0a 2b 20 20 20 20 20  t now. */.+     
5870: 20 20 20 74 68 72 65 61 64 53 74 6f 72 61 67 65     threadStorage
5880: 48 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20 28  HashTablePtr = (
5890: 54 63 6c 5f 48 61 73 68 54 61 62 6c 65 20 2a 29  Tcl_HashTable *)
58a0: 54 63 6c 70 53 79 73 41 6c 6c 6f 63 28 73 69 7a  TclpSysAlloc(siz
58b0: 65 6f 66 28 54 63 6c 5f 48 61 73 68 54 61 62 6c  eof(Tcl_HashTabl
58c0: 65 29 2c 20 30 29 3b 0a 2b 0a 2b 20 20 20 20 20  e), 0);.+.+     
58d0: 20 20 20 69 66 20 28 74 68 72 65 61 64 53 74 6f     if (threadSto
58e0: 72 61 67 65 48 61 73 68 54 61 62 6c 65 50 74 72  rageHashTablePtr
58f0: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20   != NULL) {.+   
5900: 20 20 20 20 20 20 20 20 20 2f 2a 20 69 6e 69 74           /* init
5910: 69 61 6c 69 7a 65 20 74 68 65 20 68 61 73 68 20  ialize the hash 
5920: 74 61 62 6c 65 20 2a 2f 0a 2b 20 20 20 20 20 20  table */.+      
5930: 20 20 20 20 20 20 54 63 6c 5f 49 6e 69 74 43 75        Tcl_InitCu
5940: 73 74 6f 6d 48 61 73 68 54 61 62 6c 65 28 74 68  stomHashTable(th
5950: 72 65 61 64 53 74 6f 72 61 67 65 48 61 73 68 54  readStorageHashT
5960: 61 62 6c 65 50 74 72 2c 20 54 43 4c 5f 43 55 53  ablePtr, TCL_CUS
5970: 54 4f 4d 5f 54 59 50 45 5f 4b 45 59 53 2c 20 26  TOM_TYPE_KEYS, &
5980: 74 63 6c 54 68 72 65 61 64 53 74 6f 72 61 67 65  tclThreadStorage
5990: 48 61 73 68 4b 65 79 54 79 70 65 29 3b 0a 2b 20  HashKeyType);.+ 
59a0: 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a         } else {.
59b0: 2b 20 20 20 20 20 20 20 20 20 20 20 20 70 61 6e  +            pan
59c0: 69 63 28 22 63 6f 75 6c 64 20 6e 6f 74 20 61 6c  ic("could not al
59d0: 6c 6f 63 61 74 65 20 6d 61 73 74 65 72 20 74 68  locate master th
59e0: 72 65 61 64 20 73 74 6f 72 61 67 65 20 68 61 73  read storage has
59f0: 68 20 74 61 62 6c 65 22 29 3b 0a 2b 20 20 20 20  h table");.+    
5a00: 20 20 20 20 7d 0a 2b 0a 2b 20 20 20 20 20 20 20      }.+.+       
5a10: 20 2f 2a 20 77 65 20 4d 55 53 54 20 61 6c 73 6f   /* we MUST also
5a20: 20 69 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 20   initialize the 
5a30: 63 61 63 68 65 2c 20 73 69 6e 63 65 20 69 74 20  cache, since it 
5a40: 69 73 20 63 68 65 63 6b 65 64 20 62 79 0a 2b 20  is checked by.+ 
5a50: 20 20 20 20 20 20 20 20 20 20 54 63 6c 70 54 68            TclpTh
5a60: 72 65 61 64 53 74 6f 72 61 67 65 47 65 74 48 61  readStorageGetHa
5a70: 73 68 54 61 62 6c 65 20 69 6e 20 74 68 65 20 63  shTable in the c
5a80: 61 6c 6c 20 62 65 6c 6f 77 2e 20 2a 2f 0a 2b 20  all below. */.+ 
5a90: 20 20 20 20 20 20 20 6d 65 6d 73 65 74 28 28 57         memset((W
5aa0: 69 6e 54 68 72 65 61 64 53 74 6f 72 61 67 65 20  inThreadStorage 
5ab0: 2a 29 26 74 68 72 65 61 64 53 74 6f 72 61 67 65  *)&threadStorage
5ac0: 43 61 63 68 65 2c 20 30 2c 20 73 69 7a 65 6f 66  Cache, 0, sizeof
5ad0: 28 57 69 6e 54 68 72 65 61 64 53 74 6f 72 61 67  (WinThreadStorag
5ae0: 65 29 20 2a 20 53 54 4f 52 41 47 45 5f 43 41 43  e) * STORAGE_CAC
5af0: 48 45 5f 53 4c 4f 54 53 29 3b 0a 2b 0a 2b 20 20  HE_SLOTS);.+.+  
5b00: 20 20 20 20 20 20 2f 2a 20 6e 6f 77 2c 20 77 65        /* now, we
5b10: 20 73 65 74 20 74 68 65 20 66 69 72 73 74 20 76   set the first v
5b20: 61 6c 75 65 20 74 6f 20 62 65 20 75 73 65 64 20  alue to be used 
5b30: 66 6f 72 20 61 20 74 68 72 65 61 64 20 64 61 74  for a thread dat
5b40: 61 20 6b 65 79 2e 20 2a 2f 0a 2b 20 20 20 20 20  a key. */.+     
5b50: 20 20 20 6e 65 78 74 54 68 72 65 61 64 53 74 6f     nextThreadSto
5b60: 72 61 67 65 4b 65 79 20 3d 20 53 54 4f 52 41 47  rageKey = STORAG
5b70: 45 5f 46 49 52 53 54 5f 4b 45 59 3b 0a 2b 20 20  E_FIRST_KEY;.+  
5b80: 20 20 7d 0a 2b 20 20 20 20 53 54 4f 52 41 47 45    }.+    STORAGE
5b90: 5f 55 4e 4c 4f 43 4b 3b 0a 2b 0a 2b 20 20 20 20  _UNLOCK;.+.+    
5ba0: 2f 2a 0a 2b 20 20 20 20 20 2a 20 41 20 74 68 72  /*.+     * A thr
5bb0: 65 61 64 20 49 64 20 6f 66 20 7a 65 72 6f 20 69  ead Id of zero i
5bc0: 6e 64 69 63 61 74 65 73 20 74 68 61 74 20 74 68  ndicates that th
5bd0: 65 20 63 61 6c 6c 65 72 20 64 6f 65 73 20 6e 6f  e caller does no
5be0: 74 20 77 61 6e 74 20 74 6f 0a 2b 20 20 20 20 20  t want to.+     
5bf0: 2a 20 6c 6f 6f 6b 75 70 20 6f 72 20 69 6e 69 74  * lookup or init
5c00: 69 61 6c 69 7a 65 20 74 68 65 20 68 61 73 68 20  ialize the hash 
5c10: 74 61 62 6c 65 20 70 6f 69 6e 74 65 72 20 66 6f  table pointer fo
5c20: 72 20 74 68 65 20 74 68 72 65 61 64 2e 0a 2b 20  r the thread..+ 
5c30: 20 20 20 20 2a 2f 0a 2b 20 20 20 20 69 66 20 28      */.+    if (
5c40: 69 64 20 21 3d 20 53 54 4f 52 41 47 45 5f 49 4e  id != STORAGE_IN
5c50: 56 41 4c 49 44 5f 54 48 52 45 41 44 29 20 7b 0a  VALID_THREAD) {.
5c60: 2b 20 20 20 20 20 20 20 20 68 61 73 68 54 61 62  +        hashTab
5c70: 6c 65 50 74 72 20 3d 20 54 63 6c 70 54 68 72 65  lePtr = TclpThre
5c80: 61 64 53 74 6f 72 61 67 65 47 65 74 48 61 73 68  adStorageGetHash
5c90: 54 61 62 6c 65 28 69 64 29 3b 0a 2b 0a 2b 20 20  Table(id);.+.+  
5ca0: 20 20 20 20 20 20 69 66 20 28 68 61 73 68 54 61        if (hashTa
5cb0: 62 6c 65 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20  blePtr == NULL) 
5cc0: 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 68  {.+            h
5cd0: 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20 28 54  ashTablePtr = (T
5ce0: 63 6c 5f 48 61 73 68 54 61 62 6c 65 20 2a 29 54  cl_HashTable *)T
5cf0: 63 6c 70 53 79 73 41 6c 6c 6f 63 28 73 69 7a 65  clpSysAlloc(size
5d00: 6f 66 28 54 63 6c 5f 48 61 73 68 54 61 62 6c 65  of(Tcl_HashTable
5d10: 29 2c 20 30 29 3b 0a 2b 0a 2b 20 20 20 20 20 20  ), 0);.+.+      
5d20: 20 20 20 20 20 20 69 66 20 28 68 61 73 68 54 61        if (hashTa
5d30: 62 6c 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20  blePtr != NULL) 
5d40: 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  {.+             
5d50: 20 20 20 54 63 6c 5f 49 6e 69 74 43 75 73 74 6f     Tcl_InitCusto
5d60: 6d 48 61 73 68 54 61 62 6c 65 28 68 61 73 68 54  mHashTable(hashT
5d70: 61 62 6c 65 50 74 72 2c 20 54 43 4c 5f 43 55 53  ablePtr, TCL_CUS
5d80: 54 4f 4d 5f 54 59 50 45 5f 4b 45 59 53 2c 20 26  TOM_TYPE_KEYS, &
5d90: 74 63 6c 54 68 72 65 61 64 53 74 6f 72 61 67 65  tclThreadStorage
5da0: 48 61 73 68 4b 65 79 54 79 70 65 29 3b 0a 2b 0a  HashKeyType);.+.
5db0: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
5dc0: 20 2f 2a 20 61 64 64 20 6e 65 77 20 74 68 72 65   /* add new thre
5dd0: 61 64 20 73 74 6f 72 61 67 65 20 68 61 73 68 20  ad storage hash 
5de0: 74 61 62 6c 65 20 74 6f 20 74 68 65 20 6d 61 73  table to the mas
5df0: 74 65 72 20 68 61 73 68 20 74 61 62 6c 65 20 2a  ter hash table *
5e00: 2f 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  /.+             
5e10: 20 20 20 53 54 4f 52 41 47 45 5f 4c 4f 43 4b 3b     STORAGE_LOCK;
5e20: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .+              
5e30: 20 20 68 50 74 72 20 3d 20 54 63 6c 5f 43 72 65    hPtr = Tcl_Cre
5e40: 61 74 65 48 61 73 68 45 6e 74 72 79 28 74 68 72  ateHashEntry(thr
5e50: 65 61 64 53 74 6f 72 61 67 65 48 61 73 68 54 61  eadStorageHashTa
5e60: 62 6c 65 50 74 72 2c 20 28 63 68 61 72 20 2a 29  blePtr, (char *)
5e70: 69 64 2c 20 26 6e 65 77 29 3b 0a 2b 0a 2b 20 20  id, &new);.+.+  
5e80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66                if
5e90: 20 28 68 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20   (hPtr != NULL) 
5ea0: 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  {.+             
5eb0: 20 20 20 20 20 20 20 54 63 6c 5f 53 65 74 48 61         Tcl_SetHa
5ec0: 73 68 56 61 6c 75 65 28 68 50 74 72 2c 20 68 61  shValue(hPtr, ha
5ed0: 73 68 54 61 62 6c 65 50 74 72 29 3b 0a 2b 20 20  shTablePtr);.+  
5ee0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 20                } 
5ef0: 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20 20 20  else {.+        
5f00: 20 20 20 20 20 20 20 20 20 20 20 20 70 61 6e 69              pani
5f10: 63 28 22 54 63 6c 5f 43 72 65 61 74 65 48 61 73  c("Tcl_CreateHas
5f20: 68 45 6e 74 72 79 20 66 61 69 6c 65 64 20 66 72  hEntry failed fr
5f30: 6f 6d 20 54 63 6c 70 54 68 72 65 61 64 53 74 6f  om TclpThreadSto
5f40: 72 61 67 65 49 6e 69 74 21 22 29 3b 0a 2b 20 20  rageInit!");.+  
5f50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a                }.
5f60: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
5f70: 20 53 54 4f 52 41 47 45 5f 55 4e 4c 4f 43 4b 3b   STORAGE_UNLOCK;
5f80: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 7d 20  .+            } 
5f90: 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20 20 20  else {.+        
5fa0: 20 20 20 20 20 20 20 20 70 61 6e 69 63 28 22 63          panic("c
5fb0: 6f 75 6c 64 20 6e 6f 74 20 61 6c 6c 6f 63 61 74  ould not allocat
5fc0: 65 20 74 68 72 65 61 64 20 73 70 65 63 69 66 69  e thread specifi
5fd0: 63 20 68 61 73 68 20 74 61 62 6c 65 22 29 3b 0a  c hash table");.
5fe0: 2b 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b  +            }.+
5ff0: 20 20 20 20 20 20 20 20 7d 0a 2b 20 20 20 20 7d          }.+    }
6000: 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20 20   else {.+       
6010: 20 68 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20   hashTablePtr = 
6020: 4e 55 4c 4c 3b 0a 2b 20 20 20 20 7d 0a 2b 0a 2b  NULL;.+    }.+.+
6030: 20 20 20 20 72 65 74 75 72 6e 20 68 61 73 68 54      return hashT
6040: 61 62 6c 65 50 74 72 3b 0a 2b 7d 0a 2b 0c 0a 2b  ablePtr;.+}.+..+
6050: 2f 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  /*.+ *----------
6060: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6070: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6080: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
6090: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a  ------------.+ *
60a0: 0a 20 20 2a 20 54 63 6c 70 54 68 72 65 61 64 44  .  * TclpThreadD
60b0: 61 74 61 4b 65 79 49 6e 69 74 20 2d 2d 0a 20 20  ataKeyInit --.  
60c0: 2a 0a 20 20 2a 09 54 68 69 73 20 70 72 6f 63 65  *.  *.This proce
60d0: 64 75 72 65 20 69 6e 69 74 69 61 6c 69 7a 65 73  dure initializes
60e0: 20 61 20 74 68 72 65 61 64 20 73 70 65 63 69 66   a thread specif
60f0: 69 63 20 64 61 74 61 20 62 6c 6f 63 6b 20 6b 65  ic data block ke
6100: 79 2e 0a 40 40 20 2d 35 34 30 2c 31 38 20 2b 31  y..@@ -540,18 +1
6110: 30 31 36 2c 36 37 20 40 40 0a 20 7b 0a 20 20 20  016,67 @@. {.   
6120: 20 20 44 57 4f 52 44 20 2a 69 6e 64 65 78 50 74    DWORD *indexPt
6130: 72 3b 0a 20 20 20 20 20 44 57 4f 52 44 20 6e 65  r;.     DWORD ne
6140: 77 4b 65 79 3b 0a 2d 0a 20 20 20 20 20 4d 41 53  wKey;.-.     MAS
6150: 54 45 52 5f 4c 4f 43 4b 3b 0a 20 20 20 20 20 69  TER_LOCK;.     i
6160: 66 20 28 2a 6b 65 79 50 74 72 20 3d 3d 20 4e 55  f (*keyPtr == NU
6170: 4c 4c 29 20 7b 0a 20 09 69 6e 64 65 78 50 74 72  LL) {. .indexPtr
6180: 20 3d 20 28 44 57 4f 52 44 20 2a 29 63 6b 61 6c   = (DWORD *)ckal
6190: 6c 6f 63 28 73 69 7a 65 6f 66 28 44 57 4f 52 44  loc(sizeof(DWORD
61a0: 29 29 3b 0a 2b 20 20 20 20 20 20 20 20 69 66 20  ));.+        if 
61b0: 28 69 6e 64 65 78 50 74 72 20 21 3d 20 4e 55 4c  (indexPtr != NUL
61c0: 4c 29 20 7b 0a 2b 23 69 66 6e 64 65 66 20 54 43  L) {.+#ifndef TC
61d0: 4c 5f 4e 4f 5f 54 4c 53 0a 20 09 6e 65 77 4b 65  L_NO_TLS. .newKe
61e0: 79 20 3d 20 54 6c 73 41 6c 6c 6f 63 28 29 3b 0a  y = TlsAlloc();.
61f0: 20 20 20 20 20 20 20 20 20 69 66 20 28 6e 65 77           if (new
6200: 4b 65 79 20 21 3d 20 54 4c 53 5f 4f 55 54 5f 4f  Key != TLS_OUT_O
6210: 46 5f 49 4e 44 45 58 45 53 29 20 7b 0a 20 20 20  F_INDEXES) {.   
6220: 20 20 20 20 20 20 20 20 20 20 2a 69 6e 64 65 78            *index
6230: 50 74 72 20 3d 20 6e 65 77 4b 65 79 3b 0a 2b 20  Ptr = newKey;.+ 
6240: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a                 *
6250: 6b 65 79 50 74 72 20 3d 20 28 54 63 6c 5f 54 68  keyPtr = (Tcl_Th
6260: 72 65 61 64 44 61 74 61 4b 65 79 29 69 6e 64 65  readDataKey)inde
6270: 78 50 74 72 3b 0a 2b 20 20 20 20 20 20 20 20 20  xPtr;.+         
6280: 20 20 20 20 20 20 20 54 63 6c 52 65 6d 65 6d 62         TclRememb
6290: 65 72 44 61 74 61 4b 65 79 28 6b 65 79 50 74 72  erDataKey(keyPtr
62a0: 29 3b 0a 20 20 20 20 20 20 20 20 20 7d 20 65 6c  );.         } el
62b0: 73 65 20 7b 0a 2b 20 20 20 20 20 20 20 20 20 20  se {.+          
62c0: 20 20 20 20 20 20 2f 2a 0a 2b 20 20 20 20 20 20        /*.+      
62d0: 20 20 20 20 20 20 20 20 20 20 20 2a 20 54 68 69             * Thi
62e0: 73 20 70 61 6e 69 63 20 69 73 20 70 72 6f 62 61  s panic is proba
62f0: 62 6c 79 20 74 68 65 20 6d 6f 73 74 20 6c 69 6b  bly the most lik
6300: 65 6c 79 20 6f 6e 65 20 69 6e 20 74 68 69 73 0a  ely one in this.
6310: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
6320: 20 20 2a 20 65 6e 74 69 72 65 20 66 69 6c 65 20    * entire file 
6330: 74 6f 20 61 63 74 75 61 6c 6c 79 20 62 65 20 68  to actually be h
6340: 69 74 2e 20 54 68 65 20 70 72 69 6d 61 72 79 20  it. The primary 
6350: 72 65 61 73 6f 6e 20 66 6f 72 0a 2b 20 20 20 20  reason for.+    
6360: 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 20 74               * t
6370: 68 69 73 20 69 73 20 74 68 61 74 20 74 68 65 72  his is that ther
6380: 65 20 61 72 65 20 68 61 72 64 20 63 6f 64 65 64  e are hard coded
6390: 20 6c 69 6d 69 74 73 20 6f 6e 20 74 68 65 20 6e   limits on the n
63a0: 75 6d 62 65 72 0a 2b 20 20 20 20 20 20 20 20 20  umber.+         
63b0: 20 20 20 20 20 20 20 20 2a 20 6f 66 20 54 4c 53          * of TLS
63c0: 20 69 6e 64 65 78 65 73 2f 73 6c 6f 74 73 20 6f   indexes/slots o
63d0: 6e 20 41 4c 4c 20 76 65 72 73 69 6f 6e 73 20 6f  n ALL versions o
63e0: 66 20 57 69 6e 33 32 2c 20 61 73 0a 2b 20 20 20  f Win32, as.+   
63f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 20                * 
6400: 66 6f 6c 6c 6f 77 73 3a 0a 2b 20 20 20 20 20 20  follows:.+      
6410: 20 20 20 20 20 20 20 20 20 20 20 2a 0a 2b 20 20             *.+  
6420: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a                 *
6430: 20 20 39 35 2f 4e 54 34 3a 20 36 34 0a 2b 20 20    95/NT4: 64.+  
6440: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a                 *
6450: 20 20 20 39 38 2f 4d 65 3a 20 38 30 0a 2b 20 20     98/Me: 80.+  
6460: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a                 *
6470: 20 32 30 30 30 2f 58 50 3a 20 31 30 38 38 0a 2b   2000/XP: 1088.+
6480: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
6490: 20 2a 20 20 20 20 32 30 30 33 3a 20 31 30 38 38   *    2003: 1088
64a0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .+              
64b0: 20 20 20 2a 0a 2b 20 20 20 20 20 20 20 20 20 20     *.+          
64c0: 20 20 20 20 20 20 20 2a 20 41 6c 6c 20 6f 66 20         * All of 
64d0: 74 68 65 73 65 20 6c 69 6d 69 74 73 20 61 72 65  these limits are
64e0: 20 70 65 72 20 70 72 6f 63 65 73 73 2c 20 66 6f   per process, fo
64f0: 72 20 74 68 65 20 6c 69 66 65 74 69 6d 65 0a 2b  r the lifetime.+
6500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
6510: 20 2a 20 6f 66 20 74 68 65 20 70 72 6f 63 65 73   * of the proces
6520: 73 2c 20 77 68 69 63 68 20 63 6f 75 6c 64 20 62  s, which could b
6530: 65 20 61 20 62 69 67 20 70 72 6f 62 6c 65 6d 20  e a big problem 
6540: 66 6f 72 20 6c 6f 6e 67 0a 2b 20 20 20 20 20 20  for long.+      
6550: 20 20 20 20 20 20 20 20 20 20 20 2a 20 72 75 6e             * run
6560: 6e 69 6e 67 20 70 72 6f 63 65 73 73 65 73 20 74  ning processes t
6570: 68 61 74 20 6c 6f 61 64 20 61 6e 64 20 75 6e 6c  hat load and unl
6580: 6f 61 64 20 61 20 6c 6f 74 20 6f 66 20 44 4c 4c  oad a lot of DLL
6590: 73 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  s.+             
65a0: 20 20 20 20 2a 20 74 68 61 74 20 75 73 65 20 54      * that use T
65b0: 4c 53 2e 0a 2b 20 20 20 20 20 20 20 20 20 20 20  LS..+           
65c0: 20 20 20 20 20 20 2a 2f 0a 20 20 20 20 20 20 20        */.       
65d0: 20 20 20 20 20 20 70 61 6e 69 63 28 22 54 6c 73        panic("Tls
65e0: 41 6c 6c 6f 63 20 66 61 69 6c 65 64 20 66 72 6f  Alloc failed fro
65f0: 6d 20 54 63 6c 70 54 68 72 65 61 64 44 61 74 61  m TclpThreadData
6600: 4b 65 79 49 6e 69 74 21 22 29 3b 20 2f 2a 20 74  KeyInit!"); /* t
6610: 68 69 73 20 73 68 6f 75 6c 64 20 62 65 20 61 20  his should be a 
6620: 66 61 74 61 6c 20 65 72 72 6f 72 20 2a 2f 0a 20  fatal error */. 
6630: 20 20 20 20 20 20 20 20 7d 0a 2b 23 65 6c 73 65          }.+#else
6640: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a  .+            /*
6650: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 2a  .+             *
6660: 20 57 65 20 6d 75 73 74 20 63 61 6c 6c 20 74 68   We must call th
6670: 69 73 20 6e 6f 77 20 74 6f 20 6d 61 6b 65 20 73  is now to make s
6680: 75 72 65 0a 2b 20 20 20 20 20 20 20 20 20 20 20  ure.+           
6690: 20 20 2a 20 74 68 61 74 20 6e 65 78 74 54 68 72    * that nextThr
66a0: 65 61 64 53 74 6f 72 61 67 65 4b 65 79 20 68 61  eadStorageKey ha
66b0: 73 20 61 20 77 65 6c 6c 20 64 65 66 69 6e 65 64  s a well defined
66c0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 2a  .+             *
66d0: 20 76 61 6c 75 65 2e 0a 2b 20 20 20 20 20 20 20   value..+       
66e0: 20 20 20 20 20 20 2a 2f 0a 2b 20 20 20 20 20 20        */.+      
66f0: 20 20 20 20 20 20 54 63 6c 70 54 68 72 65 61 64        TclpThread
6700: 53 74 6f 72 61 67 65 49 6e 69 74 28 53 54 4f 52  StorageInit(STOR
6710: 41 47 45 5f 49 4e 56 41 4c 49 44 5f 54 48 52 45  AGE_INVALID_THRE
6720: 41 44 29 3b 0a 2b 20 20 20 20 20 20 20 20 20 20  AD);.+          
6730: 20 20 53 54 4f 52 41 47 45 5f 4c 4f 43 4b 3b 0a    STORAGE_LOCK;.
6740: 2b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 0a  +            /*.
6750: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 20  +             * 
6760: 54 68 65 73 65 20 64 61 74 61 20 6b 65 79 20 76  These data key v
6770: 61 6c 75 65 73 20 61 72 65 20 73 65 71 75 65 6e  alues are sequen
6780: 74 69 61 6c 6c 79 0a 2b 20 20 20 20 20 20 20 20  tially.+        
6790: 20 20 20 20 20 2a 20 61 73 73 69 67 6e 65 64 20       * assigned 
67a0: 61 6e 64 20 77 65 20 6d 75 73 74 20 75 73 65 20  and we must use 
67b0: 74 68 65 20 73 74 6f 72 61 67 65 0a 2b 20 20 20  the storage.+   
67c0: 20 20 20 20 20 20 20 20 20 20 2a 20 6c 6f 63 6b            * lock
67d0: 20 74 6f 20 70 72 65 76 65 6e 74 20 73 65 72 69   to prevent seri
67e0: 6f 75 73 20 70 72 6f 62 6c 65 6d 73 20 68 65 72  ous problems her
67f0: 65 2e 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20  e..+            
6800: 20 2a 20 57 65 20 63 6f 75 6c 64 20 75 73 65 20   * We could use 
6810: 74 68 65 20 57 69 6e 33 32 20 69 6e 74 65 72 6c  the Win32 interl
6820: 6f 63 6b 65 64 0a 2b 20 20 20 20 20 20 20 20 20  ocked.+         
6830: 20 20 20 20 2a 20 69 6e 63 72 65 6d 65 6e 74 20      * increment 
6840: 68 65 72 65 20 49 46 20 69 74 20 68 61 64 20 63  here IF it had c
6850: 6f 6e 73 69 73 74 65 6e 74 0a 2b 20 20 20 20 20  onsistent.+     
6860: 20 20 20 20 20 20 20 20 2a 20 62 65 68 61 76 69          * behavi
6870: 6f 72 20 6f 6e 20 64 69 66 66 65 72 65 6e 74 20  or on different 
6880: 76 61 72 69 61 74 69 6f 6e 73 20 6f 66 0a 2b 20  variations of.+ 
6890: 20 20 20 20 20 20 20 20 20 20 20 20 2a 20 57 69              * Wi
68a0: 6e 33 32 2e 20 41 6c 73 6f 20 6e 6f 74 65 20 74  n32. Also note t
68b0: 68 61 74 20 74 68 65 20 63 61 6c 6c 65 72 20 73  hat the caller s
68c0: 68 6f 75 6c 64 0a 2b 20 20 20 20 20 20 20 20 20  hould.+         
68d0: 20 20 20 20 2a 20 4e 4f 54 20 6d 61 6b 65 20 61      * NOT make a
68e0: 6e 79 20 61 73 73 75 6d 70 74 69 6f 6e 73 20 61  ny assumptions a
68f0: 62 6f 75 74 20 74 68 65 0a 2b 20 20 20 20 20 20  bout the.+      
6900: 20 20 20 20 20 20 20 2a 20 70 72 6f 76 69 64 65         * provide
6910: 64 20 76 61 6c 75 65 73 2e 20 49 6e 20 70 61 72  d values. In par
6920: 74 69 63 75 6c 61 72 2c 20 77 65 20 6d 61 79 0a  ticular, we may.
6930: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 20  +             * 
6940: 6e 65 65 64 20 74 6f 20 72 65 73 65 72 76 65 20  need to reserve 
6950: 73 6f 6d 65 20 76 61 6c 75 65 73 20 69 6e 20 74  some values in t
6960: 68 65 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20  he.+            
6970: 20 2a 20 66 75 74 75 72 65 2e 0a 2b 20 20 20 20   * future..+    
6980: 20 20 20 20 20 20 20 20 20 2a 2f 0a 2b 20 20 20           */.+   
6990: 20 20 20 20 20 20 20 20 20 6e 65 77 4b 65 79 20           newKey 
69a0: 3d 20 6e 65 78 74 54 68 72 65 61 64 53 74 6f 72  = nextThreadStor
69b0: 61 67 65 4b 65 79 2b 2b 3b 0a 2b 20 20 20 20 20  ageKey++;.+     
69c0: 20 20 20 20 20 20 20 53 54 4f 52 41 47 45 5f 55         STORAGE_U
69d0: 4e 4c 4f 43 4b 3b 0a 2b 0a 2b 20 20 20 20 20 20  NLOCK;.+.+      
69e0: 20 20 20 20 20 20 2a 69 6e 64 65 78 50 74 72 20        *indexPtr 
69f0: 3d 20 6e 65 77 4b 65 79 3b 0a 20 09 2a 6b 65 79  = newKey;. .*key
6a00: 50 74 72 20 3d 20 28 54 63 6c 5f 54 68 72 65 61  Ptr = (Tcl_Threa
6a10: 64 44 61 74 61 4b 65 79 29 69 6e 64 65 78 50 74  dDataKey)indexPt
6a20: 72 3b 0a 20 09 54 63 6c 52 65 6d 65 6d 62 65 72  r;. .TclRemember
6a30: 44 61 74 61 4b 65 79 28 6b 65 79 50 74 72 29 3b  DataKey(keyPtr);
6a40: 0a 2b 23 65 6e 64 69 66 0a 2b 20 20 20 20 20 20  .+#endif.+      
6a50: 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20    } else {.+    
6a60: 20 20 20 20 20 20 20 20 70 61 6e 69 63 28 22 63          panic("c
6a70: 6b 61 6c 6c 6f 63 20 66 61 69 6c 65 64 20 66 72  kalloc failed fr
6a80: 6f 6d 20 54 63 6c 70 54 68 72 65 61 64 44 61 74  om TclpThreadDat
6a90: 61 4b 65 79 49 6e 69 74 21 22 29 3b 20 2f 2a 20  aKeyInit!"); /* 
6aa0: 74 68 69 73 20 73 68 6f 75 6c 64 20 61 6c 73 6f  this should also
6ab0: 20 62 65 20 61 20 66 61 74 61 6c 20 65 72 72 6f   be a fatal erro
6ac0: 72 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 7d 0a  r */.+        }.
6ad0: 20 20 20 20 20 7d 0a 20 20 20 20 20 4d 41 53 54       }.     MAST
6ae0: 45 52 5f 55 4e 4c 4f 43 4b 3b 0a 20 7d 0a 40 40  ER_UNLOCK;. }.@@
6af0: 20 2d 35 38 30 2c 31 35 20 2b 31 31 30 35 2c 34   -580,15 +1105,4
6b00: 31 20 40 40 0a 20 7b 0a 20 20 20 20 20 44 57 4f  1 @@. {.     DWO
6b10: 52 44 20 2a 69 6e 64 65 78 50 74 72 20 3d 20 2a  RD *indexPtr = *
6b20: 28 44 57 4f 52 44 20 2a 2a 29 6b 65 79 50 74 72  (DWORD **)keyPtr
6b30: 3b 0a 20 20 20 20 20 4c 50 56 4f 49 44 20 72 65  ;.     LPVOID re
6b40: 73 75 6c 74 3b 0a 2b 23 69 66 6e 64 65 66 20 54  sult;.+#ifndef T
6b50: 43 4c 5f 4e 4f 5f 54 4c 53 0a 20 20 20 20 20 69  CL_NO_TLS.     i
6b60: 66 20 28 69 6e 64 65 78 50 74 72 20 3d 3d 20 4e  f (indexPtr == N
6b70: 55 4c 4c 29 20 7b 0a 2d 09 72 65 74 75 72 6e 20  ULL) {.-.return 
6b80: 4e 55 4c 4c 3b 0a 2b 20 20 20 20 20 20 20 20 72  NULL;.+        r
6b90: 65 73 75 6c 74 20 3d 20 4e 55 4c 4c 3b 0a 20 20  esult = NULL;.  
6ba0: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20     } else {.    
6bb0: 20 20 20 20 20 72 65 73 75 6c 74 20 3d 20 54 6c       result = Tl
6bc0: 73 47 65 74 56 61 6c 75 65 28 2a 69 6e 64 65 78  sGetValue(*index
6bd0: 50 74 72 29 3b 0a 20 20 20 20 20 20 20 20 20 69  Ptr);.         i
6be0: 66 20 28 28 72 65 73 75 6c 74 20 3d 3d 20 4e 55  f ((result == NU
6bf0: 4c 4c 29 20 26 26 20 28 47 65 74 4c 61 73 74 45  LL) && (GetLastE
6c00: 72 72 6f 72 28 29 20 21 3d 20 4e 4f 5f 45 52 52  rror() != NO_ERR
6c10: 4f 52 29 29 20 7b 0a 20 20 20 20 20 20 20 20 20  OR)) {.         
6c20: 20 20 20 20 70 61 6e 69 63 28 22 54 6c 73 47 65      panic("TlsGe
6c30: 74 56 61 6c 75 65 20 66 61 69 6c 65 64 20 66 72  tValue failed fr
6c40: 6f 6d 20 54 63 6c 70 54 68 72 65 61 64 44 61 74  om TclpThreadDat
6c50: 61 4b 65 79 47 65 74 21 22 29 3b 0a 20 20 20 20  aKeyGet!");.    
6c60: 20 20 20 20 20 7d 0a 2b 20 20 20 20 7d 0a 20 09       }.+    }. .
6c70: 72 65 74 75 72 6e 20 72 65 73 75 6c 74 3b 0a 2b  return result;.+
6c80: 23 65 6c 73 65 0a 2b 20 20 20 20 54 63 6c 5f 54  #else.+    Tcl_T
6c90: 68 72 65 61 64 49 64 20 69 64 20 3d 20 54 63 6c  hreadId id = Tcl
6ca0: 5f 47 65 74 43 75 72 72 65 6e 74 54 68 72 65 61  _GetCurrentThrea
6cb0: 64 28 29 3b 0a 2b 20 20 20 20 54 63 6c 5f 48 61  d();.+    Tcl_Ha
6cc0: 73 68 54 61 62 6c 65 20 2a 68 61 73 68 54 61 62  shTable *hashTab
6cd0: 6c 65 50 74 72 3b 0a 2b 20 20 20 20 54 63 6c 5f  lePtr;.+    Tcl_
6ce0: 48 61 73 68 45 6e 74 72 79 20 2a 68 50 74 72 3b  HashEntry *hPtr;
6cf0: 0a 2b 0a 2b 20 20 20 20 69 66 20 28 69 6e 64 65  .+.+    if (inde
6d00: 78 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a  xPtr == NULL) {.
6d10: 2b 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 20  +        result 
6d20: 3d 20 4e 55 4c 4c 3b 0a 2b 20 20 20 20 7d 20 65  = NULL;.+    } e
6d30: 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20 20 20 68  lse {.+        h
6d40: 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20 54 63  ashTablePtr = Tc
6d50: 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67 65 49  lpThreadStorageI
6d60: 6e 69 74 28 69 64 29 3b 0a 2b 0a 2b 20 20 20 20  nit(id);.+.+    
6d70: 20 20 20 20 69 66 20 28 68 61 73 68 54 61 62 6c      if (hashTabl
6d80: 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  ePtr != NULL) {.
6d90: 2b 20 20 20 20 20 20 20 20 20 20 20 20 68 50 74  +            hPt
6da0: 72 20 3d 20 54 63 6c 5f 46 69 6e 64 48 61 73 68  r = Tcl_FindHash
6db0: 45 6e 74 72 79 28 68 61 73 68 54 61 62 6c 65 50  Entry(hashTableP
6dc0: 74 72 2c 20 28 63 68 61 72 20 2a 29 2a 69 6e 64  tr, (char *)*ind
6dd0: 65 78 50 74 72 29 3b 0a 2b 0a 2b 20 20 20 20 20  exPtr);.+.+     
6de0: 20 20 20 20 20 20 20 69 66 20 28 68 50 74 72 20         if (hPtr 
6df0: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20  != NULL) {.+    
6e00: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75              resu
6e10: 6c 74 20 3d 20 28 4c 50 56 4f 49 44 29 54 63 6c  lt = (LPVOID)Tcl
6e20: 5f 47 65 74 48 61 73 68 56 61 6c 75 65 28 68 50  _GetHashValue(hP
6e30: 74 72 29 3b 0a 2b 20 20 20 20 20 20 20 20 20 20  tr);.+          
6e40: 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20    } else {.+    
6e50: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75              resu
6e60: 6c 74 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 20  lt = NULL;.     
6e70: 7d 0a 2b 20 20 20 20 20 20 20 20 7d 20 65 6c 73  }.+        } els
6e80: 65 20 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20  e {.+           
6e90: 20 70 61 6e 69 63 28 22 54 63 6c 70 54 68 72 65   panic("TclpThre
6ea0: 61 64 53 74 6f 72 61 67 65 49 6e 69 74 20 66 61  adStorageInit fa
6eb0: 69 6c 65 64 20 66 72 6f 6d 20 54 63 6c 70 54 68  iled from TclpTh
6ec0: 72 65 61 64 44 61 74 61 4b 65 79 47 65 74 21 22  readDataKeyGet!"
6ed0: 29 3b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20  );.+            
6ee0: 72 65 73 75 6c 74 20 3d 20 4e 55 4c 4c 3b 0a 2b  result = NULL;.+
6ef0: 20 20 20 20 20 20 20 20 7d 0a 2b 20 20 20 20 7d          }.+    }
6f00: 0a 2b 20 20 20 20 72 65 74 75 72 6e 20 72 65 73  .+    return res
6f10: 75 6c 74 3b 0a 2b 23 65 6e 64 69 66 20 2f 2a 20  ult;.+#endif /* 
6f20: 54 43 4c 5f 4e 4f 5f 54 4c 53 20 2a 2f 0a 20 7d  TCL_NO_TLS */. }
6f30: 0a 20 0c 0a 20 2f 2a 0a 40 40 20 2d 36 31 35 2c  . .. /*.@@ -615,
6f40: 31 31 20 2b 31 31 36 36 2c 39 37 20 40 40 0a 20  11 +1166,97 @@. 
6f50: 20 20 20 20 56 4f 49 44 20 2a 64 61 74 61 3b 09      VOID *data;.
6f60: 09 09 2f 2a 20 54 68 72 65 61 64 20 6c 6f 63 61  ../* Thread loca
6f70: 6c 20 73 74 6f 72 61 67 65 20 2a 2f 0a 20 7b 0a  l storage */. {.
6f80: 20 20 20 20 20 44 57 4f 52 44 20 2a 69 6e 64 65       DWORD *inde
6f90: 78 50 74 72 20 3d 20 2a 28 44 57 4f 52 44 20 2a  xPtr = *(DWORD *
6fa0: 2a 29 6b 65 79 50 74 72 3b 0a 2b 23 69 66 6e 64  *)keyPtr;.+#ifnd
6fb0: 65 66 20 54 43 4c 5f 4e 4f 5f 54 4c 53 0a 20 20  ef TCL_NO_TLS.  
6fc0: 20 20 20 42 4f 4f 4c 20 73 75 63 63 65 73 73 3b     BOOL success;
6fd0: 0a 20 20 20 20 20 73 75 63 63 65 73 73 20 3d 20  .     success = 
6fe0: 54 6c 73 53 65 74 56 61 6c 75 65 28 2a 69 6e 64  TlsSetValue(*ind
6ff0: 65 78 50 74 72 2c 20 28 76 6f 69 64 20 2a 29 64  exPtr, (void *)d
7000: 61 74 61 29 3b 0a 20 20 20 20 20 69 66 20 28 21  ata);.     if (!
7010: 73 75 63 63 65 73 73 29 20 7b 0a 20 20 20 20 20  success) {.     
7020: 20 20 20 20 70 61 6e 69 63 28 22 54 6c 73 53 65      panic("TlsSe
7030: 74 56 61 6c 75 65 20 66 61 69 6c 65 64 20 66 72  tValue failed fr
7040: 6f 6d 20 54 63 6c 70 54 68 72 65 61 64 44 61 74  om TclpThreadDat
7050: 61 4b 65 79 53 65 74 21 22 29 3b 0a 20 20 20 20  aKeySet!");.    
7060: 20 7d 0a 2b 23 65 6c 73 65 0a 2b 20 20 20 20 54   }.+#else.+    T
7070: 63 6c 5f 54 68 72 65 61 64 49 64 20 69 64 20 3d  cl_ThreadId id =
7080: 20 54 63 6c 5f 47 65 74 43 75 72 72 65 6e 74 54   Tcl_GetCurrentT
7090: 68 72 65 61 64 28 29 3b 0a 2b 20 20 20 20 54 63  hread();.+    Tc
70a0: 6c 5f 48 61 73 68 54 61 62 6c 65 20 2a 68 61 73  l_HashTable *has
70b0: 68 54 61 62 6c 65 50 74 72 3b 0a 2b 20 20 20 20  hTablePtr;.+    
70c0: 54 63 6c 5f 48 61 73 68 45 6e 74 72 79 20 2a 68  Tcl_HashEntry *h
70d0: 50 74 72 3b 0a 2b 20 20 20 20 69 6e 74 20 6e 65  Ptr;.+    int ne
70e0: 77 3b 0a 2b 0a 2b 20 20 20 20 68 61 73 68 54 61  w;.+.+    hashTa
70f0: 62 6c 65 50 74 72 20 3d 20 54 63 6c 70 54 68 72  blePtr = TclpThr
7100: 65 61 64 53 74 6f 72 61 67 65 49 6e 69 74 28 69  eadStorageInit(i
7110: 64 29 3b 0a 2b 0a 2b 20 20 20 20 69 66 20 28 68  d);.+.+    if (h
7120: 61 73 68 54 61 62 6c 65 50 74 72 20 21 3d 20 4e  ashTablePtr != N
7130: 55 4c 4c 29 20 7b 0a 2b 20 20 20 20 20 20 20 20  ULL) {.+        
7140: 68 50 74 72 20 3d 20 54 63 6c 5f 46 69 6e 64 48  hPtr = Tcl_FindH
7150: 61 73 68 45 6e 74 72 79 28 68 61 73 68 54 61 62  ashEntry(hashTab
7160: 6c 65 50 74 72 2c 20 28 63 68 61 72 20 2a 29 2a  lePtr, (char *)*
7170: 69 6e 64 65 78 50 74 72 29 3b 0a 2b 0a 2b 20 20  indexPtr);.+.+  
7180: 20 20 20 20 20 20 2f 2a 20 64 6f 65 73 20 74 68        /* does th
7190: 65 20 69 74 65 6d 20 6e 65 65 64 20 74 6f 20 62  e item need to b
71a0: 65 20 63 72 65 61 74 65 64 3f 20 2a 2f 0a 2b 20  e created? */.+ 
71b0: 20 20 20 20 20 20 20 69 66 20 28 68 50 74 72 20         if (hPtr 
71c0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20  == NULL) {.+    
71d0: 20 20 20 20 20 20 20 20 68 50 74 72 20 3d 20 54          hPtr = T
71e0: 63 6c 5f 43 72 65 61 74 65 48 61 73 68 45 6e 74  cl_CreateHashEnt
71f0: 72 79 28 68 61 73 68 54 61 62 6c 65 50 74 72 2c  ry(hashTablePtr,
7200: 20 28 63 68 61 72 20 2a 29 2a 69 6e 64 65 78 50   (char *)*indexP
7210: 74 72 2c 20 26 6e 65 77 29 3b 0a 2b 20 20 20 20  tr, &new);.+    
7220: 20 20 20 20 7d 0a 2b 0a 2b 20 20 20 20 20 20 20      }.+.+       
7230: 20 69 66 20 28 68 50 74 72 20 21 3d 20 4e 55 4c   if (hPtr != NUL
7240: 4c 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 20 20  L) {.+          
7250: 20 20 54 63 6c 5f 53 65 74 48 61 73 68 56 61 6c    Tcl_SetHashVal
7260: 75 65 28 68 50 74 72 2c 20 64 61 74 61 29 3b 0a  ue(hPtr, data);.
7270: 2b 20 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20  +        } else 
7280: 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 70  {.+            p
7290: 61 6e 69 63 28 22 63 6f 75 6c 64 20 6e 6f 74 20  anic("could not 
72a0: 73 65 74 20 68 61 73 68 20 65 6e 74 72 79 20 76  set hash entry v
72b0: 61 6c 75 65 20 66 72 6f 6d 20 54 63 6c 70 54 68  alue from TclpTh
72c0: 72 65 61 64 44 61 74 61 4b 65 79 53 65 74 22 29  readDataKeySet")
72d0: 3b 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 20 20  ;.+        }.+  
72e0: 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20    } else {.+    
72f0: 20 20 20 20 70 61 6e 69 63 28 22 54 63 6c 70 54      panic("TclpT
7300: 68 72 65 61 64 53 74 6f 72 61 67 65 49 6e 69 74  hreadStorageInit
7310: 20 66 61 69 6c 65 64 20 66 72 6f 6d 20 54 63 6c   failed from Tcl
7320: 70 54 68 72 65 61 64 44 61 74 61 4b 65 79 53 65  pThreadDataKeySe
7330: 74 21 22 29 3b 0a 2b 20 20 20 20 7d 0a 2b 23 65  t!");.+    }.+#e
7340: 6e 64 69 66 20 2f 2a 20 54 43 4c 5f 4e 4f 5f 54  ndif /* TCL_NO_T
7350: 4c 53 20 2a 2f 0a 2b 7d 0a 2b 0c 0a 2b 2f 2a 0a  LS */.+}.+..+/*.
7360: 2b 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  + *-------------
7370: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7380: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
73a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 2b 20 2a 0a 2b 20  ---------.+ *.+ 
73b0: 2a 20 54 63 6c 70 46 69 6e 61 6c 69 7a 65 54 68  * TclpFinalizeTh
73c0: 72 65 61 64 53 74 6f 72 61 67 65 20 2d 2d 0a 2b  readStorage --.+
73d0: 20 2a 0a 2b 20 2a 20 20 20 20 20 20 54 68 69 73   *.+ *      This
73e0: 20 70 72 6f 63 65 64 75 72 65 20 63 6c 65 61 6e   procedure clean
73f0: 73 20 75 70 20 74 68 65 20 6d 61 73 74 65 72 20  s up the master 
7400: 74 68 72 65 61 64 20 73 74 6f 72 61 67 65 20 68  thread storage h
7410: 61 73 68 20 74 61 62 6c 65 2c 0a 2b 20 2a 20 20  ash table,.+ *  
7420: 20 20 20 20 61 6c 6c 20 74 68 72 65 61 64 20 73      all thread s
7430: 70 65 63 69 66 69 63 20 68 61 73 68 20 74 61 62  pecific hash tab
7440: 6c 65 73 2c 20 61 6e 64 20 74 68 65 20 74 68 72  les, and the thr
7450: 65 61 64 20 73 74 6f 72 61 67 65 20 63 61 63 68  ead storage cach
7460: 65 2e 0a 2b 20 2a 0a 2b 20 2a 20 52 65 73 75 6c  e..+ *.+ * Resul
7470: 74 73 3a 0a 2b 20 2a 20 20 20 20 20 20 4e 6f 6e  ts:.+ *      Non
7480: 65 2e 0a 2b 20 2a 0a 2b 20 2a 20 53 69 64 65 20  e..+ *.+ * Side 
7490: 65 66 66 65 63 74 73 3a 0a 2b 20 2a 20 20 20 20  effects:.+ *    
74a0: 20 20 54 68 65 20 6d 61 73 74 65 72 20 74 68 72    The master thr
74b0: 65 61 64 20 73 74 6f 72 61 67 65 20 68 61 73 68  ead storage hash
74c0: 20 74 61 62 6c 65 20 61 6e 64 20 74 68 72 65 61   table and threa
74d0: 64 20 73 74 6f 72 61 67 65 20 63 61 63 68 65 20  d storage cache 
74e0: 61 72 65 0a 2b 20 2a 20 20 20 20 20 20 72 65 73  are.+ *      res
74f0: 65 74 20 74 6f 20 74 68 65 69 72 20 69 6e 69 74  et to their init
7500: 69 61 6c 20 28 65 6d 70 74 79 29 20 73 74 61 74  ial (empty) stat
7510: 65 2e 0a 2b 20 2a 0a 2b 20 2a 2d 2d 2d 2d 2d 2d  e..+ *.+ *------
7520: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7530: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
7560: 0a 2b 20 2a 2f 0a 2b 0a 2b 76 6f 69 64 0a 2b 54  .+ */.+.+void.+T
7570: 63 6c 70 46 69 6e 61 6c 69 7a 65 54 68 72 65 61  clpFinalizeThrea
7580: 64 53 74 6f 72 61 67 65 28 29 0a 2b 7b 0a 2b 20  dStorage().+{.+ 
7590: 20 20 20 54 63 6c 5f 48 61 73 68 54 61 62 6c 65     Tcl_HashTable
75a0: 20 2a 68 61 73 68 54 61 62 6c 65 50 74 72 3b 20   *hashTablePtr; 
75b0: 2f 2a 20 68 61 73 68 20 74 61 62 6c 65 20 66 6f  /* hash table fo
75c0: 72 20 63 75 72 72 65 6e 74 20 74 68 72 65 61 64  r current thread
75d0: 20 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73   */.+    Tcl_Has
75e0: 68 53 65 61 72 63 68 20 73 65 61 72 63 68 3b 20  hSearch search; 
75f0: 2f 2a 20 77 65 20 6e 65 65 64 20 74 6f 20 68 69  /* we need to hi
7600: 74 20 65 76 65 72 79 20 74 68 72 65 61 64 20 77  t every thread w
7610: 69 74 68 20 74 68 69 73 20 73 65 61 72 63 68 20  ith this search 
7620: 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68  */.+    Tcl_Hash
7630: 45 6e 74 72 79 20 2a 68 50 74 72 3b 20 2f 2a 20  Entry *hPtr; /* 
7640: 68 61 73 68 20 65 6e 74 72 79 20 66 6f 72 20 63  hash entry for c
7650: 75 72 72 65 6e 74 20 74 68 72 65 61 64 20 69 6e  urrent thread in
7660: 20 6d 61 73 74 65 72 20 74 61 62 6c 65 20 2a 2f   master table */
7670: 0a 2b 0a 2b 20 20 20 20 53 54 4f 52 41 47 45 5f  .+.+    STORAGE_
7680: 4c 4f 43 4b 3b 0a 2b 20 20 20 20 69 66 20 28 74  LOCK;.+    if (t
7690: 68 72 65 61 64 53 74 6f 72 61 67 65 48 61 73 68  hreadStorageHash
76a0: 54 61 62 6c 65 50 74 72 20 21 3d 20 4e 55 4c 4c  TablePtr != NULL
76b0: 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 2f 2a 20  ) {.+        /* 
76c0: 77 65 20 61 72 65 20 67 6f 69 6e 67 20 74 6f 20  we are going to 
76d0: 64 65 6c 65 74 65 20 74 68 65 20 68 61 73 68 20  delete the hash 
76e0: 74 61 62 6c 65 20 66 6f 72 20 65 76 65 72 79 20  table for every 
76f0: 74 68 72 65 61 64 20 6e 6f 77 2e 20 2a 2f 0a 2b  thread now. */.+
7700: 20 20 20 20 20 20 20 20 66 6f 72 20 28 68 50 74          for (hPt
7710: 72 20 3d 20 54 63 6c 5f 46 69 72 73 74 48 61 73  r = Tcl_FirstHas
7720: 68 45 6e 74 72 79 28 74 68 72 65 61 64 53 74 6f  hEntry(threadSto
7730: 72 61 67 65 48 61 73 68 54 61 62 6c 65 50 74 72  rageHashTablePtr
7740: 2c 20 26 73 65 61 72 63 68 29 3b 0a 2b 20 20 20  , &search);.+   
7750: 20 20 20 20 20 20 20 20 20 20 20 20 20 68 50 74               hPt
7760: 72 20 21 3d 20 4e 55 4c 4c 3b 20 68 50 74 72 20  r != NULL; hPtr 
7770: 3d 20 54 63 6c 5f 4e 65 78 74 48 61 73 68 45 6e  = Tcl_NextHashEn
7780: 74 72 79 28 26 73 65 61 72 63 68 29 29 20 7b 0a  try(&search)) {.
7790: 2b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 2f  +.+            /
77a0: 2a 20 67 65 74 20 74 68 65 20 68 61 73 68 20 74  * get the hash t
77b0: 61 62 6c 65 20 63 6f 72 72 65 73 70 6f 6e 64 69  able correspondi
77c0: 6e 67 20 74 6f 20 74 68 65 20 74 68 72 65 61 64  ng to the thread
77d0: 20 69 6e 20 71 75 65 73 74 69 6f 6e 2e 20 2a 2f   in question. */
77e0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 68 61  .+            ha
77f0: 73 68 54 61 62 6c 65 50 74 72 20 3d 20 54 63 6c  shTablePtr = Tcl
7800: 5f 47 65 74 48 61 73 68 56 61 6c 75 65 28 68 50  _GetHashValue(hP
7810: 74 72 29 3b 0a 2b 0a 2b 20 20 20 20 20 20 20 20  tr);.+.+        
7820: 20 20 20 20 69 66 20 28 68 61 73 68 54 61 62 6c      if (hashTabl
7830: 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  ePtr != NULL) {.
7840: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
7850: 20 2f 2a 20 64 65 6c 65 74 65 20 74 68 72 65 61   /* delete threa
7860: 64 20 73 70 65 63 69 66 69 63 20 68 61 73 68 20  d specific hash 
7870: 74 61 62 6c 65 20 61 6e 64 20 66 72 65 65 20 74  table and free t
7880: 68 65 20 73 74 72 75 63 74 2e 20 2a 2f 0a 2b 20  he struct. */.+ 
7890: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54                 T
78a0: 63 6c 5f 44 65 6c 65 74 65 48 61 73 68 54 61 62  cl_DeleteHashTab
78b0: 6c 65 28 68 61 73 68 54 61 62 6c 65 50 74 72 29  le(hashTablePtr)
78c0: 3b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  ;.+             
78d0: 20 20 20 54 63 6c 70 53 79 73 46 72 65 65 28 28     TclpSysFree((
78e0: 63 68 61 72 20 2a 29 68 61 73 68 54 61 62 6c 65  char *)hashTable
78f0: 50 74 72 29 3b 0a 2b 20 20 20 20 20 20 20 20 20  Ptr);.+         
7900: 20 20 20 7d 0a 2b 0a 2b 20 20 20 20 20 20 20 20     }.+.+        
7910: 20 20 20 20 2f 2a 20 64 65 6c 65 74 65 20 74 68      /* delete th
7920: 72 65 61 64 20 73 70 65 63 69 66 69 63 20 65 6e  read specific en
7930: 74 72 79 20 66 72 6f 6d 20 6d 61 73 74 65 72 20  try from master 
7940: 68 61 73 68 20 74 61 62 6c 65 2e 20 2a 2f 0a 2b  hash table. */.+
7950: 20 20 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f              Tcl_
7960: 53 65 74 48 61 73 68 56 61 6c 75 65 28 68 50 74  SetHashValue(hPt
7970: 72 2c 20 4e 55 4c 4c 29 3b 0a 2b 20 20 20 20 20  r, NULL);.+     
7980: 20 20 20 7d 0a 2b 0a 2b 20 20 20 20 20 20 20 20     }.+.+        
7990: 54 63 6c 5f 44 65 6c 65 74 65 48 61 73 68 54 61  Tcl_DeleteHashTa
79a0: 62 6c 65 28 74 68 72 65 61 64 53 74 6f 72 61 67  ble(threadStorag
79b0: 65 48 61 73 68 54 61 62 6c 65 50 74 72 29 3b 0a  eHashTablePtr);.
79c0: 2b 20 20 20 20 20 20 20 20 54 63 6c 70 53 79 73  +        TclpSys
79d0: 46 72 65 65 28 28 63 68 61 72 20 2a 29 74 68 72  Free((char *)thr
79e0: 65 61 64 53 74 6f 72 61 67 65 48 61 73 68 54 61  eadStorageHashTa
79f0: 62 6c 65 50 74 72 29 3b 0a 2b 0a 2b 20 20 20 20  blePtr);.+.+    
7a00: 20 20 20 20 2f 2a 20 72 65 73 65 74 20 74 68 69      /* reset thi
7a10: 73 20 73 6f 20 74 68 61 74 20 6e 65 78 74 20 74  s so that next t
7a20: 69 6d 65 20 61 72 6f 75 6e 64 20 77 65 20 6b 6e  ime around we kn
7a30: 6f 77 20 69 74 27 73 20 6e 6f 74 20 76 61 6c 69  ow it's not vali
7a40: 64 2e 20 2a 2f 0a 2b 20 20 20 20 20 20 20 20 74  d. */.+        t
7a50: 68 72 65 61 64 53 74 6f 72 61 67 65 48 61 73 68  hreadStorageHash
7a60: 54 61 62 6c 65 50 74 72 20 3d 20 4e 55 4c 4c 3b  TablePtr = NULL;
7a70: 0a 2b 0a 2b 20 20 20 20 20 20 20 20 2f 2a 20 63  .+.+        /* c
7a80: 6c 65 61 72 20 6f 75 74 20 74 68 65 20 74 68 72  lear out the thr
7a90: 65 61 64 20 73 74 6f 72 61 67 65 20 63 61 63 68  ead storage cach
7aa0: 65 20 61 73 20 77 65 6c 6c 20 2a 2f 0a 2b 20 20  e as well */.+  
7ab0: 20 20 20 20 20 20 6d 65 6d 73 65 74 28 28 57 69        memset((Wi
7ac0: 6e 54 68 72 65 61 64 53 74 6f 72 61 67 65 20 2a  nThreadStorage *
7ad0: 29 26 74 68 72 65 61 64 53 74 6f 72 61 67 65 43  )&threadStorageC
7ae0: 61 63 68 65 2c 20 30 2c 20 73 69 7a 65 6f 66 28  ache, 0, sizeof(
7af0: 57 69 6e 54 68 72 65 61 64 53 74 6f 72 61 67 65  WinThreadStorage
7b00: 29 20 2a 20 53 54 4f 52 41 47 45 5f 43 41 43 48  ) * STORAGE_CACH
7b10: 45 5f 53 4c 4f 54 53 29 3b 0a 2b 0a 2b 20 20 20  E_SLOTS);.+.+   
7b20: 20 20 20 20 20 2f 2a 20 72 65 73 65 74 20 74 68       /* reset th
7b30: 69 73 20 74 6f 20 7a 65 72 6f 2c 20 69 74 20 77  is to zero, it w
7b40: 69 6c 6c 20 62 65 20 73 65 74 20 74 6f 20 31 20  ill be set to 1 
7b50: 69 66 20 74 68 65 20 74 68 72 65 61 64 20 73 74  if the thread st
7b60: 6f 72 61 67 65 0a 2b 20 20 20 20 20 20 20 20 20  orage.+         
7b70: 20 20 73 75 62 73 79 73 74 65 6d 20 67 65 74 73    subsystem gets
7b80: 20 72 65 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a   reinitialized *
7b90: 2f 0a 2b 20 20 20 20 20 20 20 20 6e 65 78 74 54  /.+        nextT
7ba0: 68 72 65 61 64 53 74 6f 72 61 67 65 4b 65 79 20  hreadStorageKey 
7bb0: 3d 20 53 54 4f 52 41 47 45 5f 49 4e 56 41 4c 49  = STORAGE_INVALI
7bc0: 44 5f 4b 45 59 3b 0a 2b 20 20 20 20 7d 0a 2b 20  D_KEY;.+    }.+ 
7bd0: 20 20 20 53 54 4f 52 41 47 45 5f 55 4e 4c 4f 43     STORAGE_UNLOC
7be0: 4b 3b 0a 20 7d 0a 20 0c 0a 20 2f 2a 0a 40 40 20  K;. }. .. /*.@@ 
7bf0: 2d 36 34 35 2c 31 31 20 2b 31 32 38 32 2c 31 39  -645,11 +1282,19
7c00: 20 40 40 0a 20 7b 0a 20 20 20 20 20 56 4f 49 44   @@. {.     VOID
7c10: 20 2a 72 65 73 75 6c 74 3b 0a 20 20 20 20 20 44   *result;.     D
7c20: 57 4f 52 44 20 2a 69 6e 64 65 78 50 74 72 3b 0a  WORD *indexPtr;.
7c30: 2b 23 69 66 6e 64 65 66 20 54 43 4c 5f 4e 4f 5f  +#ifndef TCL_NO_
7c40: 54 4c 53 0a 20 20 20 20 20 42 4f 4f 4c 20 73 75  TLS.     BOOL su
7c50: 63 63 65 73 73 3b 0a 2b 23 65 6c 73 65 0a 2b 20  ccess;.+#else.+ 
7c60: 20 20 20 54 63 6c 5f 54 68 72 65 61 64 49 64 20     Tcl_ThreadId 
7c70: 69 64 20 3d 20 54 63 6c 5f 47 65 74 43 75 72 72  id = Tcl_GetCurr
7c80: 65 6e 74 54 68 72 65 61 64 28 29 3b 0a 2b 20 20  entThread();.+  
7c90: 20 20 54 63 6c 5f 48 61 73 68 54 61 62 6c 65 20    Tcl_HashTable 
7ca0: 2a 68 61 73 68 54 61 62 6c 65 50 74 72 3b 20 2f  *hashTablePtr; /
7cb0: 2a 20 68 61 73 68 20 74 61 62 6c 65 20 66 6f 72  * hash table for
7cc0: 20 63 75 72 72 65 6e 74 20 74 68 72 65 61 64 20   current thread 
7cd0: 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68  */.+    Tcl_Hash
7ce0: 45 6e 74 72 79 20 2a 68 50 74 72 3b 20 2f 2a 20  Entry *hPtr; /* 
7cf0: 68 61 73 68 20 65 6e 74 72 79 20 66 6f 72 20 64  hash entry for d
7d00: 61 74 61 20 6b 65 79 20 69 6e 20 63 75 72 72 65  ata key in curre
7d10: 6e 74 20 74 68 72 65 61 64 20 2a 2f 0a 2b 23 65  nt thread */.+#e
7d20: 6e 64 69 66 0a 20 0a 20 23 69 66 64 65 66 20 55  ndif. . #ifdef U
7d30: 53 45 5f 54 48 52 45 41 44 5f 41 4c 4c 4f 43 0a  SE_THREAD_ALLOC.
7d40: 20 20 20 20 20 54 63 6c 57 69 6e 46 72 65 65 41       TclWinFreeA
7d50: 6c 6c 6f 63 43 61 63 68 65 28 29 3b 0a 20 23 65  llocCache();. #e
7d60: 6e 64 69 66 0a 2b 0a 2b 23 69 66 6e 64 65 66 20  ndif.+.+#ifndef 
7d70: 54 43 4c 5f 4e 4f 5f 54 4c 53 0a 20 20 20 20 20  TCL_NO_TLS.     
7d80: 69 66 20 28 2a 6b 65 79 50 74 72 20 21 3d 20 4e  if (*keyPtr != N
7d90: 55 4c 4c 29 20 7b 0a 20 09 69 6e 64 65 78 50 74  ULL) {. .indexPt
7da0: 72 20 3d 20 2a 28 44 57 4f 52 44 20 2a 2a 29 6b  r = *(DWORD **)k
7db0: 65 79 50 74 72 3b 0a 20 09 72 65 73 75 6c 74 20  eyPtr;. .result 
7dc0: 3d 20 28 56 4f 49 44 20 2a 29 54 6c 73 47 65 74  = (VOID *)TlsGet
7dd0: 56 61 6c 75 65 28 2a 69 6e 64 65 78 50 74 72 29  Value(*indexPtr)
7de0: 3b 0a 40 40 20 2d 36 36 35 2c 36 20 2b 31 33 31  ;.@@ -665,6 +131
7df0: 30 2c 32 39 20 40 40 0a 20 20 20 20 20 20 20 20  0,29 @@.        
7e00: 20 20 20 20 20 7d 0a 20 09 7d 0a 20 20 20 20 20       }. .}.     
7e10: 7d 0a 2b 23 65 6c 73 65 0a 2b 20 20 20 20 69 66  }.+#else.+    if
7e20: 20 28 2a 6b 65 79 50 74 72 20 21 3d 20 4e 55 4c   (*keyPtr != NUL
7e30: 4c 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 69 6e  L) {.+        in
7e40: 64 65 78 50 74 72 20 3d 20 2a 28 44 57 4f 52 44  dexPtr = *(DWORD
7e50: 20 2a 2a 29 6b 65 79 50 74 72 3b 0a 2b 0a 2b 20   **)keyPtr;.+.+ 
7e60: 20 20 20 20 20 20 20 68 61 73 68 54 61 62 6c 65         hashTable
7e70: 50 74 72 20 3d 20 54 63 6c 70 54 68 72 65 61 64  Ptr = TclpThread
7e80: 53 74 6f 72 61 67 65 49 6e 69 74 28 69 64 29 3b  StorageInit(id);
7e90: 0a 2b 0a 2b 20 20 20 20 20 20 20 20 69 66 20 28  .+.+        if (
7ea0: 68 61 73 68 54 61 62 6c 65 50 74 72 20 21 3d 20  hashTablePtr != 
7eb0: 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20 20 20 20  NULL) {.+       
7ec0: 20 20 20 20 20 68 50 74 72 20 3d 20 54 63 6c 5f       hPtr = Tcl_
7ed0: 46 69 6e 64 48 61 73 68 45 6e 74 72 79 28 68 61  FindHashEntry(ha
7ee0: 73 68 54 61 62 6c 65 50 74 72 2c 20 28 63 68 61  shTablePtr, (cha
7ef0: 72 20 2a 29 2a 69 6e 64 65 78 50 74 72 29 3b 0a  r *)*indexPtr);.
7f00: 2b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 69  +.+            i
7f10: 66 20 28 68 50 74 72 20 21 3d 20 4e 55 4c 4c 29  f (hPtr != NULL)
7f20: 20 7b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20   {.+            
7f30: 20 20 20 20 72 65 73 75 6c 74 20 3d 20 54 63 6c      result = Tcl
7f40: 5f 47 65 74 48 61 73 68 56 61 6c 75 65 28 68 50  _GetHashValue(hP
7f50: 74 72 29 3b 0a 2b 0a 2b 20 20 20 20 20 20 20 20  tr);.+.+        
7f60: 20 20 20 20 20 20 20 20 69 66 20 28 72 65 73 75          if (resu
7f70: 6c 74 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20  lt != NULL) {.+ 
7f80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
7f90: 20 20 20 63 6b 66 72 65 65 28 28 63 68 61 72 20     ckfree((char 
7fa0: 2a 29 72 65 73 75 6c 74 29 3b 0a 2b 20 20 20 20  *)result);.+    
7fb0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b 0a              }.+.
7fc0: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
7fd0: 20 54 63 6c 5f 53 65 74 48 61 73 68 56 61 6c 75   Tcl_SetHashValu
7fe0: 65 28 68 50 74 72 2c 20 4e 55 4c 4c 29 3b 0a 2b  e(hPtr, NULL);.+
7ff0: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b 20              }.+ 
8000: 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a         } else {.
8010: 2b 20 20 20 20 20 20 20 20 20 20 20 20 70 61 6e  +            pan
8020: 69 63 28 22 54 63 6c 70 54 68 72 65 61 64 53 74  ic("TclpThreadSt
8030: 6f 72 61 67 65 49 6e 69 74 20 66 61 69 6c 65 64  orageInit failed
8040: 20 66 72 6f 6d 20 54 63 6c 70 46 69 6e 61 6c 69   from TclpFinali
8050: 7a 65 54 68 72 65 61 64 44 61 74 61 21 22 29 3b  zeThreadData!");
8060: 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 20 20 20  .+        }.+   
8070: 20 7d 0a 2b 23 65 6e 64 69 66 20 2f 2a 20 54 43   }.+#endif /* TC
8080: 4c 5f 4e 4f 5f 54 4c 53 20 2a 2f 0a 20 7d 0a 20  L_NO_TLS */. }. 
8090: 0c 0a 20 2f 2a 0a 40 40 20 2d 36 39 32 2c 31 36  .. /*.@@ -692,16
80a0: 20 2b 31 33 36 30 2c 35 33 20 40 40 0a 20 20 20   +1360,53 @@.   
80b0: 20 20 54 63 6c 5f 54 68 72 65 61 64 44 61 74 61    Tcl_ThreadData
80c0: 4b 65 79 20 2a 6b 65 79 50 74 72 3b 0a 20 7b 0a  Key *keyPtr;. {.
80d0: 20 20 20 20 20 44 57 4f 52 44 20 2a 69 6e 64 65       DWORD *inde
80e0: 78 50 74 72 3b 0a 2b 23 69 66 6e 64 65 66 20 54  xPtr;.+#ifndef T
80f0: 43 4c 5f 4e 4f 5f 54 4c 53 0a 20 20 20 20 20 42  CL_NO_TLS.     B
8100: 4f 4f 4c 20 73 75 63 63 65 73 73 3b 0a 20 20 20  OOL success;.   
8110: 20 20 69 66 20 28 2a 6b 65 79 50 74 72 20 21 3d    if (*keyPtr !=
8120: 20 4e 55 4c 4c 29 20 7b 0a 20 09 69 6e 64 65 78   NULL) {. .index
8130: 50 74 72 20 3d 20 2a 28 44 57 4f 52 44 20 2a 2a  Ptr = *(DWORD **
8140: 29 6b 65 79 50 74 72 3b 0a 20 09 73 75 63 63 65  )keyPtr;. .succe
8150: 73 73 20 3d 20 54 6c 73 46 72 65 65 28 2a 69 6e  ss = TlsFree(*in
8160: 64 65 78 50 74 72 29 3b 0a 2d 20 20 20 20 20 20  dexPtr);.-      
8170: 20 20 69 66 20 28 21 73 75 63 63 65 73 73 29 20    if (!success) 
8180: 7b 0a 2b 20 20 20 20 20 20 20 20 69 66 20 28 73  {.+        if (s
8190: 75 63 63 65 73 73 29 20 7b 0a 2b 20 20 20 20 20  uccess) {.+     
81a0: 20 20 20 20 20 20 20 63 6b 66 72 65 65 28 28 63         ckfree((c
81b0: 68 61 72 20 2a 29 69 6e 64 65 78 50 74 72 29 3b  har *)indexPtr);
81c0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 2a 6b  .+            *k
81d0: 65 79 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 2b 20  eyPtr = NULL;.+ 
81e0: 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a         } else {.
81f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 70 61 6e               pan
8200: 69 63 28 22 54 6c 73 46 72 65 65 20 66 61 69 6c  ic("TlsFree fail
8210: 65 64 20 66 72 6f 6d 20 54 63 6c 70 46 69 6e 61  ed from TclpFina
8220: 6c 69 7a 65 54 68 72 65 61 64 44 61 74 61 4b 65  lizeThreadDataKe
8230: 79 21 22 29 3b 0a 20 20 20 20 20 20 20 20 20 7d  y!");.         }
8240: 0a 2b 20 20 20 20 7d 0a 2b 23 65 6c 73 65 0a 2b  .+    }.+#else.+
8250: 20 20 20 20 54 63 6c 5f 48 61 73 68 54 61 62 6c      Tcl_HashTabl
8260: 65 20 2a 68 61 73 68 54 61 62 6c 65 50 74 72 3b  e *hashTablePtr;
8270: 20 2f 2a 20 68 61 73 68 20 74 61 62 6c 65 20 66   /* hash table f
8280: 6f 72 20 63 75 72 72 65 6e 74 20 74 68 72 65 61  or current threa
8290: 64 20 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 48 61  d */.+    Tcl_Ha
82a0: 73 68 53 65 61 72 63 68 20 73 65 61 72 63 68 3b  shSearch search;
82b0: 20 2f 2a 20 77 65 20 6e 65 65 64 20 74 6f 20 68   /* we need to h
82c0: 69 74 20 65 76 65 72 79 20 74 68 72 65 61 64 20  it every thread 
82d0: 77 69 74 68 20 74 68 69 73 20 73 65 61 72 63 68  with this search
82e0: 20 2a 2f 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73   */.+    Tcl_Has
82f0: 68 45 6e 74 72 79 20 2a 68 50 74 72 3b 20 2f 2a  hEntry *hPtr; /*
8300: 20 68 61 73 68 20 65 6e 74 72 79 20 66 6f 72 20   hash entry for 
8310: 63 75 72 72 65 6e 74 20 74 68 72 65 61 64 20 69  current thread i
8320: 6e 20 6d 61 73 74 65 72 20 74 61 62 6c 65 20 2a  n master table *
8330: 2f 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68 45  /.+    Tcl_HashE
8340: 6e 74 72 79 20 2a 68 44 61 74 61 50 74 72 3b 20  ntry *hDataPtr; 
8350: 2f 2a 20 68 61 73 68 20 65 6e 74 72 79 20 66 6f  /* hash entry fo
8360: 72 20 64 61 74 61 20 6b 65 79 20 69 6e 20 63 75  r data key in cu
8370: 72 72 65 6e 74 20 74 68 72 65 61 64 20 2a 2f 0a  rrent thread */.
8380: 2b 0a 2b 20 20 20 20 69 66 20 28 2a 6b 65 79 50  +.+    if (*keyP
8390: 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20  tr != NULL) {.+ 
83a0: 20 20 20 20 20 20 20 69 6e 64 65 78 50 74 72 20         indexPtr 
83b0: 3d 20 2a 28 44 57 4f 52 44 20 2a 2a 29 6b 65 79  = *(DWORD **)key
83c0: 50 74 72 3b 0a 2b 0a 2b 20 20 20 20 20 20 20 20  Ptr;.+.+        
83d0: 53 54 4f 52 41 47 45 5f 4c 4f 43 4b 3b 0a 2b 20  STORAGE_LOCK;.+ 
83e0: 20 20 20 20 20 20 20 69 66 20 28 74 68 72 65 61         if (threa
83f0: 64 53 74 6f 72 61 67 65 48 61 73 68 54 61 62 6c  dStorageHashTabl
8400: 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  ePtr != NULL) {.
8410: 2b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20  +            /* 
8420: 77 65 20 61 72 65 20 67 6f 69 6e 67 20 74 6f 20  we are going to 
8430: 64 65 6c 65 74 65 20 74 68 65 20 73 70 65 63 69  delete the speci
8440: 66 69 65 64 20 64 61 74 61 20 6b 65 79 20 65 6e  fied data key en
8450: 74 72 79 20 66 72 6f 6d 20 65 76 65 72 79 20 74  try from every t
8460: 68 72 65 61 64 2e 20 2a 2f 0a 2b 20 20 20 20 20  hread. */.+     
8470: 20 20 20 20 20 20 20 66 6f 72 20 28 68 50 74 72         for (hPtr
8480: 20 3d 20 54 63 6c 5f 46 69 72 73 74 48 61 73 68   = Tcl_FirstHash
8490: 45 6e 74 72 79 28 74 68 72 65 61 64 53 74 6f 72  Entry(threadStor
84a0: 61 67 65 48 61 73 68 54 61 62 6c 65 50 74 72 2c  ageHashTablePtr,
84b0: 20 26 73 65 61 72 63 68 29 3b 0a 2b 20 20 20 20   &search);.+    
84c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
84d0: 68 50 74 72 20 21 3d 20 4e 55 4c 4c 3b 20 68 50  hPtr != NULL; hP
84e0: 74 72 20 3d 20 54 63 6c 5f 4e 65 78 74 48 61 73  tr = Tcl_NextHas
84f0: 68 45 6e 74 72 79 28 26 73 65 61 72 63 68 29 29  hEntry(&search))
8500: 20 7b 0a 2b 0a 2b 20 20 20 20 20 20 20 20 20 20   {.+.+          
8510: 20 20 20 20 20 20 2f 2a 20 67 65 74 20 74 68 65        /* get the
8520: 20 68 61 73 68 20 74 61 62 6c 65 20 63 6f 72 72   hash table corr
8530: 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 74 68 65  esponding to the
8540: 20 74 68 72 65 61 64 20 69 6e 20 71 75 65 73 74   thread in quest
8550: 69 6f 6e 2e 20 2a 2f 0a 2b 20 20 20 20 20 20 20  ion. */.+       
8560: 20 20 20 20 20 20 20 20 20 68 61 73 68 54 61 62           hashTab
8570: 6c 65 50 74 72 20 3d 20 54 63 6c 5f 47 65 74 48  lePtr = Tcl_GetH
8580: 61 73 68 56 61 6c 75 65 28 68 50 74 72 29 3b 0a  ashValue(hPtr);.
8590: 2b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20  +.+             
85a0: 20 20 20 69 66 20 28 68 61 73 68 54 61 62 6c 65     if (hashTable
85b0: 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b  Ptr != NULL) {.+
85c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
85d0: 20 20 20 20 2f 2a 20 6e 6f 77 20 66 69 6e 64 20      /* now find 
85e0: 74 68 65 20 65 6e 74 72 79 20 66 6f 72 20 74 68  the entry for th
85f0: 65 20 73 70 65 63 69 66 69 65 64 20 64 61 74 61  e specified data
8600: 20 6b 65 79 2e 20 2a 2f 0a 2b 20 20 20 20 20 20   key. */.+      
8610: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 68 44                hD
8620: 61 74 61 50 74 72 20 3d 20 54 63 6c 5f 46 69 6e  ataPtr = Tcl_Fin
8630: 64 48 61 73 68 45 6e 74 72 79 28 68 61 73 68 54  dHashEntry(hashT
8640: 61 62 6c 65 50 74 72 2c 20 28 63 68 61 72 20 2a  ablePtr, (char *
8650: 29 2a 69 6e 64 65 78 50 74 72 29 3b 0a 2b 0a 2b  )*indexPtr);.+.+
8660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
8670: 20 20 20 20 69 66 20 28 68 44 61 74 61 50 74 72      if (hDataPtr
8680: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20   != NULL) {.+   
8690: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
86a0: 20 20 20 20 20 2f 2a 20 64 65 6c 65 74 65 20 74       /* delete t
86b0: 68 65 20 64 61 74 61 20 6b 65 79 20 66 6f 72 20  he data key for 
86c0: 74 68 69 73 20 74 68 72 65 61 64 2e 20 2a 2f 0a  this thread. */.
86d0: 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  +               
86e0: 20 20 20 20 20 20 20 20 20 54 63 6c 5f 44 65 6c           Tcl_Del
86f0: 65 74 65 48 61 73 68 45 6e 74 72 79 28 68 44 61  eteHashEntry(hDa
8700: 74 61 50 74 72 29 3b 0a 2b 20 20 20 20 20 20 20  taPtr);.+       
8710: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b               }.+
8720: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
8730: 7d 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 7d  }.+            }
8740: 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 20 20 20  .+        }.+   
8750: 20 20 20 20 20 53 54 4f 52 41 47 45 5f 55 4e 4c       STORAGE_UNL
8760: 4f 43 4b 3b 0a 2b 0a 20 09 63 6b 66 72 65 65 28  OCK;.+. .ckfree(
8770: 28 63 68 61 72 20 2a 29 69 6e 64 65 78 50 74 72  (char *)indexPtr
8780: 29 3b 0a 20 09 2a 6b 65 79 50 74 72 20 3d 20 4e  );. .*keyPtr = N
8790: 55 4c 4c 3b 0a 20 20 20 20 20 7d 0a 2b 23 65 6e  ULL;.     }.+#en
87a0: 64 69 66 0a 20 7d 0a 20 0c 0a 20 2f 2a 0a 40 40  dif. }. .. /*.@@
87b0: 20 2d 31 30 30 35 2c 37 20 2b 31 37 31 30 2c 31   -1005,7 +1710,1
87c0: 36 20 40 40 0a 20 20 2a 20 41 64 64 69 74 69 6f  6 @@.  * Additio
87d0: 6e 73 20 62 79 20 41 4f 4c 20 66 6f 72 20 73 70  ns by AOL for sp
87e0: 65 63 69 61 6c 69 7a 65 64 20 74 68 72 65 61 64  ecialized thread
87f0: 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 6f   memory allocato
8800: 72 2e 0a 20 20 2a 2f 0a 20 23 69 66 64 65 66 20  r..  */. #ifdef 
8810: 55 53 45 5f 54 48 52 45 41 44 5f 41 4c 4c 4f 43  USE_THREAD_ALLOC
8820: 0a 2d 73 74 61 74 69 63 20 44 57 4f 52 44 20 6b  .-static DWORD k
8830: 65 79 3b 0a 2b 73 74 61 74 69 63 20 69 6e 74 20  ey;.+static int 
8840: 69 6e 69 74 54 68 72 65 61 64 41 6c 6c 6f 63 20  initThreadAlloc 
8850: 3d 20 30 3b 0a 2b 0a 2b 23 69 66 6e 64 65 66 20  = 0;.+.+#ifndef 
8860: 54 43 4c 5f 4e 4f 5f 54 4c 53 0a 2b 23 64 65 66  TCL_NO_TLS.+#def
8870: 69 6e 65 20 54 48 52 45 41 44 5f 41 4c 4c 4f 43  ine THREAD_ALLOC
8880: 5f 42 41 44 5f 4b 45 59 20 20 20 20 54 4c 53 5f  _BAD_KEY    TLS_
8890: 4f 55 54 5f 4f 46 5f 49 4e 44 45 58 45 53 0a 2b  OUT_OF_INDEXES.+
88a0: 23 65 6c 73 65 0a 2b 23 64 65 66 69 6e 65 20 54  #else.+#define T
88b0: 48 52 45 41 44 5f 41 4c 4c 4f 43 5f 42 41 44 5f  HREAD_ALLOC_BAD_
88c0: 4b 45 59 20 20 20 20 53 54 4f 52 41 47 45 5f 49  KEY    STORAGE_I
88d0: 4e 56 41 4c 49 44 5f 4b 45 59 0a 2b 23 65 6e 64  NVALID_KEY.+#end
88e0: 69 66 0a 2b 0a 2b 2f 2a 20 73 65 74 20 74 6f 20  if.+.+/* set to 
88f0: 61 6e 20 69 6e 76 61 6c 69 64 20 76 61 6c 75 65  an invalid value
8900: 20 66 6f 72 20 61 20 74 68 72 65 61 64 20 5b 6c   for a thread [l
8910: 6f 63 61 6c 5d 20 73 74 6f 72 61 67 65 20 69 6e  ocal] storage in
8920: 64 65 78 20 2a 2f 0a 2b 73 74 61 74 69 63 20 44  dex */.+static D
8930: 57 4f 52 44 20 6b 65 79 20 3d 20 54 48 52 45 41  WORD key = THREA
8940: 44 5f 41 4c 4c 4f 43 5f 42 41 44 5f 4b 45 59 3b  D_ALLOC_BAD_KEY;
8950: 0a 20 0a 20 54 63 6c 5f 4d 75 74 65 78 20 2a 0a  . . Tcl_Mutex *.
8960: 20 54 63 6c 70 4e 65 77 41 6c 6c 6f 63 4d 75 74   TclpNewAllocMut
8970: 65 78 28 76 6f 69 64 29 0a 40 40 20 2d 31 30 32  ex(void).@@ -102
8980: 37 2c 35 37 20 2b 31 37 34 31 2c 31 37 34 20 40  7,57 +1741,174 @
8990: 40 0a 20 76 6f 69 64 20 2a 0a 20 54 63 6c 70 47  @. void *. TclpG
89a0: 65 74 41 6c 6c 6f 63 43 61 63 68 65 28 76 6f 69  etAllocCache(voi
89b0: 64 29 0a 20 7b 0a 2d 20 20 20 20 73 74 61 74 69  d). {.-    stati
89c0: 63 20 69 6e 74 20 6f 6e 63 65 20 3d 20 30 3b 0a  c int once = 0;.
89d0: 20 20 20 20 20 56 4f 49 44 20 2a 72 65 73 75 6c       VOID *resul
89e0: 74 3b 0a 2d 0a 2d 20 20 20 20 69 66 20 28 21 6f  t;.-.-    if (!o
89f0: 6e 63 65 29 20 7b 0a 2b 23 69 66 6e 64 65 66 20  nce) {.+#ifndef 
8a00: 54 43 4c 5f 54 48 52 45 41 44 5f 41 4c 4c 4f 43  TCL_THREAD_ALLOC
8a10: 5f 4e 4f 5f 54 4c 53 0a 2b 20 20 20 20 69 66 20  _NO_TLS.+    if 
8a20: 28 21 69 6e 69 74 54 68 72 65 61 64 41 6c 6c 6f  (!initThreadAllo
8a30: 63 29 20 7b 0a 20 09 2f 2a 0a 20 09 20 2a 20 57  c) {. ./*. . * W
8a40: 65 20 6e 65 65 64 20 74 6f 20 6d 61 6b 65 20 73  e need to make s
8a50: 75 72 65 20 74 68 61 74 20 54 63 6c 57 69 6e 46  ure that TclWinF
8a60: 72 65 65 41 6c 6c 6f 63 43 61 63 68 65 20 69 73  reeAllocCache is
8a70: 20 63 61 6c 6c 65 64 0a 20 09 20 2a 20 6f 6e 20   called. . * on 
8a80: 65 61 63 68 20 74 68 72 65 61 64 20 74 68 61 74  each thread that
8a90: 20 63 61 6c 6c 73 20 74 68 69 73 2c 20 62 75 74   calls this, but
8aa0: 20 6f 6e 6c 79 20 6f 6e 20 74 68 72 65 61 64 73   only on threads
8ab0: 20 74 68 61 74 0a 20 09 20 2a 20 63 61 6c 6c 20   that. . * call 
8ac0: 74 68 69 73 2e 0a 20 09 20 2a 2f 0a 20 20 20 20  this.. . */.    
8ad0: 20 09 6b 65 79 20 3d 20 54 6c 73 41 6c 6c 6f 63   .key = TlsAlloc
8ae0: 28 29 3b 0a 2d 09 6f 6e 63 65 20 3d 20 31 3b 0a  ();.-.once = 1;.
8af0: 2d 09 69 66 20 28 6b 65 79 20 3d 3d 20 54 4c 53  -.if (key == TLS
8b00: 5f 4f 55 54 5f 4f 46 5f 49 4e 44 45 58 45 53 29  _OUT_OF_INDEXES)
8b10: 20 7b 0a 2b 20 20 20 20 20 20 20 20 69 66 20 28   {.+        if (
8b20: 6b 65 79 20 21 3d 20 54 4c 53 5f 4f 55 54 5f 4f  key != TLS_OUT_O
8b30: 46 5f 49 4e 44 45 58 45 53 29 20 7b 0a 2b 20 20  F_INDEXES) {.+  
8b40: 20 20 20 20 20 20 20 20 20 20 69 6e 69 74 54 68            initTh
8b50: 72 65 61 64 41 6c 6c 6f 63 20 3d 20 31 3b 0a 2b  readAlloc = 1;.+
8b60: 20 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b          } else {
8b70: 0a 20 09 20 20 20 20 70 61 6e 69 63 28 22 63 6f  . .    panic("co
8b80: 75 6c 64 20 6e 6f 74 20 61 6c 6c 6f 63 61 74 65  uld not allocate
8b90: 20 74 68 72 65 61 64 20 6c 6f 63 61 6c 20 73 74   thread local st
8ba0: 6f 72 61 67 65 22 29 3b 0a 20 09 7d 0a 20 20 20  orage");. .}.   
8bb0: 20 20 7d 0a 20 0a 2b 20 20 20 20 69 66 20 28 6b    }. .+    if (k
8bc0: 65 79 20 21 3d 20 54 4c 53 5f 4f 55 54 5f 4f 46  ey != TLS_OUT_OF
8bd0: 5f 49 4e 44 45 58 45 53 29 20 7b 0a 20 20 20 20  _INDEXES) {.    
8be0: 20 72 65 73 75 6c 74 20 3d 20 54 6c 73 47 65 74   result = TlsGet
8bf0: 56 61 6c 75 65 28 6b 65 79 29 3b 0a 20 20 20 20  Value(key);.    
8c00: 20 69 66 20 28 28 72 65 73 75 6c 74 20 3d 3d 20   if ((result == 
8c10: 4e 55 4c 4c 29 20 26 26 20 28 47 65 74 4c 61 73  NULL) && (GetLas
8c20: 74 45 72 72 6f 72 28 29 20 21 3d 20 4e 4f 5f 45  tError() != NO_E
8c30: 52 52 4f 52 29 29 20 7b 0a 20 20 20 20 20 20 20  RROR)) {.       
8c40: 20 20 70 61 6e 69 63 28 22 54 6c 73 47 65 74 56    panic("TlsGetV
8c50: 61 6c 75 65 20 66 61 69 6c 65 64 20 66 72 6f 6d  alue failed from
8c60: 20 54 63 6c 70 47 65 74 41 6c 6c 6f 63 43 61 63   TclpGetAllocCac
8c70: 68 65 21 22 29 3b 0a 20 20 20 20 20 7d 0a 2b 20  he!");.     }.+ 
8c80: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20     } else {.+   
8c90: 20 20 20 20 20 72 65 73 75 6c 74 20 3d 20 4e 55       result = NU
8ca0: 4c 4c 3b 0a 2b 20 20 20 20 7d 0a 2b 23 65 6c 73  LL;.+    }.+#els
8cb0: 65 0a 2b 20 20 20 20 54 63 6c 5f 54 68 72 65 61  e.+    Tcl_Threa
8cc0: 64 49 64 20 69 64 20 3d 20 54 63 6c 5f 47 65 74  dId id = Tcl_Get
8cd0: 43 75 72 72 65 6e 74 54 68 72 65 61 64 28 29 3b  CurrentThread();
8ce0: 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68 54 61  .+    Tcl_HashTa
8cf0: 62 6c 65 20 2a 68 61 73 68 54 61 62 6c 65 50 74  ble *hashTablePt
8d00: 72 3b 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68  r;.+    Tcl_Hash
8d10: 45 6e 74 72 79 20 2a 68 50 74 72 3b 0a 2b 20 20  Entry *hPtr;.+  
8d20: 20 20 69 6e 74 20 6e 65 77 3b 0a 2b 0a 2b 20 20    int new;.+.+  
8d30: 20 20 68 61 73 68 54 61 62 6c 65 50 74 72 20 3d    hashTablePtr =
8d40: 20 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61   TclpThreadStora
8d50: 67 65 49 6e 69 74 28 69 64 29 3b 0a 2b 0a 2b 20  geInit(id);.+.+ 
8d60: 20 20 20 69 66 20 28 21 69 6e 69 74 54 68 72 65     if (!initThre
8d70: 61 64 41 6c 6c 6f 63 29 20 7b 0a 2b 20 20 20 20  adAlloc) {.+    
8d80: 20 20 20 20 53 54 4f 52 41 47 45 5f 4c 4f 43 4b      STORAGE_LOCK
8d90: 3b 0a 2b 20 20 20 20 20 20 20 20 2f 2a 0a 2b 20  ;.+        /*.+ 
8da0: 20 20 20 20 20 20 20 20 2a 20 54 68 69 73 20 6d          * This m
8db0: 75 73 74 20 62 65 20 61 66 74 65 72 20 63 61 6c  ust be after cal
8dc0: 6c 20 74 6f 20 54 63 6c 70 54 68 72 65 61 64 53  l to TclpThreadS
8dd0: 74 6f 72 61 67 65 49 6e 69 74 2c 0a 2b 20 20 20  torageInit,.+   
8de0: 20 20 20 20 20 20 2a 20 6f 74 68 65 72 77 69 73        * otherwis
8df0: 65 20 6e 65 78 74 54 68 72 65 61 64 53 74 6f 72  e nextThreadStor
8e00: 61 67 65 4b 65 79 20 6d 61 79 20 6e 6f 74 20 68  ageKey may not h
8e10: 61 76 65 20 62 65 65 6e 20 69 6e 69 74 69 61 6c  ave been initial
8e20: 69 7a 65 64 2e 0a 2b 20 20 20 20 20 20 20 20 20  ized..+         
8e30: 2a 2f 0a 2b 20 20 20 20 20 20 20 20 6b 65 79 20  */.+        key 
8e40: 3d 20 6e 65 78 74 54 68 72 65 61 64 53 74 6f 72  = nextThreadStor
8e50: 61 67 65 4b 65 79 2b 2b 3b 0a 2b 20 20 20 20 20  ageKey++;.+     
8e60: 20 20 20 53 54 4f 52 41 47 45 5f 55 4e 4c 4f 43     STORAGE_UNLOC
8e70: 4b 3b 0a 2b 20 20 20 20 20 20 20 20 69 6e 69 74  K;.+        init
8e80: 54 68 72 65 61 64 41 6c 6c 6f 63 20 3d 20 31 3b  ThreadAlloc = 1;
8e90: 0a 2b 20 20 20 20 7d 0a 2b 0a 2b 20 20 20 20 69  .+    }.+.+    i
8ea0: 66 20 28 68 61 73 68 54 61 62 6c 65 50 74 72 20  f (hashTablePtr 
8eb0: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20  != NULL) {.+    
8ec0: 20 20 20 20 68 50 74 72 20 3d 20 54 63 6c 5f 46      hPtr = Tcl_F
8ed0: 69 6e 64 48 61 73 68 45 6e 74 72 79 28 68 61 73  indHashEntry(has
8ee0: 68 54 61 62 6c 65 50 74 72 2c 20 28 63 68 61 72  hTablePtr, (char
8ef0: 20 2a 29 6b 65 79 29 3b 0a 2b 0a 2b 20 20 20 20   *)key);.+.+    
8f00: 20 20 20 20 69 66 20 28 68 50 74 72 20 21 3d 20      if (hPtr != 
8f10: 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20 20 20 20  NULL) {.+       
8f20: 20 20 20 20 20 2f 2a 20 72 65 74 75 72 6e 20 74       /* return t
8f30: 68 65 20 76 61 6c 75 65 20 66 6f 72 20 74 68 69  he value for thi
8f40: 73 20 74 68 72 65 61 64 20 2a 2f 0a 2b 20 20 20  s thread */.+   
8f50: 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 20           result 
8f60: 3d 20 54 63 6c 5f 47 65 74 48 61 73 68 56 61 6c  = Tcl_GetHashVal
8f70: 75 65 28 68 50 74 72 29 3b 0a 2b 20 20 20 20 20  ue(hPtr);.+     
8f80: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20     } else {.+   
8f90: 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 20           result 
8fa0: 3d 20 4e 55 4c 4c 3b 0a 2b 0a 2b 20 20 20 20 20  = NULL;.+.+     
8fb0: 20 20 20 20 20 20 20 2f 2a 20 6e 6f 77 20 63 72         /* now cr
8fc0: 65 61 74 65 20 74 68 65 20 74 68 72 65 61 64 20  eate the thread 
8fd0: 73 74 6f 72 61 67 65 20 69 6e 64 65 78 20 66 6f  storage index fo
8fe0: 72 20 74 68 69 73 20 74 68 72 65 61 64 20 2a 2f  r this thread */
8ff0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 68 50  .+            hP
9000: 74 72 20 3d 20 54 63 6c 5f 43 72 65 61 74 65 48  tr = Tcl_CreateH
9010: 61 73 68 45 6e 74 72 79 28 68 61 73 68 54 61 62  ashEntry(hashTab
9020: 6c 65 50 74 72 2c 20 28 63 68 61 72 20 2a 29 6b  lePtr, (char *)k
9030: 65 79 2c 20 26 6e 65 77 29 3b 0a 2b 0a 2b 20 20  ey, &new);.+.+  
9040: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 68 50            if (hP
9050: 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20  tr != NULL) {.+ 
9060: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f                 /
9070: 2a 20 69 6e 69 74 69 61 6c 6c 79 2c 20 73 65 74  * initially, set
9080: 20 74 6f 20 4e 55 4c 4c 20 2a 2f 0a 2b 20 20 20   to NULL */.+   
9090: 20 20 20 20 20 20 20 20 20 20 20 20 20 54 63 6c               Tcl
90a0: 5f 53 65 74 48 61 73 68 56 61 6c 75 65 28 68 50  _SetHashValue(hP
90b0: 74 72 2c 20 4e 55 4c 4c 29 3b 0a 2b 20 20 20 20  tr, NULL);.+    
90c0: 20 20 20 20 20 20 20 20 7d 20 65 6c 73 65 20 7b          } else {
90d0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .+              
90e0: 20 20 70 61 6e 69 63 28 22 54 63 6c 5f 43 72 65    panic("Tcl_Cre
90f0: 61 74 65 48 61 73 68 45 6e 74 72 79 20 66 61 69  ateHashEntry fai
9100: 6c 65 64 20 66 72 6f 6d 20 54 63 6c 70 47 65 74  led from TclpGet
9110: 41 6c 6c 6f 63 43 61 63 68 65 21 22 29 3b 0a 2b  AllocCache!");.+
9120: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 2b 20              }.+ 
9130: 20 20 20 20 20 20 20 7d 0a 2b 20 20 20 20 7d 20         }.+    } 
9140: 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20 20 20  else {.+        
9150: 70 61 6e 69 63 28 22 54 63 6c 70 54 68 72 65 61  panic("TclpThrea
9160: 64 53 74 6f 72 61 67 65 49 6e 69 74 20 66 61 69  dStorageInit fai
9170: 6c 65 64 20 66 72 6f 6d 20 54 63 6c 70 47 65 74  led from TclpGet
9180: 41 6c 6c 6f 63 43 61 63 68 65 21 22 29 3b 0a 2b  AllocCache!");.+
9190: 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 20 3d          result =
91a0: 20 4e 55 4c 4c 3b 0a 2b 20 20 20 20 7d 0a 2b 23   NULL;.+    }.+#
91b0: 65 6e 64 69 66 0a 20 20 20 20 20 72 65 74 75 72  endif.     retur
91c0: 6e 20 72 65 73 75 6c 74 3b 0a 20 7d 0a 20 0a 20  n result;. }. . 
91d0: 76 6f 69 64 0a 20 54 63 6c 70 53 65 74 41 6c 6c  void. TclpSetAll
91e0: 6f 63 43 61 63 68 65 28 76 6f 69 64 20 2a 70 74  ocCache(void *pt
91f0: 72 29 0a 20 7b 0a 2b 23 69 66 6e 64 65 66 20 54  r). {.+#ifndef T
9200: 43 4c 5f 54 48 52 45 41 44 5f 41 4c 4c 4f 43 5f  CL_THREAD_ALLOC_
9210: 4e 4f 5f 54 4c 53 0a 20 20 20 20 20 42 4f 4f 4c  NO_TLS.     BOOL
9220: 20 73 75 63 63 65 73 73 3b 0a 20 20 20 20 20 73   success;.     s
9230: 75 63 63 65 73 73 20 3d 20 54 6c 73 53 65 74 56  uccess = TlsSetV
9240: 61 6c 75 65 28 6b 65 79 2c 20 70 74 72 29 3b 0a  alue(key, ptr);.
9250: 20 20 20 20 20 69 66 20 28 21 73 75 63 63 65 73       if (!succes
9260: 73 29 20 7b 0a 20 20 20 20 20 20 20 20 20 70 61  s) {.         pa
9270: 6e 69 63 28 22 54 6c 73 53 65 74 56 61 6c 75 65  nic("TlsSetValue
9280: 20 66 61 69 6c 65 64 20 66 72 6f 6d 20 54 63 6c   failed from Tcl
9290: 70 53 65 74 41 6c 6c 6f 63 43 61 63 68 65 21 22  pSetAllocCache!"
92a0: 29 3b 0a 20 20 20 20 20 7d 0a 2b 23 65 6c 73 65  );.     }.+#else
92b0: 0a 2b 20 20 20 20 54 63 6c 5f 54 68 72 65 61 64  .+    Tcl_Thread
92c0: 49 64 20 69 64 20 3d 20 54 63 6c 5f 47 65 74 43  Id id = Tcl_GetC
92d0: 75 72 72 65 6e 74 54 68 72 65 61 64 28 29 3b 0a  urrentThread();.
92e0: 2b 20 20 20 20 54 63 6c 5f 48 61 73 68 54 61 62  +    Tcl_HashTab
92f0: 6c 65 20 2a 68 61 73 68 54 61 62 6c 65 50 74 72  le *hashTablePtr
9300: 3b 0a 2b 20 20 20 20 54 63 6c 5f 48 61 73 68 45  ;.+    Tcl_HashE
9310: 6e 74 72 79 20 2a 68 50 74 72 3b 0a 2b 0a 2b 20  ntry *hPtr;.+.+ 
9320: 20 20 20 68 61 73 68 54 61 62 6c 65 50 74 72 20     hashTablePtr 
9330: 3d 20 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72  = TclpThreadStor
9340: 61 67 65 49 6e 69 74 28 69 64 29 3b 0a 2b 0a 2b  ageInit(id);.+.+
9350: 20 20 20 20 69 66 20 28 68 61 73 68 54 61 62 6c      if (hashTabl
9360: 65 50 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  ePtr != NULL) {.
9370: 2b 20 20 20 20 20 20 20 20 68 50 74 72 20 3d 20  +        hPtr = 
9380: 54 63 6c 5f 46 69 6e 64 48 61 73 68 45 6e 74 72  Tcl_FindHashEntr
9390: 79 28 68 61 73 68 54 61 62 6c 65 50 74 72 2c 20  y(hashTablePtr, 
93a0: 28 63 68 61 72 20 2a 29 6b 65 79 29 3b 0a 2b 0a  (char *)key);.+.
93b0: 2b 20 20 20 20 20 20 20 20 69 66 20 28 68 50 74  +        if (hPt
93c0: 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20  r != NULL) {.+  
93d0: 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f 53 65            Tcl_Se
93e0: 74 48 61 73 68 56 61 6c 75 65 28 68 50 74 72 2c  tHashValue(hPtr,
93f0: 20 70 74 72 29 3b 0a 2b 20 20 20 20 20 20 20 20   ptr);.+        
9400: 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20 20 20 20  } else {.+      
9410: 20 20 20 20 20 20 2f 2a 0a 2b 20 20 20 20 20 20        /*.+      
9420: 20 20 20 20 20 20 20 2a 20 54 68 69 73 20 6d 61         * This ma
9430: 79 20 69 6e 64 69 63 61 74 65 20 61 6e 20 65 72  y indicate an er
9440: 72 6f 72 20 62 79 20 74 68 65 20 63 61 6c 6c 65  ror by the calle
9450: 72 2c 20 74 68 65 79 20 73 68 6f 75 6c 64 20 68  r, they should h
9460: 61 76 65 0a 2b 20 20 20 20 20 20 20 20 20 20 20  ave.+           
9470: 20 20 2a 20 63 61 6c 6c 65 64 20 54 63 6c 70 47    * called TclpG
9480: 65 74 41 6c 6c 6f 63 43 61 63 68 65 20 70 72 69  etAllocCache pri
9490: 6f 72 20 74 6f 20 63 61 6c 6c 69 6e 67 20 74 68  or to calling th
94a0: 69 73 20 66 75 6e 63 74 69 6f 6e 2e 0a 2b 20 20  is function..+  
94b0: 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 2b 20             */.+ 
94c0: 20 20 20 20 20 20 20 20 20 20 20 70 61 6e 69 63             panic
94d0: 28 22 63 6f 75 6c 64 20 6e 6f 74 20 66 69 6e 64  ("could not find
94e0: 20 74 68 72 65 61 64 20 61 6c 6c 6f 63 20 68 61   thread alloc ha
94f0: 73 68 20 65 6e 74 72 79 20 66 72 6f 6d 20 54 63  sh entry from Tc
9500: 6c 70 53 65 74 41 6c 6c 6f 63 43 61 63 68 65 22  lpSetAllocCache"
9510: 29 3b 0a 2b 20 20 20 20 20 20 20 20 7d 0a 2b 20  );.+        }.+ 
9520: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20     } else {.+   
9530: 20 20 20 20 20 70 61 6e 69 63 28 22 54 63 6c 70       panic("Tclp
9540: 54 68 72 65 61 64 53 74 6f 72 61 67 65 49 6e 69  ThreadStorageIni
9550: 74 20 66 61 69 6c 65 64 20 66 72 6f 6d 20 54 63  t failed from Tc
9560: 6c 70 53 65 74 41 6c 6c 6f 63 43 61 63 68 65 21  lpSetAllocCache!
9570: 22 29 3b 0a 2b 20 20 20 20 7d 0a 2b 23 65 6e 64  ");.+    }.+#end
9580: 69 66 0a 20 7d 0a 20 0a 20 76 6f 69 64 0a 20 54  if. }. . void. T
9590: 63 6c 57 69 6e 46 72 65 65 41 6c 6c 6f 63 43 61  clWinFreeAllocCa
95a0: 63 68 65 28 76 6f 69 64 29 0a 20 7b 0a 20 20 20  che(void). {.   
95b0: 20 20 76 6f 69 64 20 2a 70 74 72 3b 0a 2b 23 69    void *ptr;.+#i
95c0: 66 6e 64 65 66 20 54 43 4c 5f 54 48 52 45 41 44  fndef TCL_THREAD
95d0: 5f 41 4c 4c 4f 43 5f 4e 4f 5f 54 4c 53 0a 20 20  _ALLOC_NO_TLS.  
95e0: 20 20 20 42 4f 4f 4c 20 73 75 63 63 65 73 73 3b     BOOL success;
95f0: 0a 2d 0a 20 20 20 20 20 70 74 72 20 3d 20 54 6c  .-.     ptr = Tl
9600: 73 47 65 74 56 61 6c 75 65 28 6b 65 79 29 3b 0a  sGetValue(key);.
9610: 20 20 20 20 20 69 66 20 28 70 74 72 20 21 3d 20       if (ptr != 
9620: 4e 55 4c 4c 29 20 7b 0a 20 09 73 75 63 63 65 73  NULL) {. .succes
9630: 73 20 3d 20 54 6c 73 53 65 74 56 61 6c 75 65 28  s = TlsSetValue(
9640: 6b 65 79 2c 20 4e 55 4c 4c 29 3b 0a 2d 20 20 20  key, NULL);.-   
9650: 20 20 20 20 20 69 66 20 28 21 73 75 63 63 65 73       if (!succes
9660: 73 29 20 7b 0a 2b 20 20 20 20 20 20 20 20 69 66  s) {.+        if
9670: 20 28 73 75 63 63 65 73 73 29 20 7b 0a 2b 20 20   (success) {.+  
9680: 20 20 20 20 20 20 20 20 20 20 54 63 6c 46 72 65            TclFre
9690: 65 41 6c 6c 6f 63 43 61 63 68 65 28 70 74 72 29  eAllocCache(ptr)
96a0: 3b 0a 2b 20 20 20 20 20 20 20 20 7d 20 65 6c 73  ;.+        } els
96b0: 65 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20  e {.            
96c0: 20 70 61 6e 69 63 28 22 54 6c 73 53 65 74 56 61   panic("TlsSetVa
96d0: 6c 75 65 20 66 61 69 6c 65 64 20 66 72 6f 6d 20  lue failed from 
96e0: 54 63 6c 57 69 6e 46 72 65 65 41 6c 6c 6f 63 43  TclWinFreeAllocC
96f0: 61 63 68 65 21 22 29 3b 0a 20 20 20 20 20 20 20  ache!");.       
9700: 20 20 7d 0a 2d 09 54 63 6c 46 72 65 65 41 6c 6c    }.-.TclFreeAll
9710: 6f 63 43 61 63 68 65 28 70 74 72 29 3b 0a 20 20  ocCache(ptr);.  
9720: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20     } else {.    
9730: 20 20 20 69 66 20 28 47 65 74 4c 61 73 74 45 72     if (GetLastEr
9740: 72 6f 72 28 29 20 21 3d 20 4e 4f 5f 45 52 52 4f  ror() != NO_ERRO
9750: 52 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20  R) {.           
9760: 70 61 6e 69 63 28 22 54 6c 73 47 65 74 56 61 6c  panic("TlsGetVal
9770: 75 65 20 66 61 69 6c 65 64 20 66 72 6f 6d 20 54  ue failed from T
9780: 63 6c 57 69 6e 46 72 65 65 41 6c 6c 6f 63 43 61  clWinFreeAllocCa
9790: 63 68 65 21 22 29 3b 0a 20 20 20 20 20 20 20 7d  che!");.       }
97a0: 0a 20 20 20 20 20 7d 0a 2b 23 65 6c 73 65 0a 2b  .     }.+#else.+
97b0: 20 20 20 20 54 63 6c 5f 54 68 72 65 61 64 49 64      Tcl_ThreadId
97c0: 20 69 64 20 3d 20 54 63 6c 5f 47 65 74 43 75 72   id = Tcl_GetCur
97d0: 72 65 6e 74 54 68 72 65 61 64 28 29 3b 0a 2b 20  rentThread();.+ 
97e0: 20 20 20 54 63 6c 5f 48 61 73 68 54 61 62 6c 65     Tcl_HashTable
97f0: 20 2a 68 61 73 68 54 61 62 6c 65 50 74 72 3b 0a   *hashTablePtr;.
9800: 2b 20 20 20 20 54 63 6c 5f 48 61 73 68 45 6e 74  +    Tcl_HashEnt
9810: 72 79 20 2a 68 50 74 72 3b 0a 2b 0a 2b 20 20 20  ry *hPtr;.+.+   
9820: 20 68 61 73 68 54 61 62 6c 65 50 74 72 20 3d 20   hashTablePtr = 
9830: 54 63 6c 70 54 68 72 65 61 64 53 74 6f 72 61 67  TclpThreadStorag
9840: 65 49 6e 69 74 28 69 64 29 3b 0a 2b 0a 2b 20 20  eInit(id);.+.+  
9850: 20 20 69 66 20 28 68 61 73 68 54 61 62 6c 65 50    if (hashTableP
9860: 74 72 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20  tr != NULL) {.+ 
9870: 20 20 20 20 20 20 20 68 50 74 72 20 3d 20 54 63         hPtr = Tc
9880: 6c 5f 46 69 6e 64 48 61 73 68 45 6e 74 72 79 28  l_FindHashEntry(
9890: 68 61 73 68 54 61 62 6c 65 50 74 72 2c 20 28 63  hashTablePtr, (c
98a0: 68 61 72 20 2a 29 6b 65 79 29 3b 0a 2b 0a 2b 20  har *)key);.+.+ 
98b0: 20 20 20 20 20 20 20 69 66 20 28 68 50 74 72 20         if (hPtr 
98c0: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20  != NULL) {.+    
98d0: 20 20 20 20 20 20 20 20 70 74 72 20 3d 20 54 63          ptr = Tc
98e0: 6c 5f 47 65 74 48 61 73 68 56 61 6c 75 65 28 68  l_GetHashValue(h
98f0: 50 74 72 29 3b 0a 2b 0a 2b 20 20 20 20 20 20 20  Ptr);.+.+       
9900: 20 20 20 20 20 69 66 20 28 70 74 72 20 21 3d 20       if (ptr != 
9910: 4e 55 4c 4c 29 20 7b 0a 2b 20 20 20 20 20 20 20  NULL) {.+       
9920: 20 20 20 20 20 20 20 20 20 54 63 6c 46 72 65 65           TclFree
9930: 41 6c 6c 6f 63 43 61 63 68 65 28 70 74 72 29 3b  AllocCache(ptr);
9940: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a  .+            }.
9950: 2b 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 54  +.+            T
9960: 63 6c 5f 44 65 6c 65 74 65 48 61 73 68 45 6e 74  cl_DeleteHashEnt
9970: 72 79 28 68 50 74 72 29 3b 0a 2b 20 20 20 20 20  ry(hPtr);.+     
9980: 20 20 20 7d 0a 2b 20 20 20 20 7d 20 65 6c 73 65     }.+    } else
9990: 20 7b 0a 2b 20 20 20 20 20 20 20 20 70 61 6e 69   {.+        pani
99a0: 63 28 22 54 63 6c 70 54 68 72 65 61 64 53 74 6f  c("TclpThreadSto
99b0: 72 61 67 65 49 6e 69 74 20 66 61 69 6c 65 64 20  rageInit failed 
99c0: 66 72 6f 6d 20 54 63 6c 57 69 6e 46 72 65 65 41  from TclWinFreeA
99d0: 6c 6c 6f 63 43 61 63 68 65 21 22 29 3b 0a 2b 20  llocCache!");.+ 
99e0: 20 20 20 7d 0a 2b 23 65 6e 64 69 66 0a 2b 7d 0a     }.+#endif.+}.
99f0: 2b 0a 2b 76 6f 69 64 0a 2b 54 63 6c 70 46 69 6e  +.+void.+TclpFin
9a00: 61 6c 69 7a 65 54 68 72 65 61 64 41 6c 6c 6f 63  alizeThreadAlloc
9a10: 53 75 62 73 79 73 74 65 6d 28 76 6f 69 64 29 0a  Subsystem(void).
9a20: 2b 7b 0a 2b 23 69 66 6e 64 65 66 20 54 43 4c 5f  +{.+#ifndef TCL_
9a30: 54 48 52 45 41 44 5f 41 4c 4c 4f 43 5f 4e 4f 5f  THREAD_ALLOC_NO_
9a40: 54 4c 53 0a 2b 20 20 20 20 42 4f 4f 4c 20 73 75  TLS.+    BOOL su
9a50: 63 63 65 73 73 3b 0a 2b 20 20 20 20 69 66 20 28  ccess;.+    if (
9a60: 69 6e 69 74 54 68 72 65 61 64 41 6c 6c 6f 63 29  initThreadAlloc)
9a70: 20 7b 0a 2b 20 20 20 20 20 20 20 20 73 75 63 63   {.+        succ
9a80: 65 73 73 20 3d 20 54 6c 73 46 72 65 65 28 6b 65  ess = TlsFree(ke
9a90: 79 29 3b 0a 2b 20 20 20 20 20 20 20 20 69 66 20  y);.+        if 
9aa0: 28 73 75 63 63 65 73 73 29 20 7b 0a 2b 20 20 20  (success) {.+   
9ab0: 20 20 20 20 20 20 20 20 20 2f 2a 20 72 65 73 65           /* rese
9ac0: 74 20 74 68 65 20 76 61 72 69 61 62 6c 65 20 66  t the variable f
9ad0: 6f 72 20 6e 65 78 74 20 74 69 6d 65 2e 20 2a 2f  or next time. */
9ae0: 0a 2b 20 20 20 20 20 20 20 20 20 20 20 20 6b 65  .+            ke
9af0: 79 20 3d 20 54 4c 53 5f 4f 55 54 5f 4f 46 5f 49  y = TLS_OUT_OF_I
9b00: 4e 44 45 58 45 53 3b 0a 2b 20 20 20 20 20 20 20  NDEXES;.+       
9b10: 20 20 20 20 20 69 6e 69 74 54 68 72 65 61 64 41       initThreadA
9b20: 6c 6c 6f 63 20 3d 20 30 3b 0a 2b 20 20 20 20 20  lloc = 0;.+     
9b30: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 2b 20 20 20     } else {.+   
9b40: 20 20 20 20 20 20 20 20 20 70 61 6e 69 63 28 22           panic("
9b50: 54 6c 73 46 72 65 65 20 66 61 69 6c 65 64 20 66  TlsFree failed f
9b60: 72 6f 6d 20 54 63 6c 70 46 69 6e 61 6c 69 7a 65  rom TclpFinalize
9b70: 54 68 72 65 61 64 41 6c 6c 6f 63 53 75 62 73 79  ThreadAllocSubsy
9b80: 73 74 65 6d 21 22 29 3b 0a 2b 20 20 20 20 20 20  stem!");.+      
9b90: 20 20 7d 0a 2b 20 20 20 20 7d 0a 2b 23 65 6c 73    }.+    }.+#els
9ba0: 65 0a 2b 20 20 20 20 2f 2a 20 72 65 73 65 74 20  e.+    /* reset 
9bb0: 66 6f 72 20 6e 65 78 74 20 74 69 6d 65 20 61 72  for next time ar
9bc0: 6f 75 6e 64 2e 2e 2e 20 2a 2f 0a 2b 20 20 20 20  ound... */.+    
9bd0: 6b 65 79 20 3d 20 53 54 4f 52 41 47 45 5f 49 4e  key = STORAGE_IN
9be0: 56 41 4c 49 44 5f 4b 45 59 3b 0a 2b 20 20 20 20  VALID_KEY;.+    
9bf0: 69 6e 69 74 54 68 72 65 61 64 41 6c 6c 6f 63 20  initThreadAlloc 
9c00: 3d 20 30 3b 0a 2b 23 65 6e 64 69 66 0a 20 7d 0a  = 0;.+#endif. }.
9c10: 20 0a 20 23 65 6e 64 69 66 20 2f 2a 20 55 53 45   . #endif /* USE
9c20: 5f 54 48 52 45 41 44 5f 41 4c 4c 4f 43 20 2a 2f  _THREAD_ALLOC */
9c30: 0a                                               .