Introduce priority classes for jobs
authorMartin Willi <martin@revosec.ch>
Mon, 2 May 2011 08:52:06 +0000 (10:52 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 16 May 2011 13:24:12 +0000 (15:24 +0200)
18 files changed:
src/libcharon/processing/jobs/acquire_job.c
src/libcharon/processing/jobs/delete_child_sa_job.c
src/libcharon/processing/jobs/delete_ike_sa_job.c
src/libcharon/processing/jobs/inactivity_job.c
src/libcharon/processing/jobs/initiate_mediation_job.c
src/libcharon/processing/jobs/mediation_job.c
src/libcharon/processing/jobs/migrate_job.c
src/libcharon/processing/jobs/process_message_job.c
src/libcharon/processing/jobs/rekey_child_sa_job.c
src/libcharon/processing/jobs/rekey_ike_sa_job.c
src/libcharon/processing/jobs/retransmit_job.c
src/libcharon/processing/jobs/roam_job.c
src/libcharon/processing/jobs/send_dpd_job.c
src/libcharon/processing/jobs/send_keepalive_job.c
src/libcharon/processing/jobs/start_action_job.c
src/libcharon/processing/jobs/update_sa_job.c
src/libstrongswan/processing/jobs/callback_job.c
src/libstrongswan/processing/jobs/job.h

index 3544dd3..2d836b0 100644 (file)
@@ -61,6 +61,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_acquire_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -74,6 +80,7 @@ acquire_job_t *acquire_job_create(u_int32_t reqid,
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 29122cd..bd8bb95 100644 (file)
@@ -73,6 +73,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_delete_child_sa_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -86,6 +92,7 @@ delete_child_sa_job_t *delete_child_sa_job_create(u_int32_t reqid,
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 468c9ef..c29b722 100644 (file)
@@ -92,6 +92,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_delete_ike_sa_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -104,6 +110,7 @@ delete_ike_sa_job_t *delete_ike_sa_job_create(ike_sa_id_t *ike_sa_id,
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 1371000..f3140c7 100644 (file)
@@ -127,6 +127,12 @@ METHOD(job_t, execute, void,
        }
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_inactivity_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /**
  * See header
  */
@@ -137,8 +143,9 @@ inactivity_job_t *inactivity_job_create(u_int32_t reqid, u_int32_t timeout,
 
        INIT(this,
                .public = {
-                               .job_interface = {
+                       .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index ffe8755..b310c81 100644 (file)
@@ -224,6 +224,14 @@ static void reinitiate(private_initiate_mediation_job_t *this)
 }
 
 /**
+ * Implementation of job_t.get_priority.
+ */
+static job_priority_t get_priority(private_initiate_mediation_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
+/**
  * Creates an empty job
  */
 static private_initiate_mediation_job_t *initiate_mediation_job_create_empty()
@@ -231,6 +239,7 @@ static private_initiate_mediation_job_t *initiate_mediation_job_create_empty()
        private_initiate_mediation_job_t *this = malloc_thing(private_initiate_mediation_job_t);
 
        /* interface functions */
+       this->public.job_interface.get_priority = (job_priority_t (*) (job_t *)) get_priority;
        this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
 
        /* private variables */
index b5b8af3..44145e2 100644 (file)
@@ -138,6 +138,14 @@ static void execute(private_mediation_job_t *this)
 }
 
 /**
+ * Implementation of job_t.get_priority.
+ */
+static job_priority_t get_priority(private_mediation_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
+/**
  * Creates an empty mediation job
  */
 static private_mediation_job_t *mediation_job_create_empty()
@@ -146,6 +154,7 @@ static private_mediation_job_t *mediation_job_create_empty()
 
        /* interface functions */
        this->public.job_interface.execute = (void (*) (job_t *)) execute;
+       this->public.job_interface.get_priority = (job_priority_t (*) (job_t *)) get_priority;
        this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
 
        /* private variables */
index 5e7c7ae..7190826 100644 (file)
@@ -120,6 +120,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_migrate_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -135,6 +141,7 @@ migrate_job_t *migrate_job_create(u_int32_t reqid,
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index b6de4fc..c5c5f07 100644 (file)
@@ -84,6 +84,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_process_message_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -95,6 +101,7 @@ process_message_job_t *process_message_job_create(message_t *message)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 2bcee2d..5855f1b 100644 (file)
@@ -71,6 +71,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_rekey_child_sa_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -84,6 +90,7 @@ rekey_child_sa_job_t *rekey_child_sa_job_create(u_int32_t reqid,
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index dc86ba9..5366195 100644 (file)
@@ -81,6 +81,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_rekey_ike_sa_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -92,6 +98,7 @@ rekey_ike_sa_job_t *rekey_ike_sa_job_create(ike_sa_id_t *ike_sa_id, bool reauth)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 1c78abd..5b43cf8 100644 (file)
@@ -70,6 +70,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_retransmit_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header.
  */
@@ -81,6 +87,7 @@ retransmit_job_t *retransmit_job_create(u_int32_t message_id,ike_sa_id_t *ike_sa
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 74ef8bd..2e9d887 100644 (file)
@@ -85,6 +85,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_roam_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -96,6 +102,7 @@ roam_job_t *roam_job_create(bool address)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 47b5253..e3fc3b7 100644 (file)
@@ -66,6 +66,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_send_dpd_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -77,6 +83,7 @@ send_dpd_job_t *send_dpd_job_create(ike_sa_id_t *ike_sa_id)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 8d98aad..6a5070b 100644 (file)
@@ -60,6 +60,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_send_keepalive_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -71,6 +77,7 @@ send_keepalive_job_t *send_keepalive_job_create(ike_sa_id_t *ike_sa_id)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 5dda18b..63b9d7d 100644 (file)
@@ -81,6 +81,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_start_action_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -92,6 +98,7 @@ start_action_job_t *start_action_job_create(void)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 3b4e994..c4f6e47 100644 (file)
@@ -74,6 +74,12 @@ METHOD(job_t, execute, void,
        destroy(this);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_update_sa_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header
  */
@@ -85,6 +91,7 @@ update_sa_job_t *update_sa_job_create(u_int32_t reqid, host_t *new)
                .public = {
                        .job_interface = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                },
index 0043a9c..2881775 100644 (file)
@@ -227,6 +227,12 @@ METHOD(job_t, execute, void,
        thread_cleanup_pop(cleanup);
 }
 
+METHOD(job_t, get_priority, job_priority_t,
+       private_callback_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
 /*
  * Described in header.
  */
@@ -240,6 +246,7 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
                .public = {
                        .job = {
                                .execute = _execute,
+                               .get_priority = _get_priority,
                                .destroy = _destroy,
                        },
                        .cancel = _cancel,
index 0f1c16e..7b2d487 100644 (file)
 #define JOB_H_
 
 typedef struct job_t job_t;
+typedef enum job_priority_t job_priority_t;
 
 #include <library.h>
 
 /**
- * Job-Interface as it is stored in the job queue.
+ * Priority classes of jobs
+ */
+enum job_priority_t {
+       /** Short jobs executed with highest priority */
+       JOB_PRIO_HIGH = 0,
+       /** Default job priority */
+       JOB_PRIO_MEDIUM,
+       /** Low priority jobs with thread blocking operations */
+       JOB_PRIO_LOW,
+       JOB_PRIO_MAX
+};
+
+/**
+ * Job interface as it is stored in the job queue.
  */
 struct job_t {
 
@@ -41,12 +55,19 @@ struct job_t {
        void (*execute) (job_t *this);
 
        /**
+        * Get the priority of a job.
+        *
+        * @return                      job priority
+        */
+       job_priority_t (*get_priority)(job_t *this);
+
+       /**
         * Destroy a job.
         *
         * Is only called whenever a job was not executed (e.g. due daemon shutdown).
         * After execution, jobs destroy themself.
         */
-       void (*destroy) (job_t *job);
+       void (*destroy) (job_t *this);
 };
 
 #endif /** JOB_H_ @}*/