diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-25 03:39:50 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-25 03:39:50 +0000 |
commit | dda113e3ff954064f718c73a114bb01361b5d205 (patch) | |
tree | 3ffca762dd6b009aa1905e8134ba85edc9fc40a7 /ext/openssl/ossl.c | |
parent | 03b6602417b5a689f0a446cf4905aed7e5475f47 (diff) | |
download | ruby-dda113e3ff954064f718c73a114bb01361b5d205.tar.gz |
* ext/openssl/ossl.c: support additional three thread synchronization
functions. [ruby-trunk - Bug #8386]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl.c')
-rw-r--r-- | ext/openssl/ossl.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c index 791d0f5edf..76fe3ea7fc 100644 --- a/ext/openssl/ossl.c +++ b/ext/openssl/ossl.c @@ -464,15 +464,47 @@ ossl_fips_mode_set(VALUE self, VALUE enabled) #include "../../thread_native.h" static rb_nativethread_lock_t *ossl_locks; -static void ossl_lock_callback(int mode, int type, const char *file, int line) +static void +ossl_lock_unlock(int mode, rb_nativethread_lock_t *lock) { if (mode & CRYPTO_LOCK) { - rb_nativethread_lock_lock(&ossl_locks[type]); + rb_nativethread_lock_lock(lock); } else { - rb_nativethread_lock_unlock(&ossl_locks[type]); + rb_nativethread_lock_unlock(lock); } } +static void +ossl_lock_callback(int mode, int type, const char *file, int line) +{ + ossl_lock_unlock(mode, &ossl_locks[type]); +} + +struct CRYPTO_dynlock_value { + rb_nativethread_lock_t lock; +}; + +static struct CRYPTO_dynlock_value * +ossl_dyn_create_callback(const char *file, int line) +{ + struct CRYPTO_dynlock_value *dynlock = (struct CRYPTO_dynlock_value *)OPENSSL_malloc((int)sizeof(struct CRYPTO_dynlock_value)); + rb_nativethread_lock_initialize(&dynlock->lock); + return dynlock; +} + +static void +ossl_dyn_lock_callback(int mode, struct CRYPTO_dynlock_value *l, const char *file, int line) +{ + ossl_lock_unlock(mode, &l->lock); +} + +static void +ossl_dyn_destroy_callback(struct CRYPTO_dynlock_value *l, const char *file, int line) +{ + rb_nativethread_lock_destroy(&l->lock); + OPENSSL_free(l); +} + #ifdef HAVE_CRYPTO_THREADID_PTR static void ossl_threadid_func(CRYPTO_THREADID *id) { @@ -509,6 +541,9 @@ static void Init_ossl_locks(void) CRYPTO_set_id_callback(ossl_thread_id); #endif CRYPTO_set_locking_callback(ossl_lock_callback); + CRYPTO_set_dynlock_create_callback(ossl_dyn_create_callback); + CRYPTO_set_dynlock_lock_callback(ossl_dyn_lock_callback); + CRYPTO_set_dynlock_destroy_callback(ossl_dyn_destroy_callback); } /* |