Skip to content

Commit f4a38c0

Browse files
mkroeningstlankes
authored andcommitted
hermit: Implement Condvar::wait_timeout
1 parent 61885df commit f4a38c0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

library/std/src/sys/hermit/condvar.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,18 @@ impl Condvar {
5555
mutex.lock();
5656
}
5757

58-
pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
59-
panic!("wait_timeout not supported on hermit");
58+
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
59+
if dur.is_zero() {
60+
return false;
61+
}
62+
63+
self.counter.fetch_add(1, SeqCst);
64+
mutex.unlock();
65+
let millis = dur.as_millis().min(u32::MAX as u128) as u32;
66+
let success = abi::sem_timedwait(self.sem1, millis) == 0;
67+
abi::sem_post(self.sem2);
68+
mutex.lock();
69+
success
6070
}
6171

6272
pub unsafe fn destroy(&self) {

0 commit comments

Comments
 (0)