From 868905c5d44902e293d9837bdcca3751e2b92dc8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 29 Mar 2004 01:40:30 +0000 Subject: Inital commit git-svn-id: file:///home/lennart/svn/public/fusedav/trunk@3 e35a362c-bbd6-0310-a59f-a4efcb1729c4 --- src/openssl-thread.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/openssl-thread.c (limited to 'src/openssl-thread.c') diff --git a/src/openssl-thread.c b/src/openssl-thread.c new file mode 100644 index 0000000..8dd0506 --- /dev/null +++ b/src/openssl-thread.c @@ -0,0 +1,40 @@ +#include +#include + +static pthread_mutex_t *mutexes; + +static void pthreads_locking_callback(int mode, int n, const char *file, int line) { + if (mode & CRYPTO_LOCK) + pthread_mutex_lock(mutexes+n); + else + pthread_mutex_unlock(mutexes+n); +} + +static unsigned long pthreads_thread_id(void) { + return (unsigned long)pthread_self(); +} + +void openssl_thread_setup(void) { + int i, l; + + mutexes = OPENSSL_malloc((l = CRYPTO_num_locks()) * sizeof(pthread_mutex_t)); + + for (i = 0; i < l; i++) + pthread_mutex_init(mutexes+i, NULL); + + CRYPTO_set_id_callback(pthreads_thread_id); + CRYPTO_set_locking_callback(pthreads_locking_callback); +} + +void openssl_thread_cleanup(void) { + int i, l; + + CRYPTO_set_locking_callback(NULL); + + l = CRYPTO_num_locks(); + for (i = 0; i < l; i++) + pthread_mutex_destroy(mutexes+i); + + OPENSSL_free(mutexes); +} + -- cgit