#![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, H); // 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>; type R2H = RoleH>; // A enum Branching0fromHtoA { More( MeshedChannels< RS, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursAtoH>>, R2H>>>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoH = Recv; // B enum Branching0fromHtoB { More( MeshedChannels< SR, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursBtoH>>, R2H>>>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoH = Recv; // C enum Branching0fromHtoC { More( MeshedChannels< SR, SR, RS, RS, RS, RS, Recv<(), Send<(), RecursCtoH>>, R2H>>>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoH = Recv; // D enum Branching0fromHtoD { More( MeshedChannels< SR, SR, SR, RS, RS, RS, Recv<(), Send<(), RecursDtoH>>, R2H>>>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoH = Recv; // E enum Branching0fromHtoE { More( MeshedChannels< SR, SR, SR, SR, RS, RS, Recv<(), Send<(), RecursEtoH>>, R2H>>>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoH = Recv; // F enum Branching0fromHtoF { More( MeshedChannels< SR, SR, SR, SR, SR, RS, Recv<(), Send<(), RecursFtoH>>, R2H>>>>>>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoH = Recv; // G enum Branching0fromHtoG { More( MeshedChannels< SR, SR, SR, SR, SR, SR, Recv<(), Send<(), RecursGtoH>>, R2H>>>>>>>, NameG, >, ), Done(MeshedChannels), } type RecursGtoH = Recv; // H type Choose0fromHtoA = Send; type Choose0fromHtoB = Send; type Choose0fromHtoC = Send; type Choose0fromHtoD = Send; type Choose0fromHtoE = Send; type Choose0fromHtoF = Send; type Choose0fromHtoG = Send; type EndpointMoreH = MeshedChannels< Send<(), Recv<(), Choose0fromHtoA>>, Send<(), Recv<(), Choose0fromHtoB>>, Send<(), Recv<(), Choose0fromHtoC>>, Send<(), Recv<(), Choose0fromHtoD>>, Send<(), Recv<(), Choose0fromHtoE>>, Send<(), Recv<(), Choose0fromHtoF>>, Send<(), Recv<(), Choose0fromHtoG>>, R2A>>>>>>, NameH, >; // 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, NameG>; type EndpointH = MeshedChannels< Choose0fromHtoA, Choose0fromHtoB, Choose0fromHtoC, Choose0fromHtoD, Choose0fromHtoE, Choose0fromHtoF, Choose0fromHtoG, RoleBroadcast, NameH, >; #[inline] fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoA::Done(s) => { s.close() }, Branching0fromHtoA::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_a(s) }, }) } #[inline] fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoB::Done(s) => { s.close() }, Branching0fromHtoB::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, }) } #[inline] fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoC::Done(s) => { s.close() }, Branching0fromHtoC::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, }) } #[inline] fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoD::Done(s) => { s.close() }, Branching0fromHtoD::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, }) } #[inline] fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoE::Done(s) => { s.close() }, Branching0fromHtoE::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, }) } #[inline] fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoF::Done(s) => { s.close() }, Branching0fromHtoF::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()?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, }) } #[inline] fn endpoint_g(s: EndpointG) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoG::Done(s) => { s.close() }, Branching0fromHtoG::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()?; let s = s.send(())?; let (_, s) = s.recv()?; endpoint_g(s) }, }) } #[inline] fn endpoint_h(s: EndpointH) -> Result<(), Box> { let mut temp_s = s; for _ in 1..LOOPS { temp_s = recurs_h(temp_s)?; } let s = choose_mpst_h_to_all!( temp_s, Branching0fromHtoA::Done, Branching0fromHtoB::Done, Branching0fromHtoC::Done, Branching0fromHtoD::Done, Branching0fromHtoE::Done, Branching0fromHtoF::Done, Branching0fromHtoG::Done ); s.close() } fn recurs_h(s: EndpointH) -> Result> { let s: EndpointMoreH = choose_mpst_h_to_all!( s, Branching0fromHtoA::More, Branching0fromHtoB::More, Branching0fromHtoC::More, Branching0fromHtoD::More, Branching0fromHtoE::More, Branching0fromHtoF::More, Branching0fromHtoG::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()?; 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, thread_h) = fork_mpst( endpoint_a, endpoint_b, endpoint_c, endpoint_d, endpoint_e, endpoint_f, endpoint_g, endpoint_h, ); 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(); thread_h.join().unwrap(); }