From b063aadaa5854e845ed01a1d4c1bf730ec67c79b Mon Sep 17 00:00:00 2001 From: Wildan M Date: Tue, 6 Jan 2026 23:32:15 +0700 Subject: [PATCH] Release pthread cond workaround, simplify --- src/sync/cond.rs | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/src/sync/cond.rs b/src/sync/cond.rs index 58b16c3eb4..321afa4ea6 100644 --- a/src/sync/cond.rs +++ b/src/sync/cond.rs @@ -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(()),