diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index b6706e8be16729c1218fa97812bd3c1916225be2..e1f59e016d3faae5850be6fe58a89953f32971a2 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -6,6 +6,7 @@ use std::thread; use crate::ProtocolDescription; use crate::runtime2::global_store::ConnectorVariant; +use crate::runtime2::native::Connector; use super::RuntimeInner; use super::port::{PortIdLocal}; @@ -17,6 +18,10 @@ pub(crate) struct Scheduler { runtime: Arc, } +// Thinking aloud: actual ports should be accessible by connector, but managed +// by the scheduler (to handle rerouting messages). We could just give a read- +// only context, instead of an extra call on the "Connector" trait. + impl Scheduler { pub fn new(runtime: Arc) -> Self { return Self{ runtime }; @@ -52,18 +57,20 @@ impl Scheduler { while cur_schedule == ConnectorScheduling::Immediate { // Check all the message that are in the shared inbox while let Some(message) = scheduled.public.inbox.take_message() { + // TODO: Put header in front of messages, this is a mess match message { Message::Data(message) => { // Check if we need to reroute, or can just put it // in the private inbox of the connector - if let Some(other_connector_id) = scheduled.router.should_reroute(&message) { + if let Some(other_connector_id) = scheduled.router.should_reroute(message.sending_connector, message.sending_port) { self.send_message_and_wake_up_if_sleeping(other_connector_id, Message::Data(message)); } else { - scheduled.connector.inbox.insert_message(message); + scheduled.connector.insert_data_message(message); } }, Message::Sync(message) => { - scheduled.connector + // TODO: Come back here after rewriting port ownership stuff + if let Some(other_connector_id) = scheduled.router.should_reroute() }, Message::Solution(solution) => { @@ -282,10 +289,10 @@ impl Router { /// Returns true if the supplied message should be rerouted. If so then this /// function returns the connector that should retrieve this message. - pub fn should_reroute(&self, message: &DataMessage) -> Option { + pub fn should_reroute(&self, sending_connector: ConnectorId, sending_port: PortIdLocal) -> Option { for reroute in &self.active { - if reroute.source_connector == message.sending_connector && - reroute.port == message.sending_port { + if reroute.source_connector == sending_connector && + reroute.port == sending_port { // Need to reroute this message return Some(reroute.target_connector); }