Skip to content

Commit 42cab43

Browse files
committed
hermit: Implement Condvar::wait_timeout
1 parent 37f70a0 commit 42cab43

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,20 @@ 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+
self.counter.fetch_add(1, SeqCst);
60+
mutex.unlock();
61+
let millis = dur.as_millis().min(u32::MAX as u128) as u32;
62+
63+
let res = if millis > 0 {
64+
abi::sem_timedwait(self.sem1, millis)
65+
} else {
66+
abi::sem_trywait(self.sem1)
67+
};
68+
69+
abi::sem_post(self.sem2);
70+
mutex.lock();
71+
res == 0
6072
}
6173

6274
pub unsafe fn destroy(&self) {

0 commit comments

Comments
 (0)