Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scheduling physical actions synchronously #1367

Merged
merged 6 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ lsp4jVersion=0.14.0
mwe2LaunchVersion=2.12.2
openTest4jVersion=1.2.0
resourcesVersion=3.16.0
runtimeVersion=3.25.0
shadowJarVersion=7.1.2
xtextGradleVersion=3.0.0
xtextVersion=2.27.0
Expand Down
2 changes: 0 additions & 2 deletions org.lflang/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
dependencies {
implementation "org.eclipse.xtext:org.eclipse.xtext:${xtextVersion}"
implementation "org.eclipse.xtext:org.eclipse.xtext.xbase.lib:${xtextVersion}"
// https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.runtime
implementation group: 'org.eclipse.platform', name: 'org.eclipse.core.runtime', version: "${runtimeVersion}"
// https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources
implementation group: 'org.eclipse.platform', name: 'org.eclipse.core.resources', version: "${resourcesVersion}"
// https://mvnrepository.com/artifact/org.eclipse.emf/org.eclipse.emf.mwe2.launch
Expand Down
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