Skip to content

Commit

Permalink
Merge pull request lf-lang#2082 from lf-lang/token-racing-cond
Browse files Browse the repository at this point in the history
Fix race-condition in _lf_replace_template_token
  • Loading branch information
edwardalee authored Nov 6, 2023
2 parents 63a3d9c + 537945d commit 090789b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ protected void generateReactorClassHeaders(
}
header.pr("#include \"include/core/reactor.h\"");
src.pr("#include \"include/api/api.h\"");
src.pr("#include \"include/core/platform.h\"");
generateIncludes(tpr);
if (cppMode) {
src.pr("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ public static String generateForwardBody(
? String.join(
"\n",
DISABLE_REACTION_INITIALIZATION_MARKER,
"lf_critical_section_enter(self->base.environment);",
"self->_lf_"
+ outputName
+ ".value = ("
Expand All @@ -348,7 +349,8 @@ public static String generateForwardBody(
+ ", (lf_token_t*)self->_lf__"
+ actionName
+ ".tmplt.token);",
"self->_lf_" + outputName + ".is_present = true;")
"self->_lf_" + outputName + ".is_present = true;",
"lf_critical_section_exit(self->base.environment);")
: "lf_set(" + outputName + ", " + actionName + "->value);";
}

Expand Down Expand Up @@ -551,6 +553,7 @@ private static String generateActionVariablesInReaction(
builder.pr(
String.join(
"\n",
"lf_critical_section_enter(self->base.environment);",
"// Expose the action struct as a local variable whose name matches the action name.",
structType + "* " + action.getName() + " = &self->_lf_" + action.getName() + ";",
"// Set the fields of the action struct to match the current trigger.",
Expand All @@ -565,7 +568,8 @@ private static String generateActionVariablesInReaction(
+ action.getName()
+ ", "
+ tokenPointer
+ ");"));
+ ");",
"lf_critical_section_exit(self->base.environment);"));
// Set the value field only if there is a type.
if (!type.isUndefined()) {
// The value field will either be a copy (for primitive types)
Expand Down

0 comments on commit 090789b

Please sign in to comment.