aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/processing/processor.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-07-18 11:37:42 +0200
committerMartin Willi <martin@revosec.ch>2013-07-18 16:00:31 +0200
commit6653e6c13e61da0753625af13de62c46d1ceeb48 (patch)
treefae7def33a3e4163050ebf1709353ed1ca7b1493 /src/libstrongswan/processing/processor.c
parent55240835b0562a35025d261d85dd2bb04446d350 (diff)
downloadstrongswan-6653e6c13e61da0753625af13de62c46d1ceeb48.tar.bz2
strongswan-6653e6c13e61da0753625af13de62c46d1ceeb48.tar.xz
processor: add an execute_job() method to directly execute an important job
If all worker threads are busy and waiting for an event, we must ensure that a job delivering that event gets executed. This new method has this property for CRITICAL jobs, using a worker if we have one, but executing the job directly if not.
Diffstat (limited to 'src/libstrongswan/processing/processor.c')
-rw-r--r--src/libstrongswan/processing/processor.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libstrongswan/processing/processor.c b/src/libstrongswan/processing/processor.c
index c465f0259..f193b8d5e 100644
--- a/src/libstrongswan/processing/processor.c
+++ b/src/libstrongswan/processing/processor.c
@@ -401,6 +401,31 @@ METHOD(processor_t, queue_job, void,
this->mutex->unlock(this->mutex);
}
+METHOD(processor_t, execute_job, void,
+ private_processor_t *this, job_t *job)
+{
+ job_priority_t prio;
+ bool queued = FALSE;
+
+ this->mutex->lock(this->mutex);
+ if (get_idle_threads_nolock(this))
+ {
+ prio = sane_prio(job->get_priority(job));
+ job->status = JOB_STATUS_QUEUED;
+ /* insert job in front to execute it immediately */
+ this->jobs[prio]->insert_first(this->jobs[prio], job);
+ queued = TRUE;
+ }
+ this->job_added->signal(this->job_added);
+ this->mutex->unlock(this->mutex);
+
+ if (!queued)
+ {
+ job->execute(job);
+ job->destroy(job);
+ }
+}
+
METHOD(processor_t, set_threads, void,
private_processor_t *this, u_int count)
{
@@ -512,6 +537,7 @@ processor_t *processor_create()
.get_working_threads = _get_working_threads,
.get_job_load = _get_job_load,
.queue_job = _queue_job,
+ .execute_job = _execute_job,
.set_threads = _set_threads,
.get_threads = _get_threads,
.cancel = _cancel,