diff options
author | vasiljevic <zv@archiware.com> | 2010-04-02 15:53:52 (GMT) |
---|---|---|
committer | vasiljevic <zv@archiware.com> | 2010-04-02 15:53:52 (GMT) |
commit | c5ca5644d35b1fbad9c367e78cc5d38566f584e4 (patch) | |
tree | 358332b627ca5069de2b4b29758807cc34b4c191 | |
parent | 148e4d178f75cba1bfd43ca869360e5cbfb34d93 (diff) | |
download | tcl-c5ca5644d35b1fbad9c367e78cc5d38566f584e4.zip tcl-c5ca5644d35b1fbad9c367e78cc5d38566f584e4.tar.gz tcl-c5ca5644d35b1fbad9c367e78cc5d38566f584e4.tar.bz2 |
* generic/tclThreadStorage.c (ThreadStorageGetHashTable):
avoid accessing shared table index w/o mutex protection.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | generic/tclThreadStorage.c | 19 |
2 files changed, 13 insertions, 14 deletions
@@ -1,8 +1,12 @@ 2010-04-02 Zoran Vasiljevic <vasiljevic@users.sourceforge.net> * generic/tclStringObj.c: (SetStringFromAny): avoid trampling - over the tclEmptyStringRep->bytes as it is thread-shared - (thx to Gustaf Neumann for the (hard) work of locating this one). + over the tclEmptyStringRep as it is thread-shared. + + * generic/tclThreadStorage.c (ThreadStorageGetHashTable): + avoid accessing shared table index w/o mutex protection. + + Thanks to Gustaf Neumann for the (hard) work. 2010-03-31 Donal K. Fellows <dkf@users.sf.net> 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; } |