From 3ac5a0db8ca620ab1eb536dbc742c3acf8325b98 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 5 Nov 2008 11:29:56 +0000 Subject: replaced most pthread_mutex/cond_t by wrapped mutex/condvar_t variant --- src/libstrongswan/plugins/openssl/openssl_plugin.c | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/libstrongswan') diff --git a/src/libstrongswan/plugins/openssl/openssl_plugin.c b/src/libstrongswan/plugins/openssl/openssl_plugin.c index 39c4af99a..744b6e89a 100644 --- a/src/libstrongswan/plugins/openssl/openssl_plugin.c +++ b/src/libstrongswan/plugins/openssl/openssl_plugin.c @@ -24,6 +24,7 @@ #include "openssl_plugin.h" #include +#include #include "openssl_crypter.h" #include "openssl_hasher.h" #include "openssl_diffie_hellman.h" @@ -49,7 +50,7 @@ struct private_openssl_plugin_t { /** * Array of static mutexs, with CRYPTO_num_locks() mutex */ -static pthread_mutex_t *mutex; +static mutex_t **mutex; /** * Locking callback for static locks @@ -58,11 +59,11 @@ static void locking_function(int mode, int type, const char *file, int line) { if (mode & CRYPTO_LOCK) { - pthread_mutex_lock(&mutex[type]); + mutex[type]->lock(mutex[type]); } else { - pthread_mutex_unlock(&mutex[type]); + mutex[type]->unlock(mutex[type]); } } @@ -70,7 +71,7 @@ static void locking_function(int mode, int type, const char *file, int line) * Implementation of dynlock */ struct CRYPTO_dynlock_value { - pthread_mutex_t mutex; + mutex_t *mutex; }; /** @@ -81,7 +82,7 @@ static struct CRYPTO_dynlock_value *create_function(const char *file, int line) struct CRYPTO_dynlock_value *lock; lock = malloc_thing(struct CRYPTO_dynlock_value); - pthread_mutex_init(&lock->mutex, NULL); + lock->mutex = mutex_create(MUTEX_DEFAULT); return lock; } @@ -93,11 +94,11 @@ static void lock_function(int mode, struct CRYPTO_dynlock_value *lock, { if (mode & CRYPTO_LOCK) { - pthread_mutex_lock(&lock->mutex); + lock->mutex->lock(lock->mutex); } else { - pthread_mutex_unlock(&lock->mutex); + lock->mutex->unlock(lock->mutex); } } @@ -107,7 +108,7 @@ static void lock_function(int mode, struct CRYPTO_dynlock_value *lock, static void destroy_function(struct CRYPTO_dynlock_value *lock, const char *file, int line) { - pthread_mutex_destroy(&lock->mutex); + lock->mutex->destroy(lock->mutex); free(lock); } @@ -134,10 +135,10 @@ static void threading_init() CRYPTO_set_dynlock_destroy_callback(destroy_function); num_locks = CRYPTO_num_locks(); - mutex = malloc(sizeof(pthread_mutex_t) * num_locks); + mutex = malloc(sizeof(mutex_t*) * num_locks); for (i = 0; i < num_locks; i++) { - pthread_mutex_init(&mutex[i], NULL); + mutex[i] = mutex_create(MUTEX_DEFAULT); } } @@ -151,7 +152,7 @@ static void threading_cleanup() num_locks = CRYPTO_num_locks(); for (i = 0; i < num_locks; i++) { - pthread_mutex_destroy(&mutex[i]); + mutex[i]->destroy(mutex[i]); } free(mutex); } @@ -181,8 +182,6 @@ static void destroy(private_openssl_plugin_t *this) ENGINE_cleanup(); EVP_cleanup(); - threading_cleanup(); - free(this); } -- cgit v1.2.3