diff --git a/ChangeLog b/ChangeLog index 2d73bdeb8a..981cfd38e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Jul 23 18:56:11 2013 Koichi Sasada + + * ext/openssl/ossl.c: use system native (system provided) + thread locking APIs added by last commit. + This patch fixes [Bug #8386]. + "rb_mutex_*" APIs control only "Ruby" threads. + Not for native threads. + Tue Jul 23 18:44:15 2013 Koichi Sasada * thread_native.h: added. diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c index f213f3c4cd..6032d916d8 100644 --- a/ext/openssl/ossl.c +++ b/ext/openssl/ossl.c @@ -461,14 +461,15 @@ ossl_fips_mode_set(VALUE self, VALUE enabled) /** * Stores locks needed for OpenSSL thread safety */ -static VALUE* ossl_locks; +#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) { if (mode & CRYPTO_LOCK) { - rb_mutex_lock(ossl_locks[type]); + rb_nativethread_lock_lock(&ossl_locks[type]); } else { - rb_mutex_unlock(ossl_locks[type]); + rb_nativethread_lock_unlock(&ossl_locks[type]); } } @@ -485,13 +486,12 @@ static void Init_ossl_locks(void) if ((unsigned)num_locks >= INT_MAX / (int)sizeof(VALUE)) { rb_raise(rb_eRuntimeError, "CRYPTO_num_locks() is too big: %d", num_locks); } - ossl_locks = (VALUE*) OPENSSL_malloc(num_locks * (int)sizeof(VALUE)); + ossl_locks = (rb_nativethread_lock_t *) OPENSSL_malloc(num_locks * sizeof(rb_nativethread_lock_t)); if (!ossl_locks) { rb_raise(rb_eNoMemError, "CRYPTO_num_locks() is too big: %d", num_locks); } for (i = 0; i < num_locks; i++) { - ossl_locks[i] = rb_mutex_new(); - rb_gc_register_mark_object(ossl_locks[i]); + rb_nativethread_lock_initialize(&ossl_locks[i]); } CRYPTO_set_id_callback(ossl_thread_id);