Cleanup std::sys::cloudabi

This commit is contained in:
Nathan 2019-07-23 10:20:33 -04:00
parent 82dd54baf3
commit 0ac6afafa6
3 changed files with 19 additions and 19 deletions

View File

@ -64,7 +64,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
let mut v: mem::MaybeUninit<(u64, u64)> = mem::MaybeUninit::uninit();
libc::arc4random_buf(
v.as_mut_ptr() as *mut libc::c_void,
mem::size_of_val(v.get_ref())
mem::size_of_val(&v)
);
v.assume_init()
}

View File

@ -54,7 +54,7 @@ pub struct ReentrantMutex {
impl ReentrantMutex {
pub unsafe fn uninitialized() -> ReentrantMutex {
ReentrantMutex {
ReentrantMutex {
lock: UnsafeCell::new(MaybeUninit::uninit()),
recursion: UnsafeCell::new(MaybeUninit::uninit())
}
@ -67,9 +67,9 @@ impl ReentrantMutex {
pub unsafe fn try_lock(&self) -> bool {
// Attempt to acquire the lock.
let lock = self.lock.get();
let recursion = self.recursion.get();
if let Err(old) = (*(*lock).as_mut_ptr()).compare_exchange(
let lock = (*self.lock.get()).as_mut_ptr();
let recursion = (*self.recursion.get()).as_mut_ptr();
if let Err(old) = (*lock).compare_exchange(
abi::LOCK_UNLOCKED.0,
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
Ordering::Acquire,
@ -78,14 +78,14 @@ impl ReentrantMutex {
// If we fail to acquire the lock, it may be the case
// that we've already acquired it and may need to recurse.
if old & !abi::LOCK_KERNEL_MANAGED.0 == __pthread_thread_id.0 | abi::LOCK_WRLOCKED.0 {
*(*recursion).as_mut_ptr() += 1;
*recursion += 1;
true
} else {
false
}
} else {
// Success.
assert_eq!(*(*recursion).as_mut_ptr(), 0, "Mutex has invalid recursion count");
assert_eq!(*recursion, 0, "Mutex has invalid recursion count");
true
}
}
@ -113,17 +113,17 @@ impl ReentrantMutex {
}
pub unsafe fn unlock(&self) {
let lock = self.lock.get();
let recursion = self.recursion.get();
let lock = (*self.lock.get()).as_mut_ptr();
let recursion = (*self.recursion.get()).as_mut_ptr();
assert_eq!(
(*(*lock).as_mut_ptr()).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
(*lock).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
"This mutex is locked by a different thread"
);
if *(*recursion).as_mut_ptr() > 0 {
*(*recursion).as_mut_ptr() -= 1;
} else if !(*(*lock).as_mut_ptr())
if *recursion > 0 {
*recursion -= 1;
} else if !(*lock)
.compare_exchange(
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
abi::LOCK_UNLOCKED.0,
@ -140,13 +140,13 @@ impl ReentrantMutex {
}
pub unsafe fn destroy(&self) {
let lock = self.lock.get();
let recursion = self.recursion.get();
let lock = (*self.lock.get()).as_mut_ptr();
let recursion = (*self.recursion.get()).as_mut_ptr();
assert_eq!(
(*(*lock).as_mut_ptr()).load(Ordering::Relaxed),
(*lock).load(Ordering::Relaxed),
abi::LOCK_UNLOCKED.0,
"Attempted to destroy locked mutex"
);
assert_eq!(*(*recursion).as_mut_ptr(), 0, "Recursion counter invalid");
assert_eq!(*recursion, 0, "Recursion counter invalid");
}
}

View File

@ -21,7 +21,7 @@ impl Instant {
let mut t: mem::MaybeUninit<abi::timestamp> = mem::MaybeUninit::uninit();
let ret = abi::clock_time_get(abi::clockid::MONOTONIC, 0, t.get_mut());
assert_eq!(ret, abi::errno::SUCCESS);
Instant { t }
Instant { t: t.assume_init() }
}
}
@ -62,7 +62,7 @@ impl SystemTime {
let mut t: mem::MaybeUninit<abi::timestamp> = mem::MaybeUninit::uninit();
let ret = abi::clock_time_get(abi::clockid::REALTIME, 0, t.get_mut());
assert_eq!(ret, abi::errno::SUCCESS);
SystemTime { t }
SystemTime { t: t.assume_init() }
}
}