diff --git a/src/runtime2/component/component.rs b/src/runtime2/component/component.rs index 135b41875ecc54b9a89055b13c4eae4e40856b2c..506699b8b80d90f0aa92e3164f83e04d1d606777 100644 --- a/src/runtime2/component/component.rs +++ b/src/runtime2/component/component.rs @@ -5,7 +5,7 @@ use crate::runtime2::communication::*; use super::{CompCtx, CompPDL}; use super::component_context::*; -use super::component_ip::*; +use super::component_random::*; use super::control_layer::*; use super::consensus::*; @@ -266,6 +266,31 @@ pub(crate) fn default_handle_busy_exit( } } +/// Handles a potential synchronous round decision. If there was a decision then +/// the `Some(success)` value indicates whether the round succeeded or not. +pub(crate) fn default_handle_sync_decision( + exec_state: &mut CompExecState, decision: SyncRoundDecision, + consensus: &mut Consensus +) -> Option { + debug_assert_eq!(exec_state.mode, CompMode::SyncEnd); + let success = match decision { + SyncRoundDecision::None => return None, + SyncRoundDecision::Solution => true, + SyncRoundDecision::Failure => false, + }; + + debug_assert_eq!(exec_state.mode, CompMode::SyncEnd); + if success { + exec_state.mode = CompMode::NonSync; + consensus.notify_sync_decision(decision); + return Some(true); + } else { + exec_state.mode = CompMode::StartExit; + return Some(false); + } +} + + #[inline] pub(crate) fn default_handle_exit(_exec_state: &CompExecState) -> CompScheduling { debug_assert_eq!(_exec_state.mode, CompMode::Exit); @@ -357,7 +382,6 @@ fn default_handle_unblock_put( } } - #[inline] pub(crate) fn port_id_from_eval(port_id: EvalPortId) -> PortId { return PortId(port_id.id);