diff --git a/src/runtime2/component/control_layer.rs b/src/runtime2/component/control_layer.rs index da6a34d2932f0cdf9a8f072b5966d0fdc47481a3..ccce27eca977256b682599edd1db0dc6e7946604 100644 --- a/src/runtime2/component/control_layer.rs +++ b/src/runtime2/component/control_layer.rs @@ -10,7 +10,7 @@ pub(crate) struct ControlId(u32); impl ControlId { /// Like other invalid IDs, this one doesn't care any significance, but is /// just set at u32::MAX to hopefully bring out bugs sooner. - fn new_invalid() -> Self { + pub(crate) fn new_invalid() -> Self { return ControlId(u32::MAX); } } @@ -142,7 +142,7 @@ impl ControlLayer { } // ------------------------------------------------------------------------- - // Port transfer (due to component creation) + // Port transfer // ------------------------------------------------------------------------- /// Adds an entry that, when completely ack'd, will schedule a component. @@ -169,15 +169,8 @@ impl ControlLayer { return entry_id; } - /// Removes a schedule entry. Only used if the caller preemptively called - /// `add_schedule_entry`, but ended up not calling `add_reroute_entry`, - /// hence the `ack_countdown` in the scheduling entry is at 0. - pub(crate) fn remove_schedule_entry(&mut self, schedule_entry_id: ControlId) { - let index = self.get_entry_index_by_id(schedule_entry_id).unwrap(); - debug_assert_eq!(self.entries[index].ack_countdown, 0); - self.entries.remove(index); - } - + /// Adds a rerouting entry (used to ensure all messages will end up at a + /// newly created component). Used when creating a new component. pub(crate) fn add_reroute_entry( &mut self, creator_comp_id: CompId, source_port_id: PortId, source_comp_id: CompId, @@ -210,6 +203,24 @@ impl ControlLayer { }) } + /// Creates a PortPeerChanged message (and increments ack-counter on a + /// pre-created control entry) that is used as a preliminary step before + /// transferring a port over a channel. + pub(crate) fn create_port_transfer_message( + &mut self, associated_control_id: ControlId, + sender_comp_id: CompId, target_port_id: PortId + ) -> Message { + let entry_index = self.get_entry_index_by_id(associated_control_id).unwrap(); + self.entries[entry_index].ack_countdown += 1; + + return Message::Control(ControlMessage{ + id: associated_control_id, + sender_comp_id, + target_port_id: Some(target_port_id), + content: ControlMessageContent::PortPeerChangedBlock + }) + } + // ------------------------------------------------------------------------- // Blocking, unblocking, and closing ports // -------------------------------------------------------------------------