diff options
author | Tobias Brunner <tobias@strongswan.org> | 2011-05-05 18:06:09 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-05-16 15:24:16 +0200 |
commit | 21692169b9b52a41eb8134c17afa79d3e05d676f (patch) | |
tree | 75e3648749a7013cbc527bb1f1955faa9391fd4a /src/libstrongswan/processing/processor.c | |
parent | 4baf1f3bfece66766b78eddab33014ebaee99a89 (diff) | |
download | strongswan-21692169b9b52a41eb8134c17afa79d3e05d676f.tar.bz2 strongswan-21692169b9b52a41eb8134c17afa79d3e05d676f.tar.xz |
Make sure working thread count is correctly updated
Diffstat (limited to 'src/libstrongswan/processing/processor.c')
-rw-r--r-- | src/libstrongswan/processing/processor.c | 27 |
1 files changed, 23 insertions, 4 deletions
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 @@ -114,11 +114,22 @@ static void restart(private_processor_t *this) } /** + * 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; } } |