diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-06-13 16:35:12 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-06-13 16:35:12 +0000 |
commit | d4ed91c672183d86c6f5fd0150869f8888fd723d (patch) | |
tree | 8c3272877f61dad1c95d1c656b43a5465df95caf /src/common/crypto.c | |
parent | 8f5afe4937d6b96832492aa616cdddca22ede897 (diff) | |
download | tor-d4ed91c672183d86c6f5fd0150869f8888fd723d.tar.gz tor-d4ed91c672183d86c6f5fd0150869f8888fd723d.zip |
Set dynamic-locking callbacks in openssl. These can be more efficient when openssl uses them.
svn:r15222
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r-- | src/common/crypto.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 18c5b81e0a..eb1af30daa 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2227,6 +2227,43 @@ _openssl_locking_cb(int mode, int n, const char *file, int line) tor_mutex_release(_openssl_mutexes[n]); } +struct CRYPTO_dynlock_value { + tor_mutex_t *lock; +}; + +static struct CRYPTO_dynlock_value * +_openssl_dynlock_create_cb(const char *file, int line) +{ + struct CRYPTO_dynlock_value *v; + (void)file; + (void)line; + v = tor_malloc(sizeof(struct CRYPTO_dynlock_value)); + v->lock = tor_mutex_new(); + return v; +} + +static void +_openssl_dynlock_lock_cb(int mode, struct CRYPTO_dynlock_value *v, + const char *file, int line) +{ + (void)file; + (void)line; + if (mode & CRYPTO_LOCK) + tor_mutex_acquire(v->lock); + else + tor_mutex_release(v->lock); +} + +static void +_openssl_dynlock_destroy_cb(struct CRYPTO_dynlock_value *v, + const char *file, int line) +{ + (void)file; + (void)line; + tor_mutex_free(v->lock); + tor_free(v); +} + /** Helper: Construct mutexes, and set callbacks to help OpenSSL handle being * multithreaded. */ static int @@ -2240,6 +2277,9 @@ setup_openssl_threading(void) _openssl_mutexes[i] = tor_mutex_new(); CRYPTO_set_locking_callback(_openssl_locking_cb); CRYPTO_set_id_callback(tor_get_thread_id); + CRYPTO_set_dynlock_create_callback(_openssl_dynlock_create_cb); + CRYPTO_set_dynlock_lock_callback(_openssl_dynlock_lock_cb); + CRYPTO_set_dynlock_destroy_callback(_openssl_dynlock_destroy_cb); return 0; } #else |