diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2013-10-17 21:23:38 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2013-10-17 21:23:38 +0200 |
commit | 9d37ad77ef660b92ea51b69d74e14f931d2a04e2 (patch) | |
tree | d6bbb4a5fed1959f8675df9ee7c03713b543fcc9 /src/libstrongswan/threading/thread_value.c | |
parent | 104f57d4b0fb6d7547d6898352eaa5fb4b222010 (diff) | |
parent | e5ee4e7fcdd58b7d86bf1b458da2c63e8e19627b (diff) | |
download | vyos-strongswan-9d37ad77ef660b92ea51b69d74e14f931d2a04e2.tar.gz vyos-strongswan-9d37ad77ef660b92ea51b69d74e14f931d2a04e2.zip |
Merge tag 'v5.1.0-1' into sid
tag strongSwan 5.1.0-1
Diffstat (limited to 'src/libstrongswan/threading/thread_value.c')
-rw-r--r-- | src/libstrongswan/threading/thread_value.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libstrongswan/threading/thread_value.c b/src/libstrongswan/threading/thread_value.c index 3fa70acb2..190b7434f 100644 --- a/src/libstrongswan/threading/thread_value.c +++ b/src/libstrongswan/threading/thread_value.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Tobias Brunner + * Copyright (C) 2009-2012 Tobias Brunner * Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it @@ -33,6 +33,11 @@ struct private_thread_value_t { */ pthread_key_t key; + /** + * Destructor to cleanup the value of the thread destroying this object + */ + thread_cleanup_t destructor; + }; METHOD(thread_value_t, set, void, @@ -50,11 +55,22 @@ METHOD(thread_value_t, get, void*, METHOD(thread_value_t, destroy, void, private_thread_value_t *this) { + void *val; + + /* the destructor is not called automatically for the thread calling + * pthread_key_delete() */ + if (this->destructor) + { + val = pthread_getspecific(this->key); + if (val) + { + this->destructor(val); + } + } pthread_key_delete(this->key); free(this); } - /** * Described in header. */ @@ -68,6 +84,7 @@ thread_value_t *thread_value_create(thread_cleanup_t destructor) .get = _get, .destroy = _destroy, }, + .destructor = destructor, ); pthread_key_create(&this->key, destructor); |