ruby-changes:30107
From: ko1 <ko1@a...>
Date: Thu, 25 Jul 2013 12:40:01 +0900 (JST)
Subject: [ruby-changes:30107] ko1:r42159 (trunk): * ext/openssl/ossl.c: support additional three thread synchronization
ko1 2013-07-25 12:39:50 +0900 (Thu, 25 Jul 2013) New Revision: 42159 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42159 Log: * ext/openssl/ossl.c: support additional three thread synchronization functions. [ruby-trunk - Bug #8386] Modified files: trunk/ChangeLog trunk/ext/openssl/ossl.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42158) +++ ChangeLog (revision 42159) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jul 25 12:32:11 2013 Koichi Sasada <ko1@a...> + + * ext/openssl/ossl.c: support additional three thread synchronization + functions. [ruby-trunk - Bug #8386] + Thu Jul 25 07:15:58 2013 Eric Hodel <drbrain@s...> * lib/rubygems: Import RubyGems from master as of commit 4ff70cc Index: ext/openssl/ossl.c =================================================================== --- ext/openssl/ossl.c (revision 42158) +++ ext/openssl/ossl.c (revision 42159) @@ -464,15 +464,47 @@ ossl_fips_mode_set(VALUE self, VALUE ena https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L464 #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) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L541 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); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/