Use Once instead of hacky mutex thing.
This commit is contained in:
parent
be3c164f8f
commit
dfa9a7e028
19
ssl/mod.rs
19
ssl/mod.rs
|
|
@ -1,8 +1,7 @@
|
||||||
use std::cast;
|
use std::cast;
|
||||||
use std::libc::{c_int, c_void, c_char};
|
use std::libc::{c_int, c_void, c_char};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::unstable::finally::Finally;
|
use std::unstable::mutex::{Mutex, Once, ONCE_INIT};
|
||||||
use std::unstable::mutex::{Mutex, MUTEX_INIT};
|
|
||||||
use std::io::{Stream, Reader, Writer};
|
use std::io::{Stream, Reader, Writer};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
|
|
@ -13,20 +12,14 @@ mod ffi;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
static mut INIT_LOCK: Mutex = MUTEX_INIT;
|
static mut INIT: Once = ONCE_INIT;
|
||||||
static mut INITIALIZED: bool = false;
|
|
||||||
|
|
||||||
static mut VERIFY_IDX: c_int = -1;
|
static mut VERIFY_IDX: c_int = -1;
|
||||||
static mut MUTEXES: Option<*mut ~[Mutex]> = None;
|
static mut MUTEXES: Option<*mut ~[Mutex]> = None;
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
unsafe {
|
unsafe {
|
||||||
INIT_LOCK.lock();
|
INIT.doit(|| {
|
||||||
(|| {
|
|
||||||
if INITIALIZED {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ffi::SSL_library_init();
|
ffi::SSL_library_init();
|
||||||
let verify_idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
let verify_idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
||||||
None, None);
|
None, None);
|
||||||
|
|
@ -38,11 +31,7 @@ fn init() {
|
||||||
MUTEXES = Some(cast::transmute(mutexes));
|
MUTEXES = Some(cast::transmute(mutexes));
|
||||||
|
|
||||||
ffi::CRYPTO_set_locking_callback(locking_function);
|
ffi::CRYPTO_set_locking_callback(locking_function);
|
||||||
|
});
|
||||||
INITIALIZED = true;
|
|
||||||
}).finally(|| {
|
|
||||||
INIT_LOCK.unlock();
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue