diff options
author | Martin Willi <martin@revosec.ch> | 2013-12-06 11:33:40 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 15:53:02 +0200 |
commit | 204098a7520205b4534044b3840f68cb1a6e20ae (patch) | |
tree | ef89e6c809e75628075eccf636e15fb93391267a /src/libstrongswan/threading/windows/thread.c | |
parent | 9dec601f30ca6558c1b070de1d8e1a2a43eaf49e (diff) | |
download | strongswan-204098a7.tar.bz2 strongswan-204098a7.tar.xz |
thread-value: Immediately cleanup all Windows TLS values on destroy
Diffstat (limited to 'src/libstrongswan/threading/windows/thread.c')
-rw-r--r-- | src/libstrongswan/threading/windows/thread.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/libstrongswan/threading/windows/thread.c b/src/libstrongswan/threading/windows/thread.c index 5fa68bb91..35d56c47d 100644 --- a/src/libstrongswan/threading/windows/thread.c +++ b/src/libstrongswan/threading/windows/thread.c @@ -68,7 +68,7 @@ struct private_thread_t { array_t *cleanup; /** - * Thread specific values for this thread, as cleanup_t + * Thread specific values for this thread */ hashtable_t *tls; @@ -238,13 +238,45 @@ void* thread_tls_remove(void *key) thread = get_current_thread(); old = set_leak_detective(FALSE); + threads_lock->lock(threads_lock); value = thread->tls->remove(thread->tls, key); + threads_lock->unlock(threads_lock); set_leak_detective(old); return value; } /** + * See header. + */ +void thread_tls_remove_all(void *key) +{ + private_thread_t *thread; + enumerator_t *enumerator; + void *value; + bool old; + + old = set_leak_detective(FALSE); + threads_lock->lock(threads_lock); + + enumerator = threads->create_enumerator(threads); + while (enumerator->enumerate(enumerator, NULL, &thread)) + { + value = thread->tls->remove(thread->tls, key); + if (value) + { + set_leak_detective(old); + thread_tls_cleanup(value); + set_leak_detective(FALSE); + } + } + enumerator->destroy(enumerator); + + threads_lock->unlock(threads_lock); + set_leak_detective(old); +} + +/** * Thread cleanup data */ typedef struct { @@ -272,6 +304,7 @@ static void docleanup(private_thread_t *this) set_leak_detective(FALSE); } + threads_lock->lock(threads_lock); enumerator = this->tls->create_enumerator(this->tls); while (enumerator->enumerate(enumerator, NULL, &tls)) { @@ -282,6 +315,7 @@ static void docleanup(private_thread_t *this) set_leak_detective(FALSE); } enumerator->destroy(enumerator); + threads_lock->unlock(threads_lock); set_leak_detective(old); } |