use super::Condvar;
use std::sync::atomic::Ordering;
impl Condvar {
pub fn notify_one(&self) {
let thread = self.waiting_spin_threads.with_mut(|threads| threads.pop());
if let Some(thread) = thread {
eprintln!("Popped a waiting_spin_thread");
thread.store(true, Ordering::Release);
return;
}
let thread = self.waiting_sync_threads.with_mut(|threads| threads.pop());
if let Some(thread) = thread {
thread.unpark();
return;
}
let waiter = self.waiting_async_threads.with_mut(|waiters| waiters.pop());
if let Some(waiter) = waiter {
waiter.sender.send(());
}
}
pub fn notify_all(&self) {
let threads = self.waiting_spin_threads.with_mut(std::mem::take);
for thread in threads {
thread.store(true, Ordering::Release);
}
let threads = self.waiting_sync_threads.with_mut(std::mem::take);
for thread in threads {
thread.unpark();
}
let waiters = self.waiting_async_threads.with_mut(std::mem::take);
for waiter in waiters {
waiter.sender.send(());
}
}
}