use parking_lot::{Condvar, Mutex};
#[repr(align(8))]
pub struct Signal {
mutex: Mutex<bool>,
cvar: Condvar,
}
impl Signal {
pub fn new() -> Self {
Self {
mutex: Mutex::new(false),
cvar: Condvar::new(),
}
}
pub fn notify(&self) {
let mut lock = self.mutex.lock();
*lock = true;
self.cvar.notify_all();
}
pub fn wait(&self) {
let mut lock = self.mutex.lock();
if *lock {
*lock = false;
return;
}
self.cvar.wait(&mut lock);
}
}