#![allow( clippy::type_complexity, clippy::too_many_arguments, clippy::large_enum_variant )] use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send}; use mpstthree::generate; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use std::error::Error; static LOOPS: i64 = 100; // Create new roles generate!("rec_and_cancel", MeshedChannels, A, B, C, D, E, F, G); // Types // Send/Recv type RS = Recv<(), Send<(), End>>; type SR = Send<(), Recv<(), End>>; // Roles type R2A = RoleA>; type R2B = RoleB>; type R2C = RoleC>; type R2D = RoleD>; type R2E = RoleE>; type R2F = RoleF>; type R2G = RoleG>; // A enum Branching0fromGtoA { More( MeshedChannels< RS, RS, RS, RS, RS, Recv<(), Send<(), RecursAtoG>>, R2G>>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoG = Recv; // B enum Branching0fromGtoB { More( MeshedChannels< SR, RS, RS, RS, RS, Recv<(), Send<(), RecursBtoG>>, R2G>>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoG = Recv; // C enum Branching0fromGtoC { More( MeshedChannels< SR, SR, RS, RS, RS, Recv<(), Send<(), RecursCtoG>>, R2G>>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoG = Recv; // D enum Branching0fromGtoD { More( MeshedChannels< SR, SR, SR, RS, RS, Recv<(), Send<(), RecursDtoG>>, R2G>>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoG = Recv; // E enum Branching0fromGtoE { More( MeshedChannels< SR, SR, SR, SR, RS, Recv<(), Send<(), RecursEtoG>>, R2G>>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoG = Recv; // F enum Branching0fromGtoF { More( MeshedChannels< SR, SR, SR, SR, SR, Recv<(), Send<(), RecursFtoG>>, R2G>>>>>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoG = Recv; // F type Choose0fromGtoA = Send; type Choose0fromGtoB = Send; type Choose0fromGtoC = Send; type Choose0fromGtoD = Send; type Choose0fromGtoE = Send; type Choose0fromGtoF = Send; type EndpointMoreG = MeshedChannels< Send<(), Recv<(), Choose0fromGtoA>>, Send<(), Recv<(), Choose0fromGtoB>>, Send<(), Recv<(), Choose0fromGtoC>>, Send<(), Recv<(), Choose0fromGtoD>>, Send<(), Recv<(), Choose0fromGtoE>>, Send<(), Recv<(), Choose0fromGtoF>>, R2A>>>>>, NameG, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels, NameC>; type EndpointD = MeshedChannels, NameD>; type EndpointE = MeshedChannels, NameE>; type EndpointF = MeshedChannels, NameF>; type EndpointG = MeshedChannels< Choose0fromGtoA, Choose0fromGtoB, Choose0fromGtoC, Choose0fromGtoD, Choose0fromGtoE, Choose0fromGtoF, RoleBroadcast, NameG, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoA::Done(s) => { s.close() }, Branching0fromGtoA::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_a(s) }, }) } #[inline] fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoB::Done(s) => { s.close() }, Branching0fromGtoB::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, }) } #[inline] fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoC::Done(s) => { s.close() }, Branching0fromGtoC::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, }) } #[inline] fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoD::Done(s) => { s.close() }, Branching0fromGtoD::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, }) } #[inline] fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoE::Done(s) => { s.close() }, Branching0fromGtoE::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, }) } #[inline] fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoF::Done(s) => { s.close() }, Branching0fromGtoF::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; endpoint_f(s) }, }) } #[inline] fn endpoint_g(s: EndpointG) -> Result<(), Box> { let mut temp_s = s; for _ in 1..LOOPS { temp_s = recurs_g(temp_s)?; } let s = choose_mpst_g_to_all!( temp_s, Branching0fromGtoA::Done, Branching0fromGtoB::Done, Branching0fromGtoC::Done, Branching0fromGtoD::Done, Branching0fromGtoE::Done, Branching0fromGtoF::Done ); s.close() } fn recurs_g(s: EndpointG) -> Result> { let s: EndpointMoreG = choose_mpst_g_to_all!( s, Branching0fromGtoA::More, Branching0fromGtoB::More, Branching0fromGtoC::More, Branching0fromGtoD::More, Branching0fromGtoE::More, Branching0fromGtoF::More ); let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; Ok(s) } fn main() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g) = fork_mpst( endpoint_a, endpoint_b, endpoint_c, endpoint_d, endpoint_e, endpoint_f, endpoint_g, ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); thread_g.join().unwrap(); }