Skip to content

Commit

Permalink
Merge pull request #1367 from lf-lang/rust.synchronous-physical-schedule
Browse files Browse the repository at this point in the history
Support scheduling physical actions synchronously
  • Loading branch information
cmnrd authored Sep 19, 2022
2 parents d485bcc + 050fdb2 commit dae5946
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion org.lflang/src/lib/rs/reactor-rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ ${" | "..declareChildConnections()}
else -> "&$rsRuntime::ReadablePort<$dataType>" // note: a reference
}
is TimerData -> "&${toType()}"
is ActionData -> if (isLogical && kind == DepKind.Effects) "&mut ${toType()}" else "&${toType()}"
is ActionData -> if (kind == DepKind.Effects) "&mut ${toType()}" else "&${toType()}"
}

/**
Expand Down
28 changes: 28 additions & 0 deletions test/Rust/src/PhysicalActionCanBeScheduledSynchronously.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Tests that physical actions can be scheduled like logical actions within the
// body of reactions.
target Rust

main reactor {
physical action act: u32

state count: u32

reaction(startup) -> act {=
ctx.schedule(act, Asap);
ctx.schedule(act, after!(20 ms));
=}

reaction(act) {=
println!("---- Invocation at {}", ctx.get_tag());
self.count += 1;

// If the physical time is used then it is unlikely to be
// exactly TO + 20 ms.
assert_ne!(ctx.get_elapsed_logical_time(), delay!(20 ms));
=}

reaction(shutdown) {=
assert_eq!(self.count, 2);
println!("success");
=}
}
1 change: 1 addition & 0 deletions test/Rust/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ This is not exhaustive. Ideally each of those bullet points would have a test ca
- [x] `PhysicalActionWithKeepalive.lf`: keepalive option should keep the scheduler alive when there are async threads which can send notifications
- [x] `PhysicalActionWakesSleepingScheduler.lf`: a physical action triggered during a period of idleness of the scheduler should wake it timely
- [x] `PhysicalActionKeepaliveIsSmart.lf`: keepalive option doesn't keep the program alive if live threads do not have a reference to the scheduler
- [x] `PhysicalActionCanBeScheduledSynchronously.lf`: physical actions do not need to be carried by an asynchronous thread to be scheduled. When they are scheduled within a reaction, they still use physical time and not logical time.
- [ ] todo does shutdown abort async threads or not?
- [x] timers
- [x] `TimerDefaults.lf`: timer with all params defaulted (`timer t;`) is non-periodic and has offset zero
Expand Down

0 comments on commit dae5946

Please # to comment.