From 21692169b9b52a41eb8134c17afa79d3e05d676f Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 5 May 2011 18:06:09 +0200 Subject: Make sure working thread count is correctly updated --- src/libstrongswan/processing/processor.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/libstrongswan/processing/processor.c') diff --git a/src/libstrongswan/processing/processor.c b/src/libstrongswan/processing/processor.c index 1df8d0a18..a250112ab 100644 --- a/src/libstrongswan/processing/processor.c +++ b/src/libstrongswan/processing/processor.c @@ -113,12 +113,23 @@ static void restart(private_processor_t *this) this->mutex->unlock(this->mutex); } +/** + * Data needed to decrement the working thread count of a priority class + */ +typedef struct { + private_processor_t *this; + u_int priority; +} decrement_data_t; + /** * Decrement working thread count of a priority class */ -static void decrement_working_threads(u_int *working_threads) +static void decrement_working_threads(decrement_data_t *dec) { - (*working_threads)--; + dec->this->mutex->lock(dec->this->mutex); + dec->this->working_threads[dec->priority]--; + dec->this->mutex->unlock(dec->this->mutex); + free(dec); } /** @@ -170,16 +181,24 @@ static void process_jobs(private_processor_t *this) if (this->jobs[i]->remove_first(this->jobs[i], (void**)&job) == SUCCESS) { + decrement_data_t *dec; + this->working_threads[i]++; this->mutex->unlock(this->mutex); + INIT(dec, + .this = this, + .priority = i, + ); thread_cleanup_push((thread_cleanup_t)decrement_working_threads, - &this->working_threads[i]); + dec); /* terminated threads are restarted to get a constant pool */ thread_cleanup_push((thread_cleanup_t)restart, this); job->execute(job); thread_cleanup_pop(FALSE); + thread_cleanup_pop(FALSE); this->mutex->lock(this->mutex); - thread_cleanup_pop(TRUE); + this->working_threads[i]--; + free(dec); break; } } -- cgit v1.2.3