diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2016-07-16 15:19:53 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2016-07-16 15:19:53 +0200 |
commit | bf372706c469764d59e9f29c39e3ecbebd72b8d2 (patch) | |
tree | 0f0e296e2d50e4a7faf99ae6fa428d2681e81ea1 /src/libstrongswan/threading | |
parent | 518dd33c94e041db0444c7d1f33da363bb8e3faf (diff) | |
download | vyos-strongswan-bf372706c469764d59e9f29c39e3ecbebd72b8d2.tar.gz vyos-strongswan-bf372706c469764d59e9f29c39e3ecbebd72b8d2.zip |
Imported Upstream version 5.5.0
Diffstat (limited to 'src/libstrongswan/threading')
-rw-r--r-- | src/libstrongswan/threading/thread.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/libstrongswan/threading/thread.c b/src/libstrongswan/threading/thread.c index 3d87e7fca..de5cbaa21 100644 --- a/src/libstrongswan/threading/thread.c +++ b/src/libstrongswan/threading/thread.c @@ -278,18 +278,27 @@ static private_thread_t *thread_create_internal() } /** - * Main cleanup function for threads. + * Remove and run all cleanup handlers in reverse order. */ -static void thread_cleanup(private_thread_t *this) +static void thread_cleanup_popall_internal(private_thread_t *this) { cleanup_handler_t *handler; - this->mutex->lock(this->mutex); + while (this->cleanup_handlers->remove_last(this->cleanup_handlers, - (void**)&handler) == SUCCESS) + (void**)&handler) == SUCCESS) { handler->cleanup(handler->arg); free(handler); } +} + +/** + * Main cleanup function for threads. + */ +static void thread_cleanup(private_thread_t *this) +{ + thread_cleanup_popall_internal(this); + this->mutex->lock(this->mutex); this->terminated = TRUE; thread_destroy(this); } @@ -417,15 +426,8 @@ void thread_cleanup_pop(bool execute) void thread_cleanup_popall() { private_thread_t *this = (private_thread_t*)thread_current(); - cleanup_handler_t *handler; - while (this->cleanup_handlers->get_count(this->cleanup_handlers)) - { - this->cleanup_handlers->remove_last(this->cleanup_handlers, - (void**)&handler); - handler->cleanup(handler->arg); - free(handler); - } + thread_cleanup_popall_internal(this); } /** |