mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Rollup merge of #134389 - rust-wasi-web:condvar-no-threads, r=m-ou-se
Condvar: implement wait_timeout for targets without threads This always falls back to sleeping since there is no way to notify a condvar on a target without threads. Even on a target that has no threads the following code is a legitimate use case: ```rust use std::sync::{Condvar, Mutex}; use std::time::Duration; fn main() { let cv = Condvar::new(); let mutex = Mutex::new(()); let mut guard = mutex.lock().unwrap(); cv.notify_one(); let res; (guard, res) = cv.wait_timeout(guard, Duration::from_secs(3)).unwrap(); assert!(res.timed_out()); } ```
This commit is contained in:
commit
5ed1fa84a5
@ -1,4 +1,5 @@
|
|||||||
use crate::sys::sync::Mutex;
|
use crate::sys::sync::Mutex;
|
||||||
|
use crate::thread::sleep;
|
||||||
use crate::time::Duration;
|
use crate::time::Duration;
|
||||||
|
|
||||||
pub struct Condvar {}
|
pub struct Condvar {}
|
||||||
@ -19,7 +20,8 @@ impl Condvar {
|
|||||||
panic!("condvar wait not supported")
|
panic!("condvar wait not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
|
pub unsafe fn wait_timeout(&self, _mutex: &Mutex, dur: Duration) -> bool {
|
||||||
panic!("condvar wait not supported");
|
sleep(dur);
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user