diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-06-19 10:45:17 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-06-25 17:10:28 +0200 |
commit | 7fec83af28f233a02b7ae08c6fd4de65799cb6b4 (patch) | |
tree | c1093faa3be57635e0cb8baf112c6edfaa3001e9 /src/libstrongswan/processing/jobs/callback_job.c | |
parent | 18d21a57df6085e1738a92d5a352ec17d314a753 (diff) | |
download | strongswan-7fec83af28f233a02b7ae08c6fd4de65799cb6b4.tar.bz2 strongswan-7fec83af28f233a02b7ae08c6fd4de65799cb6b4.tar.xz |
Give processor_t more control over the lifecycle of a job
Jobs are now destroyed by the processor, but they are allowed to
reschedule themselves. That is, parts of the reschedule functionality
already provided by callback_job_t is moved to the processor. Not yet
fully supported is JOB_REQUEUE_DIRECT and canceling jobs.
Note: job_t.destroy() is now called not only for queued jobs but also
after execution or cancellation of jobs. job_t.status can be used to
decide what to do in said method.
Diffstat (limited to 'src/libstrongswan/processing/jobs/callback_job.c')
-rw-r--r-- | src/libstrongswan/processing/jobs/callback_job.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/libstrongswan/processing/jobs/callback_job.c b/src/libstrongswan/processing/jobs/callback_job.c index 452c07ce6..86d5228bf 100644 --- a/src/libstrongswan/processing/jobs/callback_job.c +++ b/src/libstrongswan/processing/jobs/callback_job.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Tobias Brunner + * Copyright (C) 2009-2012 Tobias Brunner * Copyright (C) 2007-2011 Martin Willi * Copyright (C) 2011 revosec AG * Hochschule fuer Technik Rapperswil @@ -56,7 +56,7 @@ struct private_callback_job_t { thread_t *thread; /** - * mutex to access jobs interna + * mutex to access private job data */ mutex_t *mutex; @@ -71,9 +71,9 @@ struct private_callback_job_t { private_callback_job_t *parent; /** - * TRUE if the job got cancelled + * TRUE if the job got canceled */ - bool cancelled; + bool canceled; /** * condvar to synchronize the cancellation/destruction of the job @@ -103,10 +103,10 @@ static void unregister(private_callback_job_t *this) if (this->parent) { this->parent->mutex->lock(this->parent->mutex); - if (this->parent->cancelled && !this->cancelled) + if (this->parent->canceled && !this->canceled) { - /* if the parent has been cancelled but we have not yet, we do not - * unregister until we got cancelled by the parent. */ + /* if the parent has been canceled but we have not yet, we do not + * unregister until we got canceled by the parent. */ this->parent->mutex->unlock(this->parent->mutex); this->destroyable->wait(this->destroyable, this->mutex); this->parent->mutex->lock(this->parent->mutex); @@ -144,7 +144,7 @@ METHOD(callback_job_t, cancel, void, semaphore_t *terminated = NULL; this->mutex->lock(this->mutex); - this->cancelled = TRUE; + this->canceled = TRUE; /* terminate children */ while (this->children->get_first(this->children, (void**)&child) == SUCCESS) { @@ -177,12 +177,10 @@ METHOD(callback_job_t, cancel, void, } } -METHOD(job_t, execute, void, +METHOD(job_t, execute, job_requeue_t, private_callback_job_t *this) { - bool cleanup = FALSE, requeue = FALSE; - - thread_cleanup_push((thread_cleanup_t)destroy, this); + bool requeue = FALSE; this->mutex->lock(this->mutex); this->thread = thread_current(); @@ -191,10 +189,9 @@ METHOD(job_t, execute, void, while (TRUE) { this->mutex->lock(this->mutex); - if (this->cancelled) + if (this->canceled) { this->mutex->unlock(this->mutex); - cleanup = TRUE; break; } this->mutex->unlock(this->mutex); @@ -210,7 +207,6 @@ METHOD(job_t, execute, void, case JOB_REQUEUE_NONE: default: { - cleanup = TRUE; break; } } @@ -219,14 +215,10 @@ METHOD(job_t, execute, void, this->mutex->lock(this->mutex); this->thread = NULL; this->mutex->unlock(this->mutex); - /* manually create a cancellation point to avoid that a cancelled thread - * goes back into the thread pool */ + /* manually create a cancellation point to avoid that a canceled thread + * goes back into the thread pool at all */ thread_cancellation_point(); - if (requeue) - { - lib->processor->queue_job(lib->processor, &this->public.job); - } - thread_cleanup_pop(cleanup); + return requeue ? JOB_REQUEUE_FAIR : JOB_REQUEUE_NONE; } METHOD(job_t, get_priority, job_priority_t, |