diff options
author | hobbs <hobbs> | 2004-07-21 01:45:44 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2004-07-21 01:45:44 (GMT) |
commit | 4dcfe1cc24fd10bd3e184990a3b7f7c3042d6e03 (patch) | |
tree | a73f70550f592464825b855b97bcf3574735f983 /unix/tclUnixThrd.c | |
parent | b7baa5cf544d8865daa4745ad9616caabfedd664 (diff) | |
download | tcl-4dcfe1cc24fd10bd3e184990a3b7f7c3042d6e03.zip tcl-4dcfe1cc24fd10bd3e184990a3b7f7c3042d6e03.tar.gz tcl-4dcfe1cc24fd10bd3e184990a3b7f7c3042d6e03.tar.bz2 |
* generic/tclEvent.c: Correct threaded obj allocator to
* generic/tclInt.h: fully cleanup on exit and allow for
* generic/tclThreadAlloc.c: reinitialization. [Bug #736426]
* unix/tclUnixThrd.c: (mistachkin, kenny)
* win/tclWinThrd.c:
Diffstat (limited to 'unix/tclUnixThrd.c')
-rw-r--r-- | unix/tclUnixThrd.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index edcb0f3..aad394f 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -934,19 +934,20 @@ TclpInetNtoa(struct in_addr addr) * Additions by AOL for specialized thread memory allocator. */ #ifdef USE_THREAD_ALLOC -static int initialized = 0; +static volatile int initialized = 0; static pthread_key_t key; -static pthread_once_t once = PTHREAD_ONCE_INIT; + +typedef struct allocMutex { + Tcl_Mutex tlock; + pthread_mutex_t plock; +} allocMutex; Tcl_Mutex * TclpNewAllocMutex(void) { - struct lock { - Tcl_Mutex tlock; - pthread_mutex_t plock; - } *lockPtr; + struct allocMutex *lockPtr; - lockPtr = malloc(sizeof(struct lock)); + lockPtr = malloc(sizeof(struct allocMutex)); if (lockPtr == NULL) { Tcl_Panic("could not allocate lock"); } @@ -955,20 +956,41 @@ TclpNewAllocMutex(void) return &lockPtr->tlock; } -static void -InitKey(void) +void +TclpFreeAllocMutex(mutex) + Tcl_Mutex *mutex; /* The alloc mutex to free. */ +{ + allocMutex* lockPtr = (allocMutex*) mutex; + if (!lockPtr) return; + pthread_mutex_destroy(&lockPtr->plock); + free(lockPtr); +} + +void TclpFreeAllocCache(ptr) + void *ptr; { extern void TclFreeAllocCache(void *); - pthread_key_create(&key, TclFreeAllocCache); - initialized = 1; + TclFreeAllocCache(ptr); + /* + * Perform proper cleanup of things done in TclpGetAllocCache. + */ + if (initialized) { + pthread_key_delete(key); + initialized = 0; + } } void * TclpGetAllocCache(void) { if (!initialized) { - pthread_once(&once, InitKey); + pthread_mutex_lock(allocLockPtr); + if (!initialized) { + pthread_key_create(&key, TclpFreeAllocCache); + initialized = 1; + } + pthread_mutex_unlock(allocLockPtr); } return pthread_getspecific(key); } |