Migrated scheduler_t to INIT/METHOD macros

This commit is contained in:
Martin Willi
2011-05-05 11:14:51 +02:00
parent cda46be72a
commit e7643c92d3
+23 -32
View File
@@ -232,10 +232,8 @@ static job_requeue_t schedule(private_scheduler_t * this)
return JOB_REQUEUE_DIRECT; return JOB_REQUEUE_DIRECT;
} }
/** METHOD(scheduler_t, get_job_load, u_int,
* Implements scheduler_t.get_job_load private_scheduler_t *this)
*/
static u_int get_job_load(private_scheduler_t *this)
{ {
int count; int count;
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
@@ -244,10 +242,8 @@ static u_int get_job_load(private_scheduler_t *this)
return count; return count;
} }
/** METHOD(scheduler_t, schedule_job_tv, void,
* Implements scheduler_t.schedule_job_tv. private_scheduler_t *this, job_t *job, timeval_t tv)
*/
static void schedule_job_tv(private_scheduler_t *this, job_t *job, timeval_t tv)
{ {
event_t *event; event_t *event;
u_int position; u_int position;
@@ -283,10 +279,8 @@ static void schedule_job_tv(private_scheduler_t *this, job_t *job, timeval_t tv)
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(scheduler_t, schedule_job, void,
* Implements scheduler_t.schedule_job. private_scheduler_t *this, job_t *job, u_int32_t s)
*/
static void schedule_job(private_scheduler_t *this, job_t *job, u_int32_t s)
{ {
timeval_t tv; timeval_t tv;
@@ -296,10 +290,8 @@ static void schedule_job(private_scheduler_t *this, job_t *job, u_int32_t s)
schedule_job_tv(this, job, tv); schedule_job_tv(this, job, tv);
} }
/** METHOD(scheduler_t, schedule_job_ms, void,
* Implements scheduler_t.schedule_job_ms. private_scheduler_t *this, job_t *job, u_int32_t ms)
*/
static void schedule_job_ms(private_scheduler_t *this, job_t *job, u_int32_t ms)
{ {
timeval_t tv, add; timeval_t tv, add;
@@ -312,10 +304,8 @@ static void schedule_job_ms(private_scheduler_t *this, job_t *job, u_int32_t ms)
schedule_job_tv(this, job, tv); schedule_job_tv(this, job, tv);
} }
/** METHOD(scheduler_t, destroy, void,
* Implementation of scheduler_t.destroy. private_scheduler_t *this)
*/
static void destroy(private_scheduler_t *this)
{ {
event_t *event; event_t *event;
this->job->cancel(this->job); this->job->cancel(this->job);
@@ -334,22 +324,23 @@ static void destroy(private_scheduler_t *this)
*/ */
scheduler_t * scheduler_create() scheduler_t * scheduler_create()
{ {
private_scheduler_t *this = malloc_thing(private_scheduler_t); private_scheduler_t *this;
this->public.get_job_load = (u_int (*) (scheduler_t *this)) get_job_load; INIT(this,
this->public.schedule_job = (void (*) (scheduler_t *this, job_t *job, u_int32_t s)) schedule_job; .public = {
this->public.schedule_job_ms = (void (*) (scheduler_t *this, job_t *job, u_int32_t ms)) schedule_job_ms; .get_job_load = _get_job_load,
this->public.schedule_job_tv = (void (*) (scheduler_t *this, job_t *job, timeval_t tv)) schedule_job_tv; .schedule_job = _schedule_job,
this->public.destroy = (void(*)(scheduler_t*)) destroy; .schedule_job_ms = _schedule_job_ms,
.schedule_job_tv = _schedule_job_tv,
.destroy = _destroy,
},
.heap_size = HEAP_SIZE_DEFAULT,
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
.condvar = condvar_create(CONDVAR_TYPE_DEFAULT),
);
/* Note: the root of the heap is at index 1 */
this->event_count = 0;
this->heap_size = HEAP_SIZE_DEFAULT;
this->heap = (event_t**)calloc(this->heap_size + 1, sizeof(event_t*)); this->heap = (event_t**)calloc(this->heap_size + 1, sizeof(event_t*));
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
this->job = callback_job_create((callback_job_cb_t)schedule, this, NULL, NULL); this->job = callback_job_create((callback_job_cb_t)schedule, this, NULL, NULL);
lib->processor->queue_job(lib->processor, (job_t*)this->job); lib->processor->queue_job(lib->processor, (job_t*)this->job);