use super::*;
#[doc(hidden)]
pub trait MachineImpl: 'static + Send + Sync {
type Adapter;
type SenderAdapter;
type InstructionSet: Send + Sync;
fn park_sender(
channel_id: usize, receiver_machine: Weak<self::tls::collective::MachineAdapter>,
sender: crossbeam::channel::Sender<Self::InstructionSet>, instruction: Self::InstructionSet,
) -> Result<(), Self::InstructionSet>;
}
pub trait Machine<T>: Send + Sync
where
T: 'static + Send + Sync,
{
fn receive(&self, cmd: T);
fn disconnected(&self) {}
fn connected(&self, _uuid: Uuid) {}
}
impl<T, P> Machine<P> for Mutex<T>
where
T: Machine<P>,
P: MachineImpl,
{
fn receive(&self, cmd: P) {
let mut lock = self.try_lock();
if let Ok(ref mut mutex) = lock {
(*mutex).receive(cmd);
} else {
log::error!("try_lock failed for receive");
}
}
fn disconnected(&self) {
let mut lock = self.try_lock();
if let Ok(ref mut mutex) = lock {
(*mutex).disconnected();
} else {
log::error!("try_lock failed for disconnected");
}
}
fn connected(&self, uuid: Uuid) {
let mut lock = self.try_lock();
if let Ok(ref mut mutex) = lock {
(*mutex).connected(uuid);
} else {
log::error!("try_lock failed for connected");
}
}
}