Migrated callback_job to INIT/METHOD macros

This commit is contained in:
Martin Willi
2011-05-05 11:14:51 +02:00
parent 3316742969
commit cda46be72a
2 changed files with 38 additions and 38 deletions
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2009 Tobias Brunner
* Copyright (C) 2007 Martin Willi
* Copyright (C) 2007-2011 Martin Willi
* Copyright (C) 2011 revosec AG
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -29,6 +30,7 @@ typedef struct private_callback_job_t private_callback_job_t;
* Private data of an callback_job_t Object.
*/
struct private_callback_job_t {
/**
* Public callback_job_t interface.
*/
@@ -111,10 +113,8 @@ static void unregister(private_callback_job_t *this)
}
}
/**
* Implements job_t.destroy.
*/
static void destroy(private_callback_job_t *this)
METHOD(job_t, destroy, void,
private_callback_job_t *this)
{
this->mutex->lock(this->mutex);
unregister(this);
@@ -133,10 +133,8 @@ static void destroy(private_callback_job_t *this)
free(this);
}
/**
* Implementation of callback_job_t.cancel.
*/
static void cancel(private_callback_job_t *this)
METHOD(callback_job_t, cancel, void,
private_callback_job_t *this)
{
callback_job_t *child;
sem_t *terminated = NULL;
@@ -177,10 +175,8 @@ static void cancel(private_callback_job_t *this)
}
}
/**
* Implementation of job_t.execute.
*/
static void execute(private_callback_job_t *this)
METHOD(job_t, execute, void,
private_callback_job_t *this)
{
bool cleanup = FALSE, requeue = FALSE;
@@ -226,8 +222,7 @@ static void execute(private_callback_job_t *this)
thread_cancellation_point();
if (requeue)
{
lib->processor->queue_job(lib->processor,
&this->public.job_interface);
lib->processor->queue_job(lib->processor, &this->public.job);
}
thread_cleanup_pop(cleanup);
}
@@ -239,24 +234,24 @@ callback_job_t *callback_job_create(callback_job_cb_t cb, void *data,
callback_job_cleanup_t cleanup,
callback_job_t *parent)
{
private_callback_job_t *this = malloc_thing(private_callback_job_t);
private_callback_job_t *this;
/* interface functions */
this->public.job_interface.execute = (void (*) (job_t *)) execute;
this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
this->public.cancel = (void(*)(callback_job_t*))cancel;
/* private variables */
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
this->callback = cb;
this->data = data;
this->cleanup = cleanup;
this->thread = 0;
this->children = linked_list_create();
this->parent = (private_callback_job_t*)parent;
this->cancelled = FALSE;
this->destroyable = condvar_create(CONDVAR_TYPE_DEFAULT);
this->terminated = NULL;
INIT(this,
.public = {
.job = {
.execute = _execute,
.destroy = _destroy,
},
.cancel = _cancel,
},
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
.callback = cb,
.data = data,
.cleanup = cleanup,
.children = linked_list_create(),
.parent = (private_callback_job_t*)parent,
.destroyable = condvar_create(CONDVAR_TYPE_DEFAULT),
);
/* register us at parent */
if (parent)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007 Martin Willi
* Copyright (C) 2007-2011 Martin Willi
* Copyright (C) 2011 revosec AG
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -30,7 +31,7 @@ typedef struct callback_job_t callback_job_t;
typedef enum job_requeue_t job_requeue_t;
/**
* Job requeueing policy
* Job requeueing policy.
*
* The job requeueing policy defines how a job is handled when the callback
* function returns.
@@ -84,15 +85,19 @@ typedef void (*callback_job_cleanup_t)(void *data);
* of asynchronous methods, without to manage threads.
*/
struct callback_job_t {
/**
* The job_t interface.
*/
job_t job_interface;
job_t job;
/**
* Cancel the job's thread and wait for its termination. This only works
* reliably for jobs that always use JOB_REQUEUE_FAIR or JOB_REQUEUE_DIRECT,
* otherwise the job may already be destroyed when cancel is called. */
* Cancel the job's thread and wait for its termination.
*
* This only works reliably for jobs that always use JOB_REQUEUE_FAIR or
* JOB_REQUEUE_DIRECT, otherwise the job may already be destroyed when
* cancel is called.
*/
void (*cancel)(callback_job_t *this);
};