@@ -281,9 +281,10 @@ where
281
281
282
282
#[ cfg( all( unix, feature = "std" , not( target_os = "emscripten" ) ) ) ]
283
283
mod fork {
284
- use core:: sync:: atomic:: { AtomicBool , AtomicUsize , Ordering } ;
284
+ use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
285
285
#[ allow( deprecated) ] // Required for compatibility with Rust < 1.24.
286
- use core:: sync:: atomic:: { ATOMIC_BOOL_INIT , ATOMIC_USIZE_INIT } ;
286
+ use core:: sync:: atomic:: { ATOMIC_USIZE_INIT } ;
287
+ use std:: sync:: Once ;
287
288
288
289
// Fork protection
289
290
//
@@ -304,20 +305,17 @@ mod fork {
304
305
RESEEDING_RNG_FORK_COUNTER . load ( Ordering :: Relaxed )
305
306
}
306
307
307
- #[ allow( deprecated) ]
308
- static FORK_HANDLER_REGISTERED : AtomicBool = ATOMIC_BOOL_INIT ;
309
-
310
308
extern "C" fn fork_handler ( ) {
311
309
// Note: fetch_add is defined to wrap on overflow
312
310
// (which is what we want).
313
311
RESEEDING_RNG_FORK_COUNTER . fetch_add ( 1 , Ordering :: Relaxed ) ;
314
312
}
315
313
316
314
pub fn register_fork_handler ( ) {
317
- if ! FORK_HANDLER_REGISTERED . load ( Ordering :: Relaxed ) {
318
- unsafe { libc :: pthread_atfork ( None , None , Some ( fork_handler ) ) } ;
319
- FORK_HANDLER_REGISTERED . store ( true , Ordering :: Relaxed ) ;
320
- }
315
+ static REGISTER : Once = Once :: new ( ) ;
316
+ REGISTER . call_once ( || unsafe {
317
+ libc :: pthread_atfork ( None , None , Some ( fork_handler ) ) ;
318
+ } ) ;
321
319
}
322
320
}
323
321
0 commit comments