diff options
Diffstat (limited to 'win/tclWinThrd.c')
-rw-r--r-- | win/tclWinThrd.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c index c968a53..e2f399f 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.32 2004/07/19 19:19:07 vasiljevic Exp $ + * RCS: @(#) $Id: tclWinThrd.c,v 1.33 2004/07/21 01:45:45 hobbs Exp $ */ #include "tclWinInt.h" @@ -1040,17 +1040,20 @@ TclpFinalizeCondition(condPtr) * Additions by AOL for specialized thread memory allocator. */ #ifdef USE_THREAD_ALLOC +static int once; static DWORD key; +typedef struct allocMutex { + Tcl_Mutex tlock; + CRITICAL_SECTION wlock; +} allocMutex; + Tcl_Mutex * TclpNewAllocMutex(void) { - struct lock { - Tcl_Mutex tlock; - CRITICAL_SECTION wlock; - } *lockPtr; + struct allocMutex *lockPtr; - lockPtr = malloc(sizeof(struct lock)); + lockPtr = malloc(sizeof(struct allocMutex)); if (lockPtr == NULL) { Tcl_Panic("could not allocate lock"); } @@ -1059,10 +1062,19 @@ TclpNewAllocMutex(void) return &lockPtr->tlock; } +void +TclpFreeAllocMutex(mutex) + Tcl_Mutex *mutex; /* The alloc mutex to free. */ +{ + allocMutex* lockPtr = (allocMutex*) mutex; + if (!lockPtr) return; + DeleteCriticalSection(&lockPtr->wlock); + free(lockPtr); +} + void * TclpGetAllocCache(void) { - static int once = 0; VOID *result; if (!once) { @@ -1113,6 +1125,15 @@ TclWinFreeAllocCache(void) Tcl_Panic("TlsGetValue failed from TclWinFreeAllocCache!"); } } + + if (once) { + success = TlsFree(key); + if (!success) { + Tcl_Panic("TlsFree failed from TclWinFreeAllocCache!"); + } + + once = 0; /* reset for next time. */ + } } #endif /* USE_THREAD_ALLOC */ |