mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #90401 - mkroening:hermit-condvar, r=joshtriplett
hermit: Implement Condvar::wait_timeout This implements `Condvar::wait_timeout` for the `hermit` target. See * https://github.com/hermitcore/rust/pull/2 * https://github.com/hermitcore/rust/pull/5 CC: `@stlankes`
This commit is contained in:
commit
0da75bcc9c
@ -55,8 +55,20 @@ impl Condvar {
|
|||||||
mutex.lock();
|
mutex.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
|
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
|
||||||
panic!("wait_timeout not supported on hermit");
|
self.counter.fetch_add(1, SeqCst);
|
||||||
|
mutex.unlock();
|
||||||
|
let millis = dur.as_millis().min(u32::MAX as u128) as u32;
|
||||||
|
|
||||||
|
let res = if millis > 0 {
|
||||||
|
abi::sem_timedwait(self.sem1, millis)
|
||||||
|
} else {
|
||||||
|
abi::sem_trywait(self.sem1)
|
||||||
|
};
|
||||||
|
|
||||||
|
abi::sem_post(self.sem2);
|
||||||
|
mutex.lock();
|
||||||
|
res == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn destroy(&self) {
|
pub unsafe fn destroy(&self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user