Introduce priority classes for jobs

This commit is contained in:
Martin Willi
2011-05-16 15:24:12 +02:00
parent dfe9bad981
commit f77203bbfb
18 changed files with 147 additions and 3 deletions
@@ -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,
+23 -2
View File
@@ -23,11 +23,25 @@
#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 {
@@ -40,13 +54,20 @@ 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_ @}*/