diff options
author | vasiljevic <vasiljevic@noemail.net> | 2010-04-02 15:53:52 (GMT) |
---|---|---|
committer | vasiljevic <vasiljevic@noemail.net> | 2010-04-02 15:53:52 (GMT) |
commit | 240b519b5682cbbbed70e5100a1559a9fe3452c7 (patch) | |
tree | 358332b627ca5069de2b4b29758807cc34b4c191 /generic/tclThreadStorage.c | |
parent | 0c7281ae0c286d0e4e5feecf6f1a7f3c0780e536 (diff) | |
download | tcl-240b519b5682cbbbed70e5100a1559a9fe3452c7.zip tcl-240b519b5682cbbbed70e5100a1559a9fe3452c7.tar.gz tcl-240b519b5682cbbbed70e5100a1559a9fe3452c7.tar.bz2 |
* generic/tclThreadStorage.c (ThreadStorageGetHashTable):
avoid accessing shared table index w/o mutex protection.
FossilOrigin-Name: 567544270662367f6161056111c8e4cf68ba7e23
Diffstat (limited to 'generic/tclThreadStorage.c')
-rw-r--r-- | generic/tclThreadStorage.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/generic/tclThreadStorage.c b/generic/tclThreadStorage.c index 55587b3..d24973f 100644 --- a/generic/tclThreadStorage.c +++ b/generic/tclThreadStorage.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclThreadStorage.c,v 1.15 2007/12/13 15:23:20 dgp Exp $ + * RCS: @(#) $Id: tclThreadStorage.c,v 1.15.2.1 2010/04/02 15:53:53 vasiljevic Exp $ */ #include "tclInt.h" @@ -172,8 +172,7 @@ FreeThreadStorageEntry( * ThreadStorageGetHashTable -- * * This procedure returns a hash table pointer to be used for thread - * storage for the specified thread. This assumes that thread storage - * lock is held. + * storage for the specified thread. * * Results: * A hash table pointer for the specified thread, or NULL if the hash @@ -193,17 +192,13 @@ ThreadStorageGetHashTable( int index = PTR2UINT(id) % STORAGE_CACHE_SLOTS; Tcl_HashEntry *hPtr; int isNew; + Tcl_HashTable *hashTablePtr; - /* - * It's important that we pick up the hash table pointer BEFORE comparing - * thread Id in case another thread is in the critical region changing - * things out from under you. - */ + Tcl_MutexLock(&threadStorageLock); - Tcl_HashTable *hashTablePtr = threadStorageCache[index].hashTablePtr; + hashTablePtr = threadStorageCache[index].hashTablePtr; if (threadStorageCache[index].id != id) { - Tcl_MutexLock(&threadStorageLock); /* * It's not in the cache, so we look it up... @@ -257,10 +252,10 @@ ThreadStorageGetHashTable( threadStorageCache[index].id = id; threadStorageCache[index].hashTablePtr = hashTablePtr; - - Tcl_MutexUnlock(&threadStorageLock); } + Tcl_MutexUnlock(&threadStorageLock); + return hashTablePtr; } |