summaryrefslogtreecommitdiff
path: root/src/libstrongswan/processing/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/processing/jobs')
-rw-r--r--src/libstrongswan/processing/jobs/callback_job.c31
-rw-r--r--src/libstrongswan/processing/jobs/callback_job.h16
-rw-r--r--src/libstrongswan/processing/jobs/job.c23
-rw-r--r--src/libstrongswan/processing/jobs/job.h32
4 files changed, 96 insertions, 6 deletions
diff --git a/src/libstrongswan/processing/jobs/callback_job.c b/src/libstrongswan/processing/jobs/callback_job.c
index 0043a9cdb..13f22e69c 100644
--- a/src/libstrongswan/processing/jobs/callback_job.c
+++ b/src/libstrongswan/processing/jobs/callback_job.c
@@ -62,7 +62,7 @@ struct private_callback_job_t {
mutex_t *mutex;
/**
- * list of asociated child jobs
+ * list of associated child jobs
*/
linked_list_t *children;
@@ -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;
};
/**
@@ -227,12 +232,18 @@ METHOD(job_t, execute, void,
thread_cleanup_pop(cleanup);
}
+METHOD(job_t, get_priority, job_priority_t,
+ private_callback_job_t *this)
+{
+ 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;
@@ -240,6 +251,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,
@@ -251,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 */
@@ -264,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);
+}
diff --git a/src/libstrongswan/processing/jobs/callback_job.h b/src/libstrongswan/processing/jobs/callback_job.h
index 1eb5664d3..3e92b01c0 100644
--- a/src/libstrongswan/processing/jobs/callback_job.h
+++ b/src/libstrongswan/processing/jobs/callback_job.h
@@ -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_ @}*/
diff --git a/src/libstrongswan/processing/jobs/job.c b/src/libstrongswan/processing/jobs/job.c
new file mode 100644
index 000000000..ccb897173
--- /dev/null
+++ b/src/libstrongswan/processing/jobs/job.c
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2011 Martin Willi
+ * Copyright (C) 2011 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "job.h"
+
+ENUM(job_priority_names, JOB_PRIO_CRITICAL, JOB_PRIO_LOW,
+ "critical",
+ "high",
+ "medium",
+ "low",
+);
diff --git a/src/libstrongswan/processing/jobs/job.h b/src/libstrongswan/processing/jobs/job.h
index 0f1c16ebe..d25cee03e 100644
--- a/src/libstrongswan/processing/jobs/job.h
+++ b/src/libstrongswan/processing/jobs/job.h
@@ -23,11 +23,32 @@
#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 {
+ /** Critical infrastructure jobs that should always been served */
+ JOB_PRIO_CRITICAL = 0,
+ /** Short jobs executed with highest priority */
+ JOB_PRIO_HIGH,
+ /** Default job priority */
+ JOB_PRIO_MEDIUM,
+ /** Low priority jobs with thread blocking operations */
+ JOB_PRIO_LOW,
+ JOB_PRIO_MAX
+};
+
+/**
+ * Enum names for job priorities
+ */
+extern enum_name_t *job_priority_names;
+
+/**
+ * Job interface as it is stored in the job queue.
*/
struct job_t {
@@ -41,12 +62,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_ @}*/