Release pthread cond workaround, simplify
This commit is contained in:
+5
-36
@@ -90,32 +90,14 @@ impl Cond {
|
||||
_ => return Err(Errno(EINVAL)),
|
||||
};
|
||||
|
||||
match self.wait_inner(mutex, Some(&relative)) {
|
||||
Err(Errno(ETIMEDOUT)) => {
|
||||
// TODO: this is a workaround that SYS_FUTEX returns ETIMEDOUT but actually it signaled in time
|
||||
let mut monotonic = timespec::default();
|
||||
unsafe { clock_gettime(CLOCK_MONOTONIC, &mut monotonic) };
|
||||
|
||||
if timespec::subtract(relative, monotonic).is_some() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Errno(ETIMEDOUT))
|
||||
}
|
||||
}
|
||||
r => r,
|
||||
}
|
||||
self.wait_inner(mutex, Some(&relative))
|
||||
}
|
||||
pub fn timedwait(&self, mutex: &RlctMutex, timeout: ×pec) -> Result<(), Errno> {
|
||||
// TODO: The clock can be other than CLOCK_REALTIME depends on CondAttr
|
||||
self.clockwait(mutex, timeout, CLOCK_REALTIME)
|
||||
}
|
||||
fn wait_inner(&self, mutex: &RlctMutex, timeout: Option<×pec>) -> Result<(), Errno> {
|
||||
self.wait_inner_generic(
|
||||
|| mutex.unlock(),
|
||||
|| mutex.lock(),
|
||||
|timeout| mutex.lock_with_timeout(timeout),
|
||||
timeout,
|
||||
)
|
||||
self.wait_inner_generic(|| mutex.unlock(), || mutex.lock(), timeout)
|
||||
}
|
||||
pub fn wait_inner_typedmutex<'lock, T>(
|
||||
&self,
|
||||
@@ -132,7 +114,6 @@ impl Cond {
|
||||
newguard = Some(lock.lock());
|
||||
Ok(())
|
||||
},
|
||||
|_| unreachable!(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -143,7 +124,6 @@ impl Cond {
|
||||
&self,
|
||||
unlock: impl FnOnce() -> Result<()>,
|
||||
lock: impl FnOnce() -> Result<()>,
|
||||
lock_with_timeout: impl FnOnce(×pec) -> Result<()>,
|
||||
deadline: Option<×pec>,
|
||||
) -> Result<(), Errno> {
|
||||
// TODO: Error checking for certain types (i.e. robust and errorcheck) of mutexes, e.g. if the
|
||||
@@ -151,20 +131,9 @@ impl Cond {
|
||||
let current = self.cur.load(Ordering::Relaxed);
|
||||
self.prev.store(current, Ordering::Relaxed);
|
||||
|
||||
unlock();
|
||||
|
||||
let futex_r = match deadline {
|
||||
Some(deadline) => {
|
||||
let r = crate::sync::futex_wait(&self.cur, current, Some(&deadline));
|
||||
lock_with_timeout(deadline)?;
|
||||
r
|
||||
}
|
||||
None => {
|
||||
let r = crate::sync::futex_wait(&self.cur, current, None);
|
||||
lock()?;
|
||||
r
|
||||
}
|
||||
};
|
||||
unlock()?;
|
||||
let futex_r = crate::sync::futex_wait(&self.cur, current, deadline);
|
||||
lock()?;
|
||||
|
||||
match futex_r {
|
||||
super::FutexWaitResult::Waited => Ok(()),
|
||||
|
||||
Reference in New Issue
Block a user