From 32d9f23a4c8714db3a13f9870face745569f93e6 2021-11-12 13:37:37 From: MH Date: 2021-11-12 13:37:37 Subject: [PATCH] fix clearing too many messages --- diff --git a/src/runtime2/connector.rs b/src/runtime2/connector.rs index 28756d719a417835b7988cfe2b8e6b33cd994fa1..5cd7bd6061b890d86093fffdebfb7e5975a95a9f 100644 --- a/src/runtime2/connector.rs +++ b/src/runtime2/connector.rs @@ -55,7 +55,7 @@ impl ConnectorPublic { } } -#[derive(Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub(crate) enum ConnectorScheduling { Immediate, // Run again, immediately Later, // Schedule for running, at some later point in time diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index eb8ccbae8bcebfe6e4c6279c845c0c23e0065445..092b65f090107f47fe0c48f9656a99c6f473e2e6 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -296,8 +296,9 @@ impl Scheduler { if scheduled.ctx.is_in_sync { // Just entered sync region } else { - // Just left sync region. So clear inbox - scheduled.ctx.inbox_messages.clear(); + // Just left sync region. So clear inbox up until the last + // message that was read. + scheduled.ctx.inbox_messages.drain(0..scheduled.ctx.inbox_len_read); scheduled.ctx.inbox_len_read = 0; } @@ -380,7 +381,7 @@ pub(crate) struct ComponentCtx { // Mostly managed by the scheduler pub(crate) id: ConnectorId, ports: Vec, - inbox_messages: Vec, // never control or ping messages + inbox_messages: Vec, inbox_len_read: usize, // Submitted by the component is_in_sync: bool, diff --git a/src/runtime2/tests/api_component.rs b/src/runtime2/tests/api_component.rs index f4271190e131654ae8379ae6fed02e85a782ecfa..38cf5059ddfd035ffc2249a4e39ae2bfaca7415d 100644 --- a/src/runtime2/tests/api_component.rs +++ b/src/runtime2/tests/api_component.rs @@ -47,4 +47,46 @@ fn test_put_and_get() { assert!(false); } } +} + +#[test] +fn test_getting_from_component() { + const CODE: &'static str =" + primitive loop_sender(out numbers, u32 cur, u32 last) { + while (cur < last) { + print(\"sync start\"); + synchronous { + print(\"sending\"); + put(numbers, cur); + cur += 1; + } + print(\"sync solution!\"); + } + }"; + + let pd = ProtocolDescription::parse(CODE.as_bytes()).unwrap(); + let rt = Runtime::new(NUM_THREADS, pd); + let mut api = rt.create_interface(); + + let channel = api.create_channel().unwrap(); + api.create_connector("", "loop_sender", ValueGroup::new_stack(vec![ + Value::Output(PortId::new(channel.putter_id.index)), + Value::UInt32(1337), + Value::UInt32(1337 + NUM_LOOPS) + ])).unwrap(); + + for loop_idx in 0..NUM_LOOPS { + api.perform_sync_round(vec![ + ApplicationSyncAction::Get(channel.getter_id), + ]).expect("start sync round"); + + let result = api.wait().expect("finish sync round"); + + assert!(result.len() == 1 && result[0].values.len() == 1); + if let Value::UInt32(gotten) = result[0].values[0] { + assert_eq!(gotten, 1337 + loop_idx); + } else { + assert!(false); + } + } } \ No newline at end of file