* 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.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2013-07-23 09:59:28 +00:00
Родитель db22d280e1
Коммит 55201cac9e
2 изменённых файлов: 14 добавлений и 6 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Tue Jul 23 18:56:11 2013 Koichi Sasada <ko1@atdot.net>
* 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 <ko1@atdot.net>
* thread_native.h: added.

Просмотреть файл

@ -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);