From fab309ac1a28897c91a44b85a881aae7a2663625 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 9 Mar 2023 11:13:20 +0100 Subject: [PATCH 1/6] remove keepalive in C++ code generator --- .../src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt | 3 +-- .../org/lflang/generator/cpp/CppStandaloneMainGenerator.kt | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt index 064f6758f8..22e3c3045a 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppRos2NodeGenerator.kt @@ -59,14 +59,13 @@ class CppRos2NodeGenerator( | : Node("$nodeName", node_options) { | unsigned workers = ${if (targetConfig.workers != 0) targetConfig.workers else "std::thread::hardware_concurrency()"}; | bool fast{${targetConfig.fastMode}}; - | bool keepalive{${targetConfig.keepalive}}; | reactor::Duration lf_timeout{${targetConfig.timeout?.toCppCode() ?: "reactor::Duration::max()"}}; | | // provide a globally accessible reference to this node | // FIXME: this is pretty hacky... | lf_node = this; | - | lf_env = std::make_unique(workers, keepalive, fast, lf_timeout); + | lf_env = std::make_unique(workers, fast, lf_timeout); | | // instantiate the main reactor | lf_main_reactor = std::make_unique<${main.name}> ("${main.name}", lf_env.get(), ${main.name}::Parameters{}); diff --git a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt index 171b59c485..07cd3f8ba2 100644 --- a/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt +++ b/org.lflang/src/org/lflang/generator/cpp/CppStandaloneMainGenerator.kt @@ -60,7 +60,6 @@ class CppStandaloneMainGenerator( | | unsigned workers = ${if (targetConfig.workers != 0) targetConfig.workers else "std::thread::hardware_concurrency()"}; | bool fast{${targetConfig.fastMode}}; - | bool keepalive{${targetConfig.keepalive}}; | reactor::Duration timeout = ${targetConfig.timeout?.toCppCode() ?: "reactor::Duration::max()"}; | | // the timeout variable needs to be tested beyond fitting the Duration-type @@ -69,7 +68,6 @@ class CppStandaloneMainGenerator( | .add_options() | ("w,workers", "the number of worker threads used by the scheduler", cxxopts::value(workers)->default_value(std::to_string(workers)), "'unsigned'") | ("o,timeout", "Time after which the execution is aborted.", cxxopts::value(timeout)->default_value(time_to_string(timeout)), "'FLOAT UNIT'") - | ("k,keepalive", "Continue execution even when there are no events to process.", cxxopts::value(keepalive)->default_value("${targetConfig.keepalive}")) | ("f,fast", "Allow logical time to run faster than physical time.", cxxopts::value(fast)->default_value("${targetConfig.fastMode}")) | ("help", "Print help"); | @@ -91,7 +89,7 @@ class CppStandaloneMainGenerator( | return parse_error ? -1 : 0; | } | - | reactor::Environment e{workers, keepalive, fast, timeout}; + | reactor::Environment e{workers, fast, timeout}; | | // instantiate the main reactor | ${generateMainReactorInstantiation()} From affaa275506db44804021aa46893bee795ba88fd Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 9 Mar 2023 12:09:48 +0100 Subject: [PATCH 2/6] update reactor-cpp --- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a37f0ade9e..a63a870180 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a37f0ade9ee0f97606528fd7ba67712495948373 +Subproject commit a63a870180137a023b7faf875271775787a56c03 From d1c6ba18d3ba205dd06d4d9bf5400d7214ffbdde Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 9 Mar 2023 12:15:47 +0100 Subject: [PATCH 3/6] warn if keepalive is used in C++ --- org.lflang/src/org/lflang/validation/LFValidator.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index f53987e2b5..2dcd967689 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -623,7 +623,7 @@ public void checkParameter(Parameter param) { Reactor reactor = (Reactor) container; if (reactor.isMain()) { // we need to check for the cli parameters that are always taken - List cliParams = List.of("t", "threads", "o", "timeout", "k", "keepalive", "f", "fast", "help"); + List cliParams = List.of("t", "threads", "o", "timeout", "f", "fast", "help"); if (cliParams.contains(param.getName())) { error("Parameter '" + param.getName() + "' is already in use as command line argument by Lingua Franca,", @@ -1030,6 +1030,7 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { validateClockSyncTargetProperties(targetProperties); validateSchedulerTargetProperties(targetProperties); validateRos2TargetProperties(targetProperties); + validateKeepalive(targetProperties); } private KeyValuePair getKeyValuePair(KeyValuePairs targetProperties, TargetProperty property) { @@ -1125,6 +1126,14 @@ private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { } } + private void validateKeepalive(KeyValuePairs targetProperties) { + KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); + if (keepalive != null) { + warning("The keepalive property is inferred automatically by the C++ " + + "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); + } + } + private void validateRos2TargetProperties(KeyValuePairs targetProperties) { KeyValuePair ros2 = getKeyValuePair(targetProperties, TargetProperty.ROS2); KeyValuePair ros2Dependencies = getKeyValuePair(targetProperties, TargetProperty.ROS2_DEPENDENCIES); From 71739e88661282e327524a056be65f412cce9208 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 10 Mar 2023 16:10:45 +0100 Subject: [PATCH 4/6] update reactor-cpp --- .github/scripts/test-lfc.sh | 2 +- org.lflang/src/lib/cpp/reactor-cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/test-lfc.sh b/.github/scripts/test-lfc.sh index 20c087db81..a59d4acd3b 100755 --- a/.github/scripts/test-lfc.sh +++ b/.github/scripts/test-lfc.sh @@ -50,7 +50,7 @@ bin/lfc --output-path . test/C/src/Minimal.lf # --runtime-version Specify the version of the runtime # library used for compiling LF # programs. -bin/lfc --runtime-version f157be30bbeab0e2a991f29f9c7f388ca39681a7 test/Cpp/src/Minimal.lf +bin/lfc --runtime-version e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 test/Cpp/src/Minimal.lf # -w,--workers Specify the default number of worker threads. bin/lfc -w 2 test/C/src/Minimal.lf diff --git a/org.lflang/src/lib/cpp/reactor-cpp b/org.lflang/src/lib/cpp/reactor-cpp index a63a870180..e80cd36ce5 160000 --- a/org.lflang/src/lib/cpp/reactor-cpp +++ b/org.lflang/src/lib/cpp/reactor-cpp @@ -1 +1 @@ -Subproject commit a63a870180137a023b7faf875271775787a56c03 +Subproject commit e80cd36ce5bd625a7b167e7dfd65d25f78b0dd01 From 05acf6b0efcb71675ca9b6081f0eaa6222763ac8 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 10 Mar 2023 17:54:49 +0100 Subject: [PATCH 5/6] check keepalive only in C++ --- org.lflang/src/org/lflang/validation/LFValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 2dcd967689..c2fcb1cf34 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1128,7 +1128,7 @@ private void validateSchedulerTargetProperties(KeyValuePairs targetProperties) { private void validateKeepalive(KeyValuePairs targetProperties) { KeyValuePair keepalive = getKeyValuePair(targetProperties, TargetProperty.KEEPALIVE); - if (keepalive != null) { + if (keepalive != null && target == Target.CPP) { warning("The keepalive property is inferred automatically by the C++ " + "runtime and the value given here is ignored", keepalive, Literals.KEY_VALUE_PAIR__NAME); } From 8ac59367893835e189dfd860677268c350d6ee47 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Fri, 10 Mar 2023 17:55:27 +0100 Subject: [PATCH 6/6] update C++ tests --- test/Cpp/src/concurrent/AsyncCallback.lf | 1 - test/Cpp/src/concurrent/AsyncCallback2.lf | 1 - test/Cpp/src/properties/Keepalive.lf | 43 ----------------------- 3 files changed, 45 deletions(-) delete mode 100644 test/Cpp/src/properties/Keepalive.lf diff --git a/test/Cpp/src/concurrent/AsyncCallback.lf b/test/Cpp/src/concurrent/AsyncCallback.lf index 29fedc41e8..984132f133 100644 --- a/test/Cpp/src/concurrent/AsyncCallback.lf +++ b/test/Cpp/src/concurrent/AsyncCallback.lf @@ -1,7 +1,6 @@ // Test asynchronous callbacks that trigger a physical action. target Cpp { timeout: 2 sec, - keepalive: true, cmake-include: "AsyncCallback.cmake" } diff --git a/test/Cpp/src/concurrent/AsyncCallback2.lf b/test/Cpp/src/concurrent/AsyncCallback2.lf index ea493a32cd..322413617b 100644 --- a/test/Cpp/src/concurrent/AsyncCallback2.lf +++ b/test/Cpp/src/concurrent/AsyncCallback2.lf @@ -1,7 +1,6 @@ // Test asynchronous callbacks that trigger a non-physical action. target Cpp { timeout: 2 sec, - keepalive: true, cmake-include: "AsyncCallback.cmake" } diff --git a/test/Cpp/src/properties/Keepalive.lf b/test/Cpp/src/properties/Keepalive.lf deleted file mode 100644 index 1fe6c5e1bc..0000000000 --- a/test/Cpp/src/properties/Keepalive.lf +++ /dev/null @@ -1,43 +0,0 @@ -target Cpp { - keepalive: true, - cmake-include: "../concurrent/AsyncCallback.cmake" -} - -main reactor { - public preamble {= - #include - =} - - state thread: std::thread - - physical action a - state success: bool{false} - - reaction(startup) -> a {= - // start new thread - this->thread = std::thread([&] () { - // Simulate time passing before a callback occurs - std::this_thread::sleep_for(1s); - a.schedule(); - }); - =} - - reaction(a) {= - success = true; - environment()->sync_shutdown(); - =} - - reaction(shutdown) {= - if (success) { - std::cout << "SUCCESS!\n"; - } else { - std::cout << "ERROR: reaction was not invoked!\n"; - exit(1); - } - - // make sure to join the thread before shutting down - if(thread.joinable()) { - thread.join(); - } - =} -}