summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasiljevic <zv@archiware.com>2005-04-07 11:29:33 (GMT)
committervasiljevic <zv@archiware.com>2005-04-07 11:29:33 (GMT)
commit75b47cda0d8c45e5297f9c4c092047a1c479010c (patch)
treebc23a6c4879c6ec2f3be0c65798ddec8ebe7c76b
parent837379c8953f7f14bd17b71ca39e1655ae7b0801 (diff)
downloadtcl-75b47cda0d8c45e5297f9c4c092047a1c479010c.zip
tcl-75b47cda0d8c45e5297f9c4c092047a1c479010c.tar.gz
tcl-75b47cda0d8c45e5297f9c4c092047a1c479010c.tar.bz2
Renamed TclWinFreeAllocCache to TclpFreeAllocCache and fixed
to recognize when being called with NULL argument. This is a signal for it to clean up the tsd key associated with the threading allocator. Part of fixing the Tcl Bug #1178445.
-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. */
}
}