Skip to content

Commit

Permalink
Merge pull request #2285 from lf-lang/clock-sync-initial
Browse files Browse the repository at this point in the history
Code-generator changes required for reactor-c clock-sync fix
  • Loading branch information
edwardalee authored May 15, 2024
2 parents 4f8d889 + 7cfa09e commit c58ed51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ public static void initializeClockSynchronization(
.nowhere()
.info("Runtime clock synchronization is enabled for federate " + federate.id);
}

addClockSyncCompileDefinitions(federate);
} else {
addDisableClockSyncCompileDefinitions(federate);
}
}

Expand All @@ -272,20 +273,24 @@ public static void addClockSyncCompileDefinitions(FederateInstance federate) {
ClockSyncOptions options = federate.targetConfig.get(ClockSyncOptionsProperty.INSTANCE);
final var defs = new HashMap<String, String>();

defs.put("LF_CLOCK_SYNC", String.valueOf(mode.toInt()));
defs.put("_LF_CLOCK_SYNC_INITIAL", "");
defs.put("_LF_CLOCK_SYNC_PERIOD_NS", String.valueOf(options.period.toNanoSeconds()));
defs.put("_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL", String.valueOf(options.trials));
defs.put("_LF_CLOCK_SYNC_ATTENUATION", String.valueOf(options.attenuation));

if (mode == ClockSyncMode.ON) {
defs.put("_LF_CLOCK_SYNC_ON", "");
if (options.collectStats) {
defs.put("_LF_CLOCK_SYNC_COLLECT_STATS", "");
}
if (options.collectStats) {
defs.put("_LF_CLOCK_SYNC_COLLECT_STATS", "");
}
CompileDefinitionsProperty.INSTANCE.update(federate.targetConfig, defs);
}

public static void addDisableClockSyncCompileDefinitions(FederateInstance federate) {
final var defs = new HashMap<String, String>();
defs.put("LF_CLOCK_SYNC", String.valueOf(ClockSyncMode.OFF.toInt()));
CompileDefinitionsProperty.INSTANCE.update(federate.targetConfig, defs);
}

/** Generate a file to be included by CMake. */
public static void generateCMakeInclude(
FederateInstance federate, FederationFileConfig fileConfig) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@ protected Class<ClockSyncMode> enumClass() {
* <li>ON: Clock synchronization occurs at startup and at runtime.
* </ul>
*
* The values associated with the enum must match what is defined in clock_sync.h in reactor-c
*
* @author Edward A. Lee
*/
public enum ClockSyncMode {
OFF,
INIT,
ON;
OFF(1),
INIT(2),
ON(3);
private final int value;

private ClockSyncMode(int value) {
this.value = value;
}
/** Return the name in lower case. */
@Override
public String toString() {
return this.name().toLowerCase();
}

public int toInt() {
return this.value;
}
}
}

0 comments on commit c58ed51

Please sign in to comment.