Added a callback_job constructor supporting custom priorities
authorMartin Willi <martin@revosec.ch>
Wed, 4 May 2011 14:09:08 +0000 (16:09 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:24:15 +0000 (15:24 +0200)
src/libstrongswan/processing/jobs/callback_job.c
src/libstrongswan/processing/jobs/callback_job.h

index 2881775..26afea3 100644 (file)
@@ -88,6 +88,11 @@ struct private_callback_job_t {
         * without risking that it gets freed too early during destruction.
         */
        sem_t *terminated;
+
+       /**
+        * Priority of this job
+        */
+       job_priority_t prio;
 };
 
 /**
@@ -230,15 +235,15 @@ METHOD(job_t, execute, void,
 METHOD(job_t, get_priority, job_priority_t,
        private_callback_job_t *this)
 {
-       return JOB_PRIO_MEDIUM;
+       return this->prio;
 }
 
 /*
  * Described in header.
  */
-callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
-                                                                       callback_job_cleanup_t cleanup,
-                                                                       callback_job_t *parent)
+callback_job_t *callback_job_create_with_prio(callback_job_cb_t cb, void *data,
+                                       callback_job_cleanup_t cleanup, callback_job_t *parent,
+                                       job_priority_t prio)
 {
        private_callback_job_t *this;
 
@@ -258,6 +263,7 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
                .children = linked_list_create(),
                .parent = (private_callback_job_t*)parent,
                .destroyable = condvar_create(CONDVAR_TYPE_DEFAULT),
+               .prio = prio,
        );
 
        /* register us at parent */
@@ -271,3 +277,13 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
        return &this->public;
 }
 
+/*
+ * Described in header.
+ */
+callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
+                                                                       callback_job_cleanup_t cleanup,
+                                                                       callback_job_t *parent)
+{
+       return callback_job_create_with_prio(cb, data, cleanup, parent,
+                                                                                JOB_PRIO_MEDIUM);
+}
index 1eb5664..3e92b01 100644 (file)
@@ -120,4 +120,20 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
                                                                        callback_job_cleanup_t cleanup,
                                                                        callback_job_t *parent);
 
+/**
+ * Creates a callback job, with priority.
+ *
+ * Same as callback_job_create(), but with different priorities than default.
+ *
+ * @param cb                           callback to call from the processor
+ * @param data                         user data to supply to callback
+ * @param cleanup                      destructor for data on destruction, or NULL
+ * @param parent                       parent of this job
+ * @param prio                         job priority
+ * @return                                     callback_job_t object
+ */
+callback_job_t *callback_job_create_with_prio(callback_job_cb_t cb, void *data,
+                                       callback_job_cleanup_t cleanup, callback_job_t *parent,
+                                       job_priority_t prio);
+
 #endif /** CALLBACK_JOB_H_ @}*/