File tree Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Expand file tree Collapse file tree 1 file changed +5
-14
lines changed Original file line number Diff line number Diff line change @@ -138,17 +138,14 @@ cfg_if::cfg_if! {
138
138
139
139
#[ cfg( feature = "std" ) ]
140
140
mod lock {
141
- use std:: boxed:: Box ;
142
141
use std:: cell:: Cell ;
143
- use std:: ptr;
144
- use std:: sync:: { Mutex , MutexGuard , Once } ;
142
+ use std:: sync:: { Mutex , MutexGuard } ;
145
143
146
144
/// A "Maybe" LockGuard
147
145
pub struct LockGuard ( Option < MutexGuard < ' static , ( ) > > ) ;
148
146
149
- /// The global lock, lazily allocated on first use
150
- static mut LOCK : * mut Mutex < ( ) > = ptr:: null_mut ( ) ;
151
- static INIT : Once = Once :: new ( ) ;
147
+ /// The global lock
148
+ static LOCK : Mutex < ( ) > = Mutex :: new ( ( ) ) ;
152
149
// Whether this thread is the one that holds the lock
153
150
thread_local ! ( static LOCK_HELD : Cell <bool > = const { Cell :: new( false ) } ) ;
154
151
@@ -226,14 +223,8 @@ mod lock {
226
223
// Insist that we totally are the thread holding the lock
227
224
// (our thread will block until we are)
228
225
LOCK_HELD . with ( |s| s. set ( true ) ) ;
229
- unsafe {
230
- // lazily allocate the lock if necessary
231
- INIT . call_once ( || {
232
- LOCK = Box :: into_raw ( Box :: new ( Mutex :: new ( ( ) ) ) ) ;
233
- } ) ;
234
- // ok *actually* try to acquire the lock, blocking as necessary
235
- LockGuard ( Some ( ( * LOCK ) . lock ( ) . unwrap ( ) ) )
236
- }
226
+ // ok *actually* try to acquire the lock, blocking as necessary
227
+ LockGuard ( Some ( LOCK . lock ( ) . unwrap ( ) ) )
237
228
}
238
229
}
239
230
You can’t perform that action at this time.
0 commit comments