Skip to content

Commit 0ac6afa

Browse files
committed
Cleanup std::sys::cloudabi
1 parent 82dd54b commit 0ac6afa

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/libstd/sys/cloudabi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
6464
let mut v: mem::MaybeUninit<(u64, u64)> = mem::MaybeUninit::uninit();
6565
libc::arc4random_buf(
6666
v.as_mut_ptr() as *mut libc::c_void,
67-
mem::size_of_val(v.get_ref())
67+
mem::size_of_val(&v)
6868
);
6969
v.assume_init()
7070
}

src/libstd/sys/cloudabi/mutex.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct ReentrantMutex {
5454

5555
impl ReentrantMutex {
5656
pub unsafe fn uninitialized() -> ReentrantMutex {
57-
ReentrantMutex {
57+
ReentrantMutex {
5858
lock: UnsafeCell::new(MaybeUninit::uninit()),
5959
recursion: UnsafeCell::new(MaybeUninit::uninit())
6060
}
@@ -67,9 +67,9 @@ impl ReentrantMutex {
6767

6868
pub unsafe fn try_lock(&self) -> bool {
6969
// Attempt to acquire the lock.
70-
let lock = self.lock.get();
71-
let recursion = self.recursion.get();
72-
if let Err(old) = (*(*lock).as_mut_ptr()).compare_exchange(
70+
let lock = (*self.lock.get()).as_mut_ptr();
71+
let recursion = (*self.recursion.get()).as_mut_ptr();
72+
if let Err(old) = (*lock).compare_exchange(
7373
abi::LOCK_UNLOCKED.0,
7474
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
7575
Ordering::Acquire,
@@ -78,14 +78,14 @@ impl ReentrantMutex {
7878
// If we fail to acquire the lock, it may be the case
7979
// that we've already acquired it and may need to recurse.
8080
if old & !abi::LOCK_KERNEL_MANAGED.0 == __pthread_thread_id.0 | abi::LOCK_WRLOCKED.0 {
81-
*(*recursion).as_mut_ptr() += 1;
81+
*recursion += 1;
8282
true
8383
} else {
8484
false
8585
}
8686
} else {
8787
// Success.
88-
assert_eq!(*(*recursion).as_mut_ptr(), 0, "Mutex has invalid recursion count");
88+
assert_eq!(*recursion, 0, "Mutex has invalid recursion count");
8989
true
9090
}
9191
}
@@ -113,17 +113,17 @@ impl ReentrantMutex {
113113
}
114114

115115
pub unsafe fn unlock(&self) {
116-
let lock = self.lock.get();
117-
let recursion = self.recursion.get();
116+
let lock = (*self.lock.get()).as_mut_ptr();
117+
let recursion = (*self.recursion.get()).as_mut_ptr();
118118
assert_eq!(
119-
(*(*lock).as_mut_ptr()).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
119+
(*lock).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
120120
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
121121
"This mutex is locked by a different thread"
122122
);
123123

124-
if *(*recursion).as_mut_ptr() > 0 {
125-
*(*recursion).as_mut_ptr() -= 1;
126-
} else if !(*(*lock).as_mut_ptr())
124+
if *recursion > 0 {
125+
*recursion -= 1;
126+
} else if !(*lock)
127127
.compare_exchange(
128128
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
129129
abi::LOCK_UNLOCKED.0,
@@ -140,13 +140,13 @@ impl ReentrantMutex {
140140
}
141141

142142
pub unsafe fn destroy(&self) {
143-
let lock = self.lock.get();
144-
let recursion = self.recursion.get();
143+
let lock = (*self.lock.get()).as_mut_ptr();
144+
let recursion = (*self.recursion.get()).as_mut_ptr();
145145
assert_eq!(
146-
(*(*lock).as_mut_ptr()).load(Ordering::Relaxed),
146+
(*lock).load(Ordering::Relaxed),
147147
abi::LOCK_UNLOCKED.0,
148148
"Attempted to destroy locked mutex"
149149
);
150-
assert_eq!(*(*recursion).as_mut_ptr(), 0, "Recursion counter invalid");
150+
assert_eq!(*recursion, 0, "Recursion counter invalid");
151151
}
152152
}

src/libstd/sys/cloudabi/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Instant {
2121
let mut t: mem::MaybeUninit<abi::timestamp> = mem::MaybeUninit::uninit();
2222
let ret = abi::clock_time_get(abi::clockid::MONOTONIC, 0, t.get_mut());
2323
assert_eq!(ret, abi::errno::SUCCESS);
24-
Instant { t }
24+
Instant { t: t.assume_init() }
2525
}
2626
}
2727

@@ -62,7 +62,7 @@ impl SystemTime {
6262
let mut t: mem::MaybeUninit<abi::timestamp> = mem::MaybeUninit::uninit();
6363
let ret = abi::clock_time_get(abi::clockid::REALTIME, 0, t.get_mut());
6464
assert_eq!(ret, abi::errno::SUCCESS);
65-
SystemTime { t }
65+
SystemTime { t: t.assume_init() }
6666
}
6767
}
6868

0 commit comments

Comments
 (0)