Switch to real mutex for init.
This commit is contained in:
parent
70483c1a0c
commit
4d7aa58680
23
ssl/mod.rs
23
ssl/mod.rs
|
|
@ -1,10 +1,9 @@
|
||||||
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::task;
|
use std::sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, Acquire, Release, SeqCst};
|
||||||
use std::sync::atomics::{AtomicBool, INIT_ATOMIC_BOOL, AtomicUint,
|
use std::unstable::finally::Finally;
|
||||||
INIT_ATOMIC_UINT, Acquire, Release, SeqCst};
|
use std::unstable::mutex::{Mutex, MUTEX_INIT};
|
||||||
use std::unstable::mutex::Mutex;
|
|
||||||
use std::io::{Stream, Reader, Writer, Decorator};
|
use std::io::{Stream, Reader, Writer, Decorator};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
|
|
@ -15,8 +14,8 @@ mod ffi;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
static mut STARTED_INIT: AtomicBool = INIT_ATOMIC_BOOL;
|
static mut INIT_LOCK: Mutex = MUTEX_INIT;
|
||||||
static mut FINISHED_INIT: AtomicBool = INIT_ATOMIC_BOOL;
|
static mut INITIALIZED: bool = false;
|
||||||
|
|
||||||
static mut VERIFY_IDX: AtomicUint = INIT_ATOMIC_UINT;
|
static mut VERIFY_IDX: AtomicUint = INIT_ATOMIC_UINT;
|
||||||
|
|
||||||
|
|
@ -25,10 +24,9 @@ static mut MUTEXES: AtomicUint = INIT_ATOMIC_UINT;
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
unsafe {
|
unsafe {
|
||||||
if STARTED_INIT.swap(true, Acquire) {
|
INIT_LOCK.lock();
|
||||||
while !FINISHED_INIT.load(Release) {
|
(|| {
|
||||||
task::deschedule();
|
if INITIALIZED {
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +42,10 @@ fn init() {
|
||||||
|
|
||||||
ffi::CRYPTO_set_locking_callback(locking_function);
|
ffi::CRYPTO_set_locking_callback(locking_function);
|
||||||
|
|
||||||
FINISHED_INIT.store(true, Release);
|
INITIALIZED = true;
|
||||||
|
}).finally(|| {
|
||||||
|
INIT_LOCK.unlock();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue