diff --git a/src/runtime2/inbox.rs b/src/runtime2/inbox.rs index 8b1a6fd9b7a04dca1fd591b7fff46e2127c7975a..6c7f03c300f50335fb7e8b048ba18604d8cfb2bd 100644 --- a/src/runtime2/inbox.rs +++ b/src/runtime2/inbox.rs @@ -239,107 +239,4 @@ impl PublicInbox { let lock = self.messages.lock().unwrap(); return lock.is_empty(); } -} - -pub(crate) struct PrivateInbox { - // "Normal" messages, intended for a PDL protocol. These need to stick - // around during an entire sync-block (to handle `put`s for which the - // corresponding `get`s have not yet been reached). - messages: Vec<(PortIdLocal, DataMessage)>, - len_read: usize, -} - -impl PrivateInbox { - pub fn new() -> Self { - Self{ - messages: Vec::new(), - len_read: 0, - } - } - - /// Will insert the message into the inbox. Only exception is when the tuple - /// (prev_branch_id, cur_branch_id, receiving_port_id) already exists, then - /// nothing is inserted.. - pub(crate) fn insert_message(&mut self, target_port: PortIdLocal, message: DataMessage) { - for (existing_target_port, existing) in self.messages.iter() { - if existing.sender_prev_branch_id == message.sender_prev_branch_id && - existing.sender_cur_branch_id == message.sender_cur_branch_id && - *existing_target_port == target_port { - // Message was already received - return; - } - } - - self.messages.push((target_port, message)); - } - - /// Retrieves all previously read messages that satisfy the provided - /// speculative conditions. Note that the inbox remains read-locked until - /// the returned iterator is dropped. Should only be called by the - /// inbox-reader (i.e. the thread executing a connector's PDL code). - /// - /// This function should only be used to check if already-received messages - /// could be received by a newly encountered `get` call in a connector's - /// PDL code. - pub(crate) fn get_messages(&self, port_id: PortIdLocal, prev_branch_id: BranchId) -> InboxMessageIter { - return InboxMessageIter { - messages: &self.messages, - next_index: 0, - max_index: self.len_read, - match_port_id: port_id, - match_prev_branch_id: prev_branch_id, - }; - } - - /// Retrieves the next unread message. Should only be called by the - /// inbox-reader. - pub(crate) fn next_message(&mut self) -> Option<(&PortIdLocal, &DataMessage)> { - if self.len_read == self.messages.len() { - return None; - } - - let (target_port, message) = &self.messages[self.len_read]; - self.len_read += 1; - return Some((target_port, message)); - } - - /// Simply empties the inbox - pub(crate) fn clear(&mut self) { - self.messages.clear(); - self.len_read = 0; - } -} - -/// Iterator over previously received messages in the inbox. -pub(crate) struct InboxMessageIter<'i> { - messages: &'i Vec<(PortIdLocal, DataMessage)>, - next_index: usize, - max_index: usize, - match_port_id: PortIdLocal, - match_prev_branch_id: BranchId, -} - -impl<'i> Iterator for InboxMessageIter<'i> { - type Item = &'i DataMessage; - - fn next(&mut self) -> Option { - // Loop until match is found or at end of messages - while self.next_index < self.max_index { - let (target_port, cur_message) = &self.messages[self.next_index]; - if *target_port == self.match_port_id && cur_message.sender_prev_branch_id == self.match_prev_branch_id { - // Found a match - break; - } - - self.next_index += 1; - } - - if self.next_index == self.max_index { - return None; - } - - let (_, message) = &self.messages[self.next_index]; - self.next_index += 1; - return Some(message); - } } \ No newline at end of file