diff --git a/src/runtime2/component/component_ip.rs b/src/runtime2/component/component_ip.rs index 1b9b906d48addf922f4f4edc8312d6aeaee8d9ac..7848835ed25cb158db34797fed309145e0ec0141 100644 --- a/src/runtime2/component/component_ip.rs +++ b/src/runtime2/component/component_ip.rs @@ -16,6 +16,8 @@ pub struct ComponentRandomU32 { output_port_id: PortId, random_minimum: u32, random_maximum: u32, + num_sends: u32, + max_num_sends: u32, generator: random::ThreadRng, // Generic state-tracking exec_state: CompExecState, @@ -65,10 +67,15 @@ impl Component for ComponentRandomU32 { panic!("going to crash 'n burn your system now, please provide valid arguments"); } - sched_ctx.log("Entering sync mode"); - self.did_perform_send = false; - self.consensus.notify_sync_start(comp_ctx); - self.exec_state.mode = CompMode::Sync; + if self.num_sends >= self.max_num_sends { + self.exec_state.mode = CompMode::StartExit; + } else { + sched_ctx.log("Entering sync mode"); + self.did_perform_send = false; + self.consensus.notify_sync_start(comp_ctx); + self.exec_state.mode = CompMode::Sync; + } + return Ok(CompScheduling::Immediate); }, CompMode::Sync => { @@ -105,6 +112,7 @@ impl Component for ComponentRandomU32 { // blocked then the moment we become unblocked (and are back // at the `Sync` mode) we have sent the message. self.did_perform_send = true; + self.num_sends += 1; return Ok(scheduling) } else { // Message was sent, finish this sync round @@ -129,16 +137,19 @@ impl Component for ComponentRandomU32 { impl ComponentRandomU32 { pub(crate) fn new(arguments: ValueGroup) -> Self { - debug_assert_eq!(arguments.values.len(), 3); + debug_assert_eq!(arguments.values.len(), 4); debug_assert!(arguments.regions.is_empty()); let port_id = component::port_id_from_eval(arguments.values[0].as_port_id()); let minimum = arguments.values[1].as_uint32(); let maximum = arguments.values[2].as_uint32(); + let num_sends = arguments.values[3].as_uint32(); return Self{ output_port_id: port_id, random_minimum: minimum, random_maximum: maximum, + num_sends: 0, + max_num_sends: num_sends, generator: random::thread_rng(), exec_state: CompExecState::new(), did_perform_send: false,