@@ -287,7 +287,7 @@ pub struct Init {
287
287
/// synchronization. Also note that it is safe to call this function multiple
288
288
/// times recursively.
289
289
pub fn init ( ) -> Result < Init , ( ) > {
290
- use core:: sync:: atomic:: { AtomicUsize , Ordering :: SeqCst } ;
290
+ use core:: sync:: atomic:: { AtomicPtr , Ordering :: SeqCst } ;
291
291
292
292
// Helper function for generating a name that's unique to the process.
293
293
fn mutex_name ( ) -> [ u8 ; 33 ] {
@@ -341,22 +341,21 @@ pub fn init() -> Result<Init, ()> {
341
341
//
342
342
// After we've actually go the lock we simply acquire it, and our `Init`
343
343
// handle we hand out will be responsible for dropping it eventually.
344
- static LOCK : AtomicUsize = AtomicUsize :: new ( 0 ) ;
344
+ static LOCK : AtomicPtr < c_void > = AtomicPtr :: new ( ptr :: null_mut ( ) ) ;
345
345
let mut lock = LOCK . load ( SeqCst ) ;
346
- if lock == 0 {
346
+ if lock. is_null ( ) {
347
347
let name = mutex_name ( ) ;
348
- lock = CreateMutexA ( ptr:: null_mut ( ) , 0 , name. as_ptr ( ) . cast :: < i8 > ( ) ) as usize ;
349
- if lock == 0 {
348
+ lock = CreateMutexA ( ptr:: null_mut ( ) , 0 , name. as_ptr ( ) . cast :: < i8 > ( ) ) ;
349
+ if lock. is_null ( ) {
350
350
return Err ( ( ) ) ;
351
351
}
352
- if let Err ( other) = LOCK . compare_exchange ( 0 , lock, SeqCst , SeqCst ) {
353
- debug_assert ! ( other != 0 ) ;
354
- CloseHandle ( lock as HANDLE ) ;
352
+ if let Err ( other) = LOCK . compare_exchange ( ptr :: null_mut ( ) , lock, SeqCst , SeqCst ) {
353
+ debug_assert ! ( !other . is_null ( ) ) ;
354
+ CloseHandle ( lock) ;
355
355
lock = other;
356
356
}
357
357
}
358
- debug_assert ! ( lock != 0 ) ;
359
- let lock = lock as HANDLE ;
358
+ debug_assert ! ( !lock. is_null( ) ) ;
360
359
let r = WaitForSingleObjectEx ( lock, INFINITE , FALSE ) ;
361
360
debug_assert_eq ! ( r, 0 ) ;
362
361
let ret = Init { lock } ;
0 commit comments