diff options
Diffstat (limited to 'src/libstrongswan')
-rw-r--r-- | src/libstrongswan/Makefile.am | 2 | ||||
-rw-r--r-- | src/libstrongswan/asn1/asn1.c | 1 | ||||
-rw-r--r-- | src/libstrongswan/credentials/credential_factory.c | 14 | ||||
-rw-r--r-- | src/libstrongswan/library.c | 6 | ||||
-rw-r--r-- | src/libstrongswan/plugins/mysql/mysql_database.c | 17 | ||||
-rw-r--r-- | src/libstrongswan/plugins/openssl/openssl_plugin.c | 4 | ||||
-rw-r--r-- | src/libstrongswan/printf_hook.c | 18 | ||||
-rw-r--r-- | src/libstrongswan/threading/mutex.c | 1 | ||||
-rw-r--r-- | src/libstrongswan/threading/mutex.h | 29 |
9 files changed, 31 insertions, 61 deletions
diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am index fd297a0b7..7ee15052c 100644 --- a/src/libstrongswan/Makefile.am +++ b/src/libstrongswan/Makefile.am @@ -43,6 +43,8 @@ credentials/ietf_attributes/ietf_attributes.c credentials/ietf_attributes/ietf_a database/database.h database/database_factory.h database/database_factory.c \ fetcher/fetcher.h fetcher/fetcher_manager.h fetcher/fetcher_manager.c \ selectors/traffic_selector.c selectors/traffic_selector.h \ +threading/thread.h threading/thread.c \ +threading/thread_value.h threading/thread_value.c \ threading/mutex.h threading/mutex.c threading/condvar.h \ threading/rwlock.h threading/rwlock.c \ threading/lock_profiler.h \ diff --git a/src/libstrongswan/asn1/asn1.c b/src/libstrongswan/asn1/asn1.c index 0b6859690..fffc18863 100644 --- a/src/libstrongswan/asn1/asn1.c +++ b/src/libstrongswan/asn1/asn1.c @@ -18,7 +18,6 @@ #include <stdio.h> #include <string.h> #include <time.h> -#include <pthread.h> #include <utils.h> #include <debug.h> diff --git a/src/libstrongswan/credentials/credential_factory.c b/src/libstrongswan/credentials/credential_factory.c index ff2393f69..5139ad504 100644 --- a/src/libstrongswan/credentials/credential_factory.c +++ b/src/libstrongswan/credentials/credential_factory.c @@ -14,12 +14,12 @@ */ #include <stdint.h> -#include <pthread.h> #include "credential_factory.h" #include <debug.h> #include <utils/linked_list.h> +#include <threading/thread_value.h> #include <threading/rwlock.h> #include <credentials/certificates/x509.h> @@ -50,7 +50,7 @@ struct private_credential_factory_t { /** * Thread specific recursiveness counter */ - pthread_key_t recursive; + thread_value_t *recursive; /** * lock access to builders @@ -121,8 +121,8 @@ static void* create(private_credential_factory_t *this, credential_type_t type, int failures = 0; uintptr_t level; - level = (uintptr_t)pthread_getspecific(this->recursive); - pthread_setspecific(this->recursive, (void*)level + 1); + level = (uintptr_t)this->recursive->get(this->recursive); + this->recursive->set(this->recursive, (void*)level + 1); this->lock->read_lock(this->lock); enumerator = this->constructors->create_enumerator(this->constructors); @@ -154,7 +154,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type, DBG1("building %N - %N failed, tried %d builders", credential_type_names, type, names, subtype, failures); } - pthread_setspecific(this->recursive, (void*)level); + this->recursive->set(this->recursive, (void*)level); return construct; } @@ -164,7 +164,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type, static void destroy(private_credential_factory_t *this) { this->constructors->destroy_function(this->constructors, free); - pthread_key_delete(this->recursive); + this->recursive->destroy(this->recursive); this->lock->destroy(this->lock); free(this); } @@ -182,7 +182,7 @@ credential_factory_t *credential_factory_create() this->public.destroy = (void(*)(credential_factory_t*))destroy; this->constructors = linked_list_create(); - pthread_key_create(&this->recursive, NULL); + this->recursive = thread_value_create(NULL); this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT); return &this->public; diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index 5aeb5c038..4e8bb87d0 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -21,6 +21,7 @@ #include <utils.h> #include <chunk.h> #include <debug.h> +#include <threading/thread.h> #include <utils/identification.h> #include <utils/host.h> #ifdef LEAK_DETECTIVE @@ -81,6 +82,9 @@ void library_deinit() this->detective->destroy(this->detective); } #endif /* LEAK_DETECTIVE */ + + threads_deinit(); + free(this); lib = NULL; } @@ -94,6 +98,8 @@ bool library_init(char *settings) private_library_t *this = malloc_thing(private_library_t); lib = &this->public; + threads_init(); + lib->leak_detective = FALSE; #ifdef LEAK_DETECTIVE diff --git a/src/libstrongswan/plugins/mysql/mysql_database.c b/src/libstrongswan/plugins/mysql/mysql_database.c index 6c2a25b50..2338428f2 100644 --- a/src/libstrongswan/plugins/mysql/mysql_database.c +++ b/src/libstrongswan/plugins/mysql/mysql_database.c @@ -15,12 +15,12 @@ #define _GNU_SOURCE #include <string.h> -#include <pthread.h> #include <mysql.h> #include "mysql_database.h" #include <debug.h> +#include <threading/thread_value.h> #include <threading/mutex.h> #include <utils/linked_list.h> @@ -104,19 +104,20 @@ static void conn_release(conn_t *conn) { conn->in_use = FALSE; } + /** * thread specific initialization flag */ -pthread_key_t initialized; +thread_value_t *initialized; /** * Initialize a thread for mysql usage */ static void thread_initialize() { - if (pthread_getspecific(initialized) == NULL) + if (initialized->get(initialized) == NULL) { - pthread_setspecific(initialized, (void*)TRUE); + initialized->set(initialized, (void*)TRUE); mysql_thread_init(); } } @@ -130,11 +131,7 @@ bool mysql_database_init() { return FALSE; } - if (pthread_key_create(&initialized, (void*)mysql_thread_end)) - { - mysql_library_end(); - return FALSE; - } + initialized = thread_value_create((thread_cleanup_t)mysql_thread_end); return TRUE; } @@ -143,7 +140,7 @@ bool mysql_database_init() */ void mysql_database_deinit() { - pthread_key_delete(initialized); + initialized->destroy(initialized); mysql_thread_end(); /* mysql_library_end(); would be the clean way, however, it hangs... */ } diff --git a/src/libstrongswan/plugins/openssl/openssl_plugin.c b/src/libstrongswan/plugins/openssl/openssl_plugin.c index 46446fc25..548a76bb4 100644 --- a/src/libstrongswan/plugins/openssl/openssl_plugin.c +++ b/src/libstrongswan/plugins/openssl/openssl_plugin.c @@ -18,11 +18,11 @@ #include <openssl/evp.h> #include <openssl/engine.h> #include <openssl/crypto.h> -#include <pthread.h> #include "openssl_plugin.h" #include <library.h> +#include <threading/thread.h> #include <threading/mutex.h> #include "openssl_util.h" #include "openssl_crypter.h" @@ -120,7 +120,7 @@ static void destroy_function(struct CRYPTO_dynlock_value *lock, */ static unsigned long id_function(void) { - return (unsigned long)pthread_self(); + return (unsigned long)thread_current_id(); } /** diff --git a/src/libstrongswan/printf_hook.c b/src/libstrongswan/printf_hook.c index df3c7c810..0b516c99e 100644 --- a/src/libstrongswan/printf_hook.c +++ b/src/libstrongswan/printf_hook.c @@ -191,15 +191,9 @@ static void vstr_fmt_add_handler(Vstr_conf *conf, printf_hook_handler_t *handler /** * Management of thread-specific Vstr_conf objects */ -#include <pthread.h> +#include <threading/thread_value.h> -static pthread_key_t vstr_conf_key; -static pthread_once_t vstr_conf_key_once = PTHREAD_ONCE_INIT; - -static void init_vstr_conf_key(void) -{ - pthread_key_create(&vstr_conf_key, (void*)vstr_free_conf); -} +static thread_value_t *vstr_conf; static Vstr_conf *create_vstr_conf() { @@ -223,12 +217,11 @@ static Vstr_conf *create_vstr_conf() static inline Vstr_conf *get_vstr_conf() { Vstr_conf *conf; - pthread_once(&vstr_conf_key_once, init_vstr_conf_key); - conf = (Vstr_conf*)pthread_getspecific(vstr_conf_key); + conf = (Vstr_conf*)vstr_conf->get(vstr_conf); if (!conf) { conf = create_vstr_conf(); - pthread_setspecific(vstr_conf_key, conf); + vstr_conf->set(vstr_conf, conf); } return conf; } @@ -412,7 +405,7 @@ static void destroy(private_printf_hook_t *this) #ifdef USE_VSTR /* freeing the Vstr_conf of the main thread */ - pthread_key_delete(vstr_conf_key); + vstr_conf->destroy(vstr_conf); vstr_free_conf(conf); vstr_exit(); #endif @@ -438,6 +431,7 @@ printf_hook_t *printf_hook_create() free(this); return NULL; } + vstr_conf = thread_value_create((thread_cleanup_t)vstr_free_conf); #endif return &this->public; diff --git a/src/libstrongswan/threading/mutex.c b/src/libstrongswan/threading/mutex.c index 0bfe06959..9c05ff044 100644 --- a/src/libstrongswan/threading/mutex.c +++ b/src/libstrongswan/threading/mutex.c @@ -23,6 +23,7 @@ #include <library.h> #include <debug.h> +#include "condvar.h" #include "mutex.h" #include "lock_profiler.h" diff --git a/src/libstrongswan/threading/mutex.h b/src/libstrongswan/threading/mutex.h index ca242f680..ac36b6a25 100644 --- a/src/libstrongswan/threading/mutex.h +++ b/src/libstrongswan/threading/mutex.h @@ -25,35 +25,6 @@ typedef struct mutex_t mutex_t; typedef enum mutex_type_t mutex_type_t; -#include "condvar.h" - -#ifdef __APPLE__ -/* on Mac OS X 10.5 several system calls we use are no cancellation points. - * fortunately, select isn't one of them, so we wrap some of the others with - * calls to select(2). - */ -#include <sys/socket.h> -#include <sys/select.h> - -#define WRAP_WITH_SELECT(func, socket, ...)\ - fd_set rfds; FD_ZERO(&rfds); FD_SET(socket, &rfds);\ - if (select(socket + 1, &rfds, NULL, NULL, NULL) <= 0) { return -1; }\ - return func(socket, __VA_ARGS__) - -static inline int cancellable_accept(int socket, struct sockaddr *address, - socklen_t *address_len) -{ - WRAP_WITH_SELECT(accept, socket, address, address_len); -} -#define accept cancellable_accept -static inline int cancellable_recvfrom(int socket, void *buffer, size_t length, - int flags, struct sockaddr *address, socklen_t *address_len) -{ - WRAP_WITH_SELECT(recvfrom, socket, buffer, length, flags, address, address_len); -} -#define recvfrom cancellable_recvfrom -#endif /* __APPLE__ */ - /** * Type of mutex. */ |