diff options
author | Kevin B Kenny <kennykb@acm.org> | 2015-10-21 23:30:41 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2015-10-21 23:30:41 (GMT) |
commit | f82f46df1628c6703ad0ff2b94d83c6c9a46c56f (patch) | |
tree | cd72f2c405b20397c8c5627e59888bd8ab5983b2 /unix | |
parent | 0a228666ae8b3189ae92ff7624263de1455c24ff (diff) | |
download | tcl-f82f46df1628c6703ad0ff2b94d83c6c9a46c56f.zip tcl-f82f46df1628c6703ad0ff2b94d83c6c9a46c56f.tar.gz tcl-f82f46df1628c6703ad0ff2b94d83c6c9a46c56f.tar.bz2 |
Micro-optimization: remove double checked lock from TclGetAllocCache in favour of initialization in TclInitSubsystems
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tclUnixThrd.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index ea03332..0f4a8a3 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -680,7 +680,6 @@ TclpInetNtoa( */ #ifdef USE_THREAD_ALLOC -static volatile int initialized = 0; static pthread_key_t key; typedef struct allocMutex { @@ -727,29 +726,23 @@ TclpFreeAllocCache( TclFreeAllocCache(ptr); pthread_setspecific(key, NULL); - - } else if (initialized) { - /* - * Called by us in TclFinalizeThreadAlloc() during the library - * finalization initiated from Tcl_Finalize() - */ - + + } else { pthread_key_delete(key); - initialized = 0; } } +void +TclpInitThreadAlloc(void) +{ + pthread_mutex_lock(allocLockPtr); + pthread_key_create(&key, TclpFreeAllocCache); + pthread_mutex_unlock(allocLockPtr); +} + void * TclpGetAllocCache(void) { - if (!initialized) { - pthread_mutex_lock(allocLockPtr); - if (!initialized) { - pthread_key_create(&key, TclpFreeAllocCache); - initialized = 1; - } - pthread_mutex_unlock(allocLockPtr); - } return pthread_getspecific(key); } |