aboutsummaryrefslogtreecommitdiff
path: root/src/ffi.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2014-10-13 23:19:14 -0700
committerSteven Fackler <[email protected]>2014-10-13 23:19:14 -0700
commit60dce4c2190ecb935044152c02f4362d76a381e2 (patch)
tree9be063d21a6ca4c90f20be1dd54d0dc3144b959f /src/ffi.rs
parentMerge pull request #83 from jmesmon/set-cipher-list (diff)
parentCorrect init mutexes and locking function (diff)
downloadrust-openssl-60dce4c2190ecb935044152c02f4362d76a381e2.tar.xz
rust-openssl-60dce4c2190ecb935044152c02f4362d76a381e2.zip
Merge pull request #81 from vhbit/lock-init
Correct init mutexes and locking function
Diffstat (limited to 'src/ffi.rs')
-rwxr-xr-xsrc/ffi.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ffi.rs b/src/ffi.rs
index 4dc7b0cc..8b2cd467 100755
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -1,7 +1,9 @@
#![allow(non_camel_case_types, non_uppercase_statics, non_snake_case)]
#![allow(dead_code)]
use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t};
+use std::mem;
use std::ptr;
+use std::rt::mutex::NativeMutex;
use sync::one::{Once, ONCE_INIT};
pub use bn::BIGNUM;
@@ -182,13 +184,34 @@ extern {}
#[link(name="wsock32")]
extern { }
+static mut MUTEXES: *mut Vec<NativeMutex> = 0 as *mut Vec<NativeMutex>;
+
+extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char,
+ _line: c_int) {
+ unsafe {
+ let mutex = (*MUTEXES).get_mut(n as uint);
+
+ if mode & CRYPTO_LOCK != 0 {
+ mutex.lock_noguard();
+ } else {
+ mutex.unlock_noguard();
+ }
+ }
+}
+
pub fn init() {
static mut INIT: Once = ONCE_INIT;
unsafe {
INIT.doit(|| {
SSL_library_init();
- SSL_load_error_strings()
+ SSL_load_error_strings();
+
+ let num_locks = CRYPTO_num_locks();
+ let mutexes = box Vec::from_fn(num_locks as uint, |_| NativeMutex::new());
+ MUTEXES = mem::transmute(mutexes);
+
+ CRYPTO_set_locking_callback(locking_function);
})
}
}