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),
}
}
#[track_caller]
pub fn notify(&self) {
self.object.notify(location!());
}
#[track_caller]
pub fn wait(&self) {
self.waiting
.compare_exchange(false, true, SeqCst, SeqCst)
.expect("only a single thread may wait on `Notify`");
self.object.wait(location!());
self.waiting.store(false, SeqCst);
}
}
impl Default for Notify {
fn default() -> Self {
Self::new()
}
}