]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
processor: add an execute_job() method to directly execute an important job
authorMartin Willi <martin@revosec.ch>
Thu, 18 Jul 2013 09:37:42 +0000 (11:37 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Jul 2013 14:00:31 +0000 (16:00 +0200)
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.

src/libstrongswan/processing/processor.c
src/libstrongswan/processing/processor.h

index c465f02591a8d89cb6255043619da995019b7a7b..f193b8d5e1de9cbbf3bb38d5f60b5dd1b4da1332 100644 (file)
@@ -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,
index bd708fba86cfda940b3f779e18945d069e7e321a..c691cfb609aa66875f222c12c9a7fcd778247d64 100644 (file)
@@ -74,6 +74,16 @@ struct processor_t {
         */
        void (*queue_job) (processor_t *this, job_t *job);
 
+       /**
+        * Directly execute a job with an idle worker thread.
+        *
+        * If no idle thread is available, the job gets executed by the calling
+        * thread.
+        *
+        * @param job                   job, gets destroyed
+        */
+       void (*execute_job)(processor_t *this, job_t *job);
+
        /**
         * Set the number of threads to use in the processor.
         *