diff --git a/src/runtime2/mod.rs b/src/runtime2/mod.rs index 5238d2ca54a24635e0ad21cfc077131084f531f1..fd5a8c1f4a1ae39e5134f103a1bcb423e059a189 100644 --- a/src/runtime2/mod.rs +++ b/src/runtime2/mod.rs @@ -24,6 +24,7 @@ use inbox::Message; use connector::{ConnectorPDL, ConnectorPublic, ConnectorScheduling, RunDeltaState}; use scheduler::{Scheduler, ConnectorCtx, Router}; use native::{Connector, ConnectorApplication, ApplicationInterface}; +use crate::runtime2::port::Port; /// A kind of token that, once obtained, allows mutable access to a connector. /// We're trying to use move semantics as much as possible: the owner of this @@ -213,6 +214,33 @@ impl RuntimeInner { self.scheduler_notifier.notify_one(); } + // --- Creating ports + + /// Creates a new port pair. Note that these are stored globally like the + /// connectors are. Ports stored by components belong to those components. + pub(crate) fn create_channel(&self) -> (Port, Port) { + use port::{PortIdLocal, PortKind}; + + let getter_id = self.port_counter.fetch_add(2, Ordering::SeqCst); + let putter_id = PortIdLocal::new(getter_id + 1); + let getter_id = PortIdLocal::new(getter_id); + + let getter_port = Port{ + self_id: getter_id, + peer_id: putter_id, + kind: PortKind::Getter, + peer_connector: self.connector_id, + }; + let putter_port = Port{ + self_id: putter_id, + peer_id: getter_id, + kind: PortKind::Putter, + peer_connector: self.connector_id, + }; + + return (getter_port, putter_port); + } + // --- Creating/retrieving/destroying components pub(crate) fn create_interface_component(&self, component: ConnectorApplication) -> ConnectorKey { @@ -276,11 +304,13 @@ impl RuntimeInner { #[inline] pub(crate) fn increment_active_interfaces(&self) { let _old_num = self.active_interfaces.fetch_add(1, Ordering::SeqCst); + println!("DEBUG: Incremented active interfaces to {}", _old_num + 1); debug_assert_ne!(_old_num, 0); // once it hits 0, it stays zero } pub(crate) fn decrement_active_interfaces(&self) { let old_num = self.active_interfaces.fetch_sub(1, Ordering::SeqCst); + println!("DEBUG: Decremented active interfaces to {}", old_num - 1); debug_assert!(old_num > 0); if old_num == 1 { // such that active interfaces is now 0 let num_connectors = self.active_connectors.load(Ordering::Acquire); @@ -292,11 +322,13 @@ impl RuntimeInner { #[inline] fn increment_active_components(&self) { - self.active_connectors.fetch_add(1, Ordering::SeqCst); + let _old_num = self.active_connectors.fetch_add(1, Ordering::SeqCst); + println!("DEBUG: Incremented components to {}", _old_num + 1); } fn decrement_active_components(&self) { let old_num = self.active_connectors.fetch_sub(1, Ordering::SeqCst); + println!("DEBUG: Decremented components to {}", old_num - 1); debug_assert!(old_num > 0); if old_num == 0 { // such that we have no more active connectors (for now!) let num_interfaces = self.active_interfaces.load(Ordering::Acquire);