diff --git a/src/runtime2/branch.rs b/src/runtime2/branch.rs index 2bc4b40970ebb3e4e47bb2cc73d876d2b9a0ef96..4b3e5a79740ff5ffd7da36ce8f791911057d3739 100644 --- a/src/runtime2/branch.rs +++ b/src/runtime2/branch.rs @@ -130,6 +130,7 @@ impl BranchQueue { const NUM_QUEUES: usize = 3; +#[derive(PartialEq, Eq)] pub(crate) enum QueueKind { Runnable, AwaitingMessage, @@ -185,6 +186,7 @@ impl ExecTree { /// Pops a branch (ID) from a queue. pub fn pop_from_queue(&mut self, kind: QueueKind) -> Option { + debug_assert_ne!(kind, QueueKind::FinishedSync); // for purposes of logic we expect the queue to grow during a sync round let queue = &mut self.queues[kind.as_index()]; if queue.is_empty() { return None; @@ -219,10 +221,24 @@ impl ExecTree { 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 { + /// Returns an iterator over all the elements in the queue of the given + /// kind. One can start the iteration at the branch *after* the provided + /// branch. Just make sure it actually is in the provided queue. + pub fn iter_queue(&self, kind: QueueKind, start_at: Option) -> BranchQueueIter { let queue = &self.queues[kind.as_index()]; - let index = queue.first as usize; + + let index = match start_at { + Some(branch_id) => { + debug_assert!(self.iter_queue(kind, None).any(|v| v.id == branch_id)); + let branch = &self.branches[branch_id.index as usize]; + + branch.next_in_queue.index as usize + }, + None => { + queue.first as usize + } + }; + return BranchQueueIter { branches: self.branches.as_slice(), index,