Migrated thread_t to INIT/METHOD macros.
This commit is contained in:
@@ -113,6 +113,7 @@ static mutex_t *id_mutex;
|
|||||||
*/
|
*/
|
||||||
static thread_value_t *current_thread;
|
static thread_value_t *current_thread;
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_PTHREAD_CANCEL
|
#ifndef HAVE_PTHREAD_CANCEL
|
||||||
/* if pthread_cancel is not available, we emulate it using a signal */
|
/* if pthread_cancel is not available, we emulate it using a signal */
|
||||||
#define SIG_CANCEL (SIGRTMIN+7)
|
#define SIG_CANCEL (SIGRTMIN+7)
|
||||||
@@ -146,10 +147,8 @@ static void thread_destroy(private_thread_t *this)
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(thread_t, cancel, void,
|
||||||
* Implementation of thread_t.cancel.
|
private_thread_t *this)
|
||||||
*/
|
|
||||||
static void cancel(private_thread_t *this)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
if (pthread_equal(this->thread_id, pthread_self()))
|
if (pthread_equal(this->thread_id, pthread_self()))
|
||||||
@@ -166,10 +165,8 @@ static void cancel(private_thread_t *this)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(thread_t, kill_, void,
|
||||||
* Implementation of thread_t.kill.
|
private_thread_t *this, int sig)
|
||||||
*/
|
|
||||||
static void _kill(private_thread_t *this, int sig)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
if (pthread_equal(this->thread_id, pthread_self()))
|
if (pthread_equal(this->thread_id, pthread_self()))
|
||||||
@@ -187,10 +184,8 @@ static void _kill(private_thread_t *this, int sig)
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(thread_t, detach, void,
|
||||||
* Implementation of thread_t.detach.
|
private_thread_t *this)
|
||||||
*/
|
|
||||||
static void detach(private_thread_t *this)
|
|
||||||
{
|
{
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
pthread_detach(this->thread_id);
|
pthread_detach(this->thread_id);
|
||||||
@@ -198,10 +193,8 @@ static void detach(private_thread_t *this)
|
|||||||
thread_destroy(this);
|
thread_destroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(thread_t, join, void*,
|
||||||
* Implementation of thread_t.join.
|
private_thread_t *this)
|
||||||
*/
|
|
||||||
static void *join(private_thread_t *this)
|
|
||||||
{
|
{
|
||||||
pthread_t thread_id;
|
pthread_t thread_id;
|
||||||
void *val;
|
void *val;
|
||||||
@@ -241,22 +234,19 @@ static void *join(private_thread_t *this)
|
|||||||
*/
|
*/
|
||||||
static private_thread_t *thread_create_internal()
|
static private_thread_t *thread_create_internal()
|
||||||
{
|
{
|
||||||
private_thread_t *this = malloc_thing(private_thread_t);
|
private_thread_t *this;
|
||||||
|
|
||||||
this->public.cancel = (void(*)(thread_t*))cancel;
|
INIT(this,
|
||||||
this->public.kill = (void(*)(thread_t*,int))_kill;
|
.public = {
|
||||||
this->public.detach = (void(*)(thread_t*))detach;
|
.cancel = _cancel,
|
||||||
this->public.join = (void*(*)(thread_t*))join;
|
.kill = _kill_,
|
||||||
|
.detach = _detach,
|
||||||
this->id = 0;
|
.join = _join,
|
||||||
this->thread_id = 0;
|
},
|
||||||
this->main = NULL;
|
.cleanup_handlers = linked_list_create(),
|
||||||
this->arg = NULL;
|
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
|
||||||
this->cleanup_handlers = linked_list_create();
|
);
|
||||||
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
|
||||||
sem_init(&this->created, FALSE, 0);
|
sem_init(&this->created, FALSE, 0);
|
||||||
this->detached_or_joined = FALSE;
|
|
||||||
this->terminated = FALSE;
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -344,10 +334,12 @@ void thread_cleanup_push(thread_cleanup_t cleanup, void *arg)
|
|||||||
private_thread_t *this = (private_thread_t*)thread_current();
|
private_thread_t *this = (private_thread_t*)thread_current();
|
||||||
cleanup_handler_t *handler;
|
cleanup_handler_t *handler;
|
||||||
|
|
||||||
|
INIT(handler,
|
||||||
|
.cleanup = cleanup,
|
||||||
|
.arg = arg,
|
||||||
|
);
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
handler = malloc_thing(cleanup_handler_t);
|
|
||||||
handler->cleanup = cleanup;
|
|
||||||
handler->arg = arg;
|
|
||||||
this->cleanup_handlers->insert_last(this->cleanup_handlers, handler);
|
this->cleanup_handlers->insert_last(this->cleanup_handlers, handler);
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user