Skip to content

Commit

Permalink
Cleanup std::sys::cloudabi
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Jul 23, 2019
1 parent 82dd54b commit 0ac6afa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/libstd/sys/cloudabi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
32 changes: 16 additions & 16 deletions src/libstd/sys/cloudabi/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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,
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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");
}
}
4 changes: 2 additions & 2 deletions src/libstd/sys/cloudabi/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}

Expand Down Expand Up @@ -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() }
}
}

Expand Down

0 comments on commit 0ac6afa

Please sign in to comment.