use core::{fmt, task::Waker};
mod cell;
pub(crate) mod queue;
pub(crate) use self::{cell::WaitCell, queue::WaitQueue};
#[cfg(feature = "std")]
use crate::loom::thread;
#[derive(Debug, Eq, PartialEq)]
pub(crate) enum WaitResult {
Wait,
Closed,
Notified,
}
pub(crate) trait Notify: fmt::Debug + Clone {
fn notify(self);
fn same(&self, other: &Self) -> bool;
}
#[cfg(feature = "std")]
impl Notify for thread::Thread {
#[inline]
fn notify(self) {
test_println!("NOTIFYING {:?} (from {:?})", self, thread::current());
self.unpark();
}
#[inline]
fn same(&self, other: &Self) -> bool {
other.id() == self.id()
}
}
impl Notify for Waker {
#[inline]
fn notify(self) {
test_println!("WAKING TASK {:?} (from {:?})", self, thread::current());
self.wake();
}
#[inline]
fn same(&self, other: &Self) -> bool {
other.will_wake(self)
}
}