Migrated callback_job to INIT/METHOD macros
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2009 Tobias Brunner
|
* 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
|
* Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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.
|
* Private data of an callback_job_t Object.
|
||||||
*/
|
*/
|
||||||
struct private_callback_job_t {
|
struct private_callback_job_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public callback_job_t interface.
|
* Public callback_job_t interface.
|
||||||
*/
|
*/
|
||||||
@@ -111,10 +113,8 @@ static void unregister(private_callback_job_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(job_t, destroy, void,
|
||||||
* Implements job_t.destroy.
|
private_callback_job_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_callback_job_t *this)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
unregister(this);
|
unregister(this);
|
||||||
@@ -133,10 +133,8 @@ static void destroy(private_callback_job_t *this)
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(callback_job_t, cancel, void,
|
||||||
* Implementation of callback_job_t.cancel.
|
private_callback_job_t *this)
|
||||||
*/
|
|
||||||
static void cancel(private_callback_job_t *this)
|
|
||||||
{
|
{
|
||||||
callback_job_t *child;
|
callback_job_t *child;
|
||||||
sem_t *terminated = NULL;
|
sem_t *terminated = NULL;
|
||||||
@@ -177,10 +175,8 @@ static void cancel(private_callback_job_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(job_t, execute, void,
|
||||||
* Implementation of job_t.execute.
|
private_callback_job_t *this)
|
||||||
*/
|
|
||||||
static void execute(private_callback_job_t *this)
|
|
||||||
{
|
{
|
||||||
bool cleanup = FALSE, requeue = FALSE;
|
bool cleanup = FALSE, requeue = FALSE;
|
||||||
|
|
||||||
@@ -226,8 +222,7 @@ static void execute(private_callback_job_t *this)
|
|||||||
thread_cancellation_point();
|
thread_cancellation_point();
|
||||||
if (requeue)
|
if (requeue)
|
||||||
{
|
{
|
||||||
lib->processor->queue_job(lib->processor,
|
lib->processor->queue_job(lib->processor, &this->public.job);
|
||||||
&this->public.job_interface);
|
|
||||||
}
|
}
|
||||||
thread_cleanup_pop(cleanup);
|
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_cleanup_t cleanup,
|
||||||
callback_job_t *parent)
|
callback_job_t *parent)
|
||||||
{
|
{
|
||||||
private_callback_job_t *this = malloc_thing(private_callback_job_t);
|
private_callback_job_t *this;
|
||||||
|
|
||||||
/* interface functions */
|
INIT(this,
|
||||||
this->public.job_interface.execute = (void (*) (job_t *)) execute;
|
.public = {
|
||||||
this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
|
.job = {
|
||||||
this->public.cancel = (void(*)(callback_job_t*))cancel;
|
.execute = _execute,
|
||||||
|
.destroy = _destroy,
|
||||||
/* private variables */
|
},
|
||||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
.cancel = _cancel,
|
||||||
this->callback = cb;
|
},
|
||||||
this->data = data;
|
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||||
this->cleanup = cleanup;
|
.callback = cb,
|
||||||
this->thread = 0;
|
.data = data,
|
||||||
this->children = linked_list_create();
|
.cleanup = cleanup,
|
||||||
this->parent = (private_callback_job_t*)parent;
|
.children = linked_list_create(),
|
||||||
this->cancelled = FALSE;
|
.parent = (private_callback_job_t*)parent,
|
||||||
this->destroyable = condvar_create(CONDVAR_TYPE_DEFAULT);
|
.destroyable = condvar_create(CONDVAR_TYPE_DEFAULT),
|
||||||
this->terminated = NULL;
|
);
|
||||||
|
|
||||||
/* register us at parent */
|
/* register us at parent */
|
||||||
if (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
|
* Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it
|
* 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;
|
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
|
* The job requeueing policy defines how a job is handled when the callback
|
||||||
* function returns.
|
* function returns.
|
||||||
@@ -84,15 +85,19 @@ typedef void (*callback_job_cleanup_t)(void *data);
|
|||||||
* of asynchronous methods, without to manage threads.
|
* of asynchronous methods, without to manage threads.
|
||||||
*/
|
*/
|
||||||
struct callback_job_t {
|
struct callback_job_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The job_t interface.
|
* The job_t interface.
|
||||||
*/
|
*/
|
||||||
job_t job_interface;
|
job_t job;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel the job's thread and wait for its termination. This only works
|
* Cancel the job's thread and wait for its termination.
|
||||||
* reliably for jobs that always use JOB_REQUEUE_FAIR or JOB_REQUEUE_DIRECT,
|
*
|
||||||
* otherwise the job may already be destroyed when cancel is called. */
|
* 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);
|
void (*cancel)(callback_job_t *this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user