Project

General

Profile

Bug #13935 » ruby_2_3-0005-ossl.c-make-legacy-locking-callbacks-reentrant.patch

rhenium (Kazuki Yamaguchi), 09/24/2017 04:48 PM

View differences:

ext/openssl/ossl.c
#include "ruby/thread_native.h"
struct CRYPTO_dynlock_value {
rb_nativethread_lock_t lock;
rb_nativethread_id_t owner;
size_t count;
};
static void
ossl_lock_init(struct CRYPTO_dynlock_value *l)
{
rb_nativethread_lock_initialize(&l->lock);
l->count = 0;
}
static void
ossl_lock_unlock(int mode, struct CRYPTO_dynlock_value *l)
{
if (mode & CRYPTO_LOCK) {
/* TODO: rb_nativethread_id_t is not necessarily compared with ==. */
rb_nativethread_id_t tid = rb_nativethread_self();
if (l->count && l->owner == tid) {
l->count++;
return;
}
rb_nativethread_lock_lock(&l->lock);
l->owner = tid;
l->count = 1;
} else {
rb_nativethread_lock_unlock(&l->lock);
if (!--l->count)
rb_nativethread_lock_unlock(&l->lock);
}
}
(6-6/8)