Migrated processor to INIT/METHOD macros
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2007 Martin Willi
|
* Copyright (C) 2005-2011 Martin Willi
|
||||||
|
* Copyright (C) 2011 revosec AG
|
||||||
* Copyright (C) 2005 Jan Hutter
|
* Copyright (C) 2005 Jan Hutter
|
||||||
* Hochschule fuer Technik Rapperswil
|
* Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
@@ -141,46 +142,41 @@ static void process_jobs(private_processor_t *this)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(processor_t, get_total_threads, u_int,
|
||||||
* Implementation of processor_t.get_total_threads.
|
private_processor_t *this)
|
||||||
*/
|
|
||||||
static u_int get_total_threads(private_processor_t *this)
|
|
||||||
{
|
{
|
||||||
u_int count;
|
u_int count;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
count = this->total_threads;
|
count = this->total_threads;
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(processor_t, get_idle_threads, u_int,
|
||||||
* Implementation of processor_t.get_idle_threads.
|
private_processor_t *this)
|
||||||
*/
|
|
||||||
static u_int get_idle_threads(private_processor_t *this)
|
|
||||||
{
|
{
|
||||||
u_int count;
|
u_int count;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
count = this->idle_threads;
|
count = this->idle_threads;
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(processor_t, get_job_load, u_int,
|
||||||
* implements processor_t.get_job_load
|
private_processor_t *this)
|
||||||
*/
|
|
||||||
static u_int get_job_load(private_processor_t *this)
|
|
||||||
{
|
{
|
||||||
u_int load;
|
u_int load;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
load = this->list->get_count(this->list);
|
load = this->list->get_count(this->list);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
return load;
|
return load;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(processor_t, queue_job, void,
|
||||||
* implements function processor_t.queue_job
|
private_processor_t *this, job_t *job)
|
||||||
*/
|
|
||||||
static void queue_job(private_processor_t *this, job_t *job)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
this->list->insert_last(this->list, job);
|
this->list->insert_last(this->list, job);
|
||||||
@@ -188,10 +184,8 @@ static void queue_job(private_processor_t *this, job_t *job)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(processor_t, set_threads, void,
|
||||||
* Implementation of processor_t.set_threads.
|
private_processor_t *this, u_int count)
|
||||||
*/
|
|
||||||
static void set_threads(private_processor_t *this, u_int count)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
if (count > this->total_threads)
|
if (count > this->total_threads)
|
||||||
@@ -219,12 +213,11 @@ static void set_threads(private_processor_t *this, u_int count)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(processor_t, destroy, void,
|
||||||
* Implementation of processor_t.destroy.
|
private_processor_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_processor_t *this)
|
|
||||||
{
|
{
|
||||||
thread_t *current;
|
thread_t *current;
|
||||||
|
|
||||||
set_threads(this, 0);
|
set_threads(this, 0);
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
while (this->total_threads > 0)
|
while (this->total_threads > 0)
|
||||||
@@ -251,23 +244,23 @@ static void destroy(private_processor_t *this)
|
|||||||
*/
|
*/
|
||||||
processor_t *processor_create()
|
processor_t *processor_create()
|
||||||
{
|
{
|
||||||
private_processor_t *this = malloc_thing(private_processor_t);
|
private_processor_t *this;
|
||||||
|
|
||||||
this->public.get_total_threads = (u_int(*)(processor_t*))get_total_threads;
|
INIT(this,
|
||||||
this->public.get_idle_threads = (u_int(*)(processor_t*))get_idle_threads;
|
.public = {
|
||||||
this->public.get_job_load = (u_int(*)(processor_t*))get_job_load;
|
.get_total_threads = _get_total_threads,
|
||||||
this->public.queue_job = (void(*)(processor_t*, job_t*))queue_job;
|
.get_idle_threads = _get_idle_threads,
|
||||||
this->public.set_threads = (void(*)(processor_t*, u_int))set_threads;
|
.get_job_load = _get_job_load,
|
||||||
this->public.destroy = (void(*)(processor_t*))destroy;
|
.queue_job = _queue_job,
|
||||||
|
.set_threads = _set_threads,
|
||||||
this->list = linked_list_create();
|
.destroy = _destroy,
|
||||||
this->threads = linked_list_create();
|
},
|
||||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
.list = linked_list_create(),
|
||||||
this->job_added = condvar_create(CONDVAR_TYPE_DEFAULT);
|
.threads = linked_list_create(),
|
||||||
this->thread_terminated = condvar_create(CONDVAR_TYPE_DEFAULT);
|
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||||
this->total_threads = 0;
|
.job_added = condvar_create(CONDVAR_TYPE_DEFAULT),
|
||||||
this->desired_threads = 0;
|
.thread_terminated = condvar_create(CONDVAR_TYPE_DEFAULT),
|
||||||
this->idle_threads = 0;
|
);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user