clean unsafe op in unsafe fn

This commit is contained in:
袁浩----天命剑主 2024-07-16 11:34:23 +08:00 committed by GitHub
parent 060a40de63
commit 00fff8ac64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -76,16 +76,16 @@ impl Condvar {
#[inline] #[inline]
pub unsafe fn wait(&self, mutex: &Mutex) { pub unsafe fn wait(&self, mutex: &Mutex) {
let mutex = mutex::raw(mutex); let mutex = unsafe { mutex::raw(mutex) };
self.verify(mutex); self.verify(mutex);
let r = libc::pthread_cond_wait(raw(self), mutex); let r = unsafe { libc::pthread_cond_wait(raw(self), mutex) };
debug_assert_eq!(r, 0); debug_assert_eq!(r, 0);
} }
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool { pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
use crate::sys::time::Timespec; use crate::sys::time::Timespec;
let mutex = mutex::raw(mutex); let mutex = unsafe { mutex::raw(mutex) };
self.verify(mutex); self.verify(mutex);
let timeout = Timespec::now(libc::CLOCK_MONOTONIC) let timeout = Timespec::now(libc::CLOCK_MONOTONIC)
@ -93,7 +93,7 @@ impl Condvar {
.and_then(|t| t.to_timespec()) .and_then(|t| t.to_timespec())
.unwrap_or(TIMESPEC_MAX); .unwrap_or(TIMESPEC_MAX);
let r = pthread_cond_timedwait(raw(self), mutex, &timeout); let r = unsafe { pthread_cond_timedwait(raw(self), mutex, &timeout) };
assert!(r == libc::ETIMEDOUT || r == 0); assert!(r == libc::ETIMEDOUT || r == 0);
r == 0 r == 0
} }