use crate::rt;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering::SeqCst;
#[derive(Debug)]
pub struct Notify {
object: rt::Notify,
waiting: AtomicBool,
}
impl Notify {
pub fn new() -> Notify {
Notify {
object: rt::Notify::new(false, true),
waiting: AtomicBool::new(false),
}
}
pub fn notify(&self) {
self.object.notify();
}
pub fn wait(&self) {
let actual = self.waiting.compare_and_swap(false, true, SeqCst);
assert!(!actual, "only a single thread may wait on `Notify`");
self.object.wait();
self.waiting.store(false, SeqCst);
}
}