diff --git a/src/lib.rs b/src/lib.rs index 13ca6b58..8e188351 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -138,17 +138,14 @@ cfg_if::cfg_if! { #[cfg(feature = "std")] mod lock { - use std::boxed::Box; use std::cell::Cell; - use std::ptr; - use std::sync::{Mutex, MutexGuard, Once}; + use std::sync::{Mutex, MutexGuard}; /// A "Maybe" LockGuard pub struct LockGuard(Option>); - /// The global lock, lazily allocated on first use - static mut LOCK: *mut Mutex<()> = ptr::null_mut(); - static INIT: Once = Once::new(); + /// The global lock + static LOCK: Mutex<()> = Mutex::new(()); // Whether this thread is the one that holds the lock thread_local!(static LOCK_HELD: Cell = const { Cell::new(false) }); @@ -226,14 +223,8 @@ mod lock { // Insist that we totally are the thread holding the lock // (our thread will block until we are) LOCK_HELD.with(|s| s.set(true)); - unsafe { - // lazily allocate the lock if necessary - INIT.call_once(|| { - LOCK = Box::into_raw(Box::new(Mutex::new(()))); - }); - // ok *actually* try to acquire the lock, blocking as necessary - LockGuard(Some((*LOCK).lock().unwrap())) - } + // ok *actually* try to acquire the lock, blocking as necessary + LockGuard(Some(LOCK.lock().unwrap())) } }