From: Tobias Brunner Date: Mon, 3 Oct 2011 13:54:36 +0000 (+0200) Subject: Migrated thread_t to INIT/METHOD macros. X-Git-Tag: 4.6.0~304 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8541efe709bf8b916186bdac45a2b36f721c948;p=thirdparty%2Fstrongswan.git Migrated thread_t to INIT/METHOD macros. --- diff --git a/src/libstrongswan/threading/thread.c b/src/libstrongswan/threading/thread.c index fcc0019d88..5b6f0d2ce9 100644 --- a/src/libstrongswan/threading/thread.c +++ b/src/libstrongswan/threading/thread.c @@ -113,6 +113,7 @@ static mutex_t *id_mutex; */ static thread_value_t *current_thread; + #ifndef HAVE_PTHREAD_CANCEL /* if pthread_cancel is not available, we emulate it using a signal */ #define SIG_CANCEL (SIGRTMIN+7) @@ -146,10 +147,8 @@ static void thread_destroy(private_thread_t *this) free(this); } -/** - * Implementation of thread_t.cancel. - */ -static void cancel(private_thread_t *this) +METHOD(thread_t, cancel, void, + private_thread_t *this) { this->mutex->lock(this->mutex); if (pthread_equal(this->thread_id, pthread_self())) @@ -166,10 +165,8 @@ static void cancel(private_thread_t *this) this->mutex->unlock(this->mutex); } -/** - * Implementation of thread_t.kill. - */ -static void _kill(private_thread_t *this, int sig) +METHOD(thread_t, kill_, void, + private_thread_t *this, int sig) { this->mutex->lock(this->mutex); 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); } -/** - * Implementation of thread_t.detach. - */ -static void detach(private_thread_t *this) +METHOD(thread_t, detach, void, + private_thread_t *this) { this->mutex->lock(this->mutex); pthread_detach(this->thread_id); @@ -198,10 +193,8 @@ static void detach(private_thread_t *this) thread_destroy(this); } -/** - * Implementation of thread_t.join. - */ -static void *join(private_thread_t *this) +METHOD(thread_t, join, void*, + private_thread_t *this) { pthread_t thread_id; void *val; @@ -241,22 +234,19 @@ static void *join(private_thread_t *this) */ static private_thread_t *thread_create_internal() { - private_thread_t *this = malloc_thing(private_thread_t); - - this->public.cancel = (void(*)(thread_t*))cancel; - this->public.kill = (void(*)(thread_t*,int))_kill; - this->public.detach = (void(*)(thread_t*))detach; - this->public.join = (void*(*)(thread_t*))join; - - this->id = 0; - this->thread_id = 0; - this->main = NULL; - this->arg = NULL; - this->cleanup_handlers = linked_list_create(); - this->mutex = mutex_create(MUTEX_TYPE_DEFAULT); + private_thread_t *this; + + INIT(this, + .public = { + .cancel = _cancel, + .kill = _kill_, + .detach = _detach, + .join = _join, + }, + .cleanup_handlers = linked_list_create(), + .mutex = mutex_create(MUTEX_TYPE_DEFAULT), + ); sem_init(&this->created, FALSE, 0); - this->detached_or_joined = FALSE; - this->terminated = FALSE; 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(); cleanup_handler_t *handler; + INIT(handler, + .cleanup = cleanup, + .arg = arg, + ); + 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->mutex->unlock(this->mutex); }