summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--win/tclWinThrd.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index 05a321b..953a154 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinThrd.c,v 1.24.2.9 2004/10/28 21:12:38 andreas_kupries Exp $
+ * RCS: @(#) $Id: tclWinThrd.c,v 1.24.2.10 2005/04/07 11:29:33 vasiljevic Exp $
*/
#include "tclWinInt.h"
@@ -680,13 +680,16 @@ TclpFinalizeThreadData(keyPtr)
DWORD *indexPtr;
BOOL success;
-#if defined(USE_THREAD_ALLOC) && !defined(TCL_MEM_DEBUG)
- TclWinFreeAllocCache();
-#endif
if (*keyPtr != NULL) {
indexPtr = *(DWORD **)keyPtr;
result = (VOID *)TlsGetValue(*indexPtr);
if (result != NULL) {
+#if defined(USE_THREAD_ALLOC) && !defined(TCL_MEM_DEBUG)
+ if (indexPtr == &key) {
+ TclpFreeAllocCache(result);
+ return;
+ }
+#endif
ckfree((char *)result);
success = TlsSetValue(*indexPtr, (void *)NULL);
if (!success) {
@@ -1078,7 +1081,7 @@ TclpGetAllocCache(void)
if (!once) {
/*
- * We need to make sure that TclWinFreeAllocCache is called
+ * We need to make sure that TclpFreeAllocCache is called
* on each thread that calls this, but only on threads that
* call this.
*/
@@ -1107,30 +1110,28 @@ TclpSetAllocCache(void *ptr)
}
void
-TclWinFreeAllocCache(void)
+TclpFreeAllocCache(void *ptr)
{
- void *ptr;
BOOL success;
- ptr = TlsGetValue(key);
if (ptr != NULL) {
- success = TlsSetValue(key, NULL);
+ /*
+ * Called by the pthread lib when a thread exits
+ */
+ TclFreeAllocCache(ptr);
+ success = TlsSetValue(key, NULL);
if (!success) {
- panic("TlsSetValue failed from TclWinFreeAllocCache!");
+ panic("TlsSetValue failed from TclpFreeAllocCache!");
}
- TclFreeAllocCache(ptr);
- } else {
- if (GetLastError() != NO_ERROR) {
- panic("TlsGetValue failed from TclWinFreeAllocCache!");
- }
- }
-
- if (once) {
+ } else if (once) {
+ /*
+ * Called by us in TclFinalizeThreadAlloc() during
+ * the library finalization initiated from Tcl_Finalize()
+ */
success = TlsFree(key);
if (!success) {
- Tcl_Panic("TlsFree failed from TclWinFreeAllocCache!");
+ Tcl_Panic("TlsFree failed from TclpFreeAllocCache!");
}
-
once = 0; /* reset for next time. */
}
}