diff --git a/src/runtime2/branch.rs b/src/runtime2/branch.rs index 16931db7d8d272feb58fb48d8950889cb978c032..2bc4b40970ebb3e4e47bb2cc73d876d2b9a0ef96 100644 --- a/src/runtime2/branch.rs +++ b/src/runtime2/branch.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use std::ops::{Index, IndexMut}; use crate::protocol::ComponentState; -use crate::protocol::eval::ValueGroup; -use crate::runtime2::port::PortIdLocal; +use crate::protocol::eval::{Value, ValueGroup}; +use crate::runtime2::port::{Port, PortIdLocal}; /// Generic branch ID. A component will always have one branch: the /// non-speculative branch. This branch has ID 0. Hence in a speculative context @@ -55,7 +55,8 @@ pub(crate) struct Branch { pub sync_state: SpeculativeState, pub awaiting_port: PortIdLocal, // only valid if in "awaiting message" queue. TODO: Maybe put in enum pub next_in_queue: BranchId, // used by `ExecTree`/`BranchQueue` - pub inbox: HashMap; // TODO: Remove, currently only valid in single-get/put mode + pub inbox: HashMap, // TODO: Remove, currently only valid in single-get/put mode + pub prepared_channel: Option<(Value, Value)>, // TODO: Maybe remove? } impl Branch { @@ -69,6 +70,7 @@ impl Branch { awaiting_port: PortIdLocal::new_invalid(), next_in_queue: BranchId::new_invalid(), inbox: HashMap::new(), + prepared_channel: None, } } @@ -89,6 +91,7 @@ impl Branch { awaiting_port: parent_branch.awaiting_port, next_in_queue: BranchId::new_invalid(), inbox: parent_branch.inbox.clone(), + prepared_channel: None, } } @@ -210,6 +213,12 @@ impl ExecTree { } } + /// Returns the non-sync branch (TODO: better name?) + pub fn base_branch_mut(&mut self) -> &mut Branch { + debug_assert!(!self.is_in_sync()); + return &mut self.branches[0]; + } + /// Returns an iterator over all the elements in the queue of the given kind pub fn iter_queue(&self, kind: QueueKind) -> BranchQueueIter { let queue = &self.queues[kind.as_index()]; @@ -232,13 +241,15 @@ impl ExecTree { // --- Preparing and finishing a speculative round /// Starts a synchronous round by cloning the non-sync branch and marking it - /// as the root of the speculative tree. - pub fn start_sync(&mut self) { + /// as the root of the speculative tree. The id of this root sync branch is + /// returned. + pub fn start_sync(&mut self) -> BranchId { debug_assert!(!self.is_in_sync()); let sync_branch = Branch::new_sync(1, &self.branches[0]); let sync_branch_id = sync_branch.id; self.branches.push(sync_branch); - self.push_into_queue(QueueKind::Runnable, sync_branch_id); + + return sync_branch_id; } /// Creates a new speculative branch based on the provided one. The index to