aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2015-03-27 20:16:58 +0100
committerMartin Willi <martin@revosec.ch>2015-04-13 14:50:45 +0200
commit7394ad92aeeb12316fa3710d3ac2138d7cee7c6c (patch)
treedc676f359a761a9c82678e4ab4160ae64478f814 /src
parent101d67440f0b127032b3bc1ba521fa4ed91c823f (diff)
downloadstrongswan-7394ad92aeeb12316fa3710d3ac2138d7cee7c6c.tar.bz2
strongswan-7394ad92aeeb12316fa3710d3ac2138d7cee7c6c.tar.xz
thread: Remove unneeded thread startup synchronization
sem_init() is deprecated on OS X, and it actually fails with ENOSYS. Using our wrapped semaphore object is not an option, as it relies on the thread cleanup that we can't rely on at this stage. It is unclear why startup synchronization is required, as we can allocate the thread ID just before creating the pthread. There is a chance that we allocate a thread ID for a thread that fails to create, but the risk and consequences are negligible.
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/threading/thread.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/libstrongswan/threading/thread.c b/src/libstrongswan/threading/thread.c
index 593f44a44..2bf86c158 100644
--- a/src/libstrongswan/threading/thread.c
+++ b/src/libstrongswan/threading/thread.c
@@ -16,7 +16,6 @@
#define _GNU_SOURCE
#include <pthread.h>
#include <signal.h>
-#include <semaphore.h>
#ifdef HAVE_GETTID
#include <sys/types.h>
@@ -79,11 +78,6 @@ struct private_thread_t {
mutex_t *mutex;
/**
- * Semaphore used to sync the creation/start of the thread.
- */
- sem_t created;
-
- /**
* TRUE if this thread has been detached or joined, i.e. can be cleaned
* up after terminating.
*/
@@ -160,7 +154,6 @@ static void thread_destroy(private_thread_t *this)
this->cleanup_handlers->destroy(this->cleanup_handlers);
this->mutex->unlock(this->mutex);
this->mutex->destroy(this->mutex);
- sem_destroy(&this->created);
free(this);
}
@@ -263,7 +256,6 @@ static private_thread_t *thread_create_internal()
.cleanup_handlers = linked_list_create(),
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
);
- sem_init(&this->created, FALSE, 0);
return this;
}
@@ -292,7 +284,6 @@ static void *thread_main(private_thread_t *this)
{
void *res;
- sem_wait(&this->created);
current_thread->set(current_thread, this);
pthread_cleanup_push((thread_cleanup_t)thread_cleanup, this);
@@ -324,6 +315,10 @@ thread_t *thread_create(thread_main_t main, void *arg)
this->main = main;
this->arg = arg;
+ id_mutex->lock(id_mutex);
+ this->id = next_id++;
+ id_mutex->unlock(id_mutex);
+
if (pthread_create(&this->thread_id, NULL, (void*)thread_main, this) != 0)
{
DBG1(DBG_LIB, "failed to create thread!");
@@ -331,10 +326,6 @@ thread_t *thread_create(thread_main_t main, void *arg)
thread_destroy(this);
return NULL;
}
- id_mutex->lock(id_mutex);
- this->id = next_id++;
- id_mutex->unlock(id_mutex);
- sem_post(&this->created);
return &this->public;
}