Skip to content

Commit

Permalink
hermit: Implement Condvar::wait_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening authored and stlankes committed Aug 13, 2021
1 parent 61885df commit f4a38c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions library/std/src/sys/hermit/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ impl Condvar {
mutex.lock();
}

pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
panic!("wait_timeout not supported on hermit");
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
if dur.is_zero() {
return false;
}

self.counter.fetch_add(1, SeqCst);
mutex.unlock();
let millis = dur.as_millis().min(u32::MAX as u128) as u32;
let success = abi::sem_timedwait(self.sem1, millis) == 0;
abi::sem_post(self.sem2);
mutex.lock();
success
}

pub unsafe fn destroy(&self) {
Expand Down

0 comments on commit f4a38c0

Please sign in to comment.