Skip to content

Commit 565403b

Browse files
committed
formatting
1 parent 53d4b82 commit 565403b

File tree

10 files changed

+49
-52
lines changed

10 files changed

+49
-52
lines changed

include/reactor-uc/macros_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ typedef struct FederatedInputConnection FederatedInputConnection;
562562
#define LF_DEFINE_STARTUP_COORDINATOR_CTOR(ReactorName, NumNeighbors, LongestPath, NumEvents, JoiningPolicy) \
563563
void ReactorName##StartupCoordinator_ctor(ReactorName##StartupCoordinator *self, Environment *env) { \
564564
StartupCoordinator_ctor(&self->super, env, self->neighbors, NumNeighbors, LongestPath, JoiningPolicy, \
565-
sizeof(StartupEvent), (void *)self->events, self->used, (NumEvents)); \
565+
sizeof(StartupEvent), (void *)self->events, self->used, (NumEvents)); \
566566
}
567567

568568
#define LF_DEFINE_STARTUP_COORDINATOR(ReactorName) ReactorName##StartupCoordinator startup_coordinator;

include/reactor-uc/startup_coordinator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ typedef struct {
2121
bool handshake_response_sent; // Whether a handshake response has been sent to this neighbor.
2222
size_t start_time_proposals_received; // The number of start time proposals received from this neighbor.
2323
StartupCoordinationState initial_state_of_neighbor; // Saves the initial state of the neighbor
24-
interval_t current_logical_time; // Used by transient to figure out the current logical times of all neighboring federates
24+
interval_t
25+
current_logical_time; // Used by transient to figure out the current logical times of all neighboring federates
2526
} NeighborState;
2627

2728
/** The payload of a StartupCoordinator event. */

lfc/core/src/main/java/org/lflang/AttributeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static List<Attribute> getInterfaceAttributes(Instantiation node) {
292292
}
293293

294294
public static Attribute getJoiningPolicy(Instantiation node) {
295-
return findAttributeByName(node, "joining_policy");
295+
return findAttributeByName(node, "joining_policy");
296296
}
297297

298298
public static int getMaxNumberOfPendingEvents(Action node) {

lfc/core/src/main/java/org/lflang/validation/AttributeSpec.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,8 @@ enum AttrParamType {
294294
new AttrParamSpec("args", AttrParamType.STRING, true),
295295
new AttrParamSpec("include", AttrParamType.STRING, false))));
296296
ATTRIBUTE_SPECS_BY_NAME.put(
297-
"joining_policy",
298-
new AttributeSpec(List.of(
299-
new AttrParamSpec("policy", AttrParamType.STRING, false)
300-
))
301-
);
297+
"joining_policy",
298+
new AttributeSpec(List.of(new AttrParamSpec("policy", AttrParamType.STRING, false))));
302299
// @link(type="string", server_port=int, server_side="string", args="string") e.g.
303300
// @link(type="TcpIp", server_port=1042)
304301
ATTRIBUTE_SPECS_BY_NAME.put(

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederate.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ class UcFederate(val inst: Instantiation, val bankIdx: Int) {
3030
}
3131

3232
fun getInterface(name: String): UcNetworkInterface = interfaces.find { it.name == name }!!
33+
3334
fun getJoiningPolicy(): JoiningPolicy {
34-
val attr: Attribute? = AttributeUtils.getJoiningPolicy(inst);
35-
return attr?.let {
36-
JoiningPolicy.parse(it.getAttrParms().get(0).getValue())
37-
}.run {
38-
JoiningPolicy.IMMEDIATELY
39-
};
35+
val attr: Attribute? = AttributeUtils.getJoiningPolicy(inst)
36+
return attr
37+
?.let { JoiningPolicy.parse(it.getAttrParms().get(0).getValue()) }
38+
.run { JoiningPolicy.IMMEDIATELY }
4039
}
4140

4241
fun getDefaultInterface(): UcNetworkInterface = interfaces.first()

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcFederateGenerator.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class UcFederateGenerator(
2424
container, parameters, ports, connections, reactions, fileConfig, messageReporter)
2525
private val clockSync = UcClockSyncGenerator(currentFederate, connections, targetConfig)
2626

27-
private val startupCooordinator = UcStartupCoordinatorGenerator(currentFederate, connections, currentFederate.getJoiningPolicy())
27+
private val startupCooordinator =
28+
UcStartupCoordinatorGenerator(
29+
currentFederate, connections, currentFederate.getJoiningPolicy())
2830
private val headerFile = "lf_federate.h"
2931
private val includeGuard = "LFC_GEN_FEDERATE_${currentFederate.inst.name.uppercase()}_H"
3032

lfc/core/src/main/kotlin/org/lflang/generator/uc/UcStartupCoordinatorGenerator.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ enum class JoiningPolicy {
88
TIMER_ALIGNED;
99

1010
companion object {
11-
fun parse(str: String): JoiningPolicy = when(str) {
11+
fun parse(str: String): JoiningPolicy =
12+
when (str) {
1213
"IMMEDIATELY" -> JoiningPolicy.IMMEDIATELY
1314
"TIMER_ALIGNED" -> JoiningPolicy.TIMER_ALIGNED
1415
else -> throw IllegalArgumentException("Invalid Joining policy specified")
15-
}
16+
}
1617
}
1718
}
1819

19-
fun JoiningPolicy.toCString() = when(this) {
20-
JoiningPolicy.IMMEDIATELY -> "JOIN_IMMEDIATELY"
21-
JoiningPolicy.TIMER_ALIGNED -> "JOIN_INDIVIDUAL_TIMER_ALIGNED"
22-
else -> throw IllegalArgumentException("Joining policy not handled")
23-
}
20+
fun JoiningPolicy.toCString() =
21+
when (this) {
22+
JoiningPolicy.IMMEDIATELY -> "JOIN_IMMEDIATELY"
23+
JoiningPolicy.TIMER_ALIGNED -> "JOIN_INDIVIDUAL_TIMER_ALIGNED"
24+
else -> throw IllegalArgumentException("Joining policy not handled")
25+
}
2426

2527
class UcStartupCoordinatorGenerator(
2628
private val federate: UcFederate,
@@ -51,12 +53,12 @@ class UcStartupCoordinatorGenerator(
5153

5254
val instName = "startup_coordinator"
5355
}
56+
5457
private val numNeighbors = connectionGenerator.getNumFederatedConnectionBundles()
5558
private val numSystemEvents = getNumSystemEvents(numNeighbors)
5659
private val longestPath = connectionGenerator.getLongestFederatePath()
5760
private val typeName = "Federate"
5861

59-
6062
fun generateSelfStruct() =
6163
"LF_DEFINE_STARTUP_COORDINATOR_STRUCT(${typeName}, ${numNeighbors}, ${numSystemEvents})"
6264

src/schedulers/dynamic/scheduler.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ void Scheduler_do_shutdown(Scheduler *untyped_self, tag_t shutdown_tag) {
227227
}
228228
}
229229

230-
231-
232230
void Scheduler_set_and_schedule_start_tag(Scheduler *untyped_self, instant_t start_time) {
233231
DynamicScheduler *self = (DynamicScheduler *)untyped_self;
234232

src/startup_coordinator.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ void StartupCoordinator_schedule_timers(StartupCoordinator *self, const Reactor
8484
}
8585
}
8686

87-
void StartupCoordinator_schedule_timers_joining(StartupCoordinator* self, Reactor* reactor, interval_t federation_start_time, interval_t join_time) {
87+
void StartupCoordinator_schedule_timers_joining(StartupCoordinator *self, Reactor *reactor,
88+
interval_t federation_start_time, interval_t join_time) {
8889
lf_ret_t ret;
8990
for (size_t i = 0; i < reactor->triggers_size; i++) {
9091
Trigger *trigger = reactor->triggers[i];
@@ -377,7 +378,7 @@ static void StartupCoordinator_handle_start_time_proposal(StartupCoordinator *se
377378
}
378379

379380
static void StartupCoordinator_handle_start_time_request(StartupCoordinator *self, StartupEvent *payload) {
380-
FederatedEnvironment* env = (FederatedEnvironment*)self->env;
381+
FederatedEnvironment *env = (FederatedEnvironment *)self->env;
381382
if (payload->neighbor_index == NEIGHBOR_INDEX_SELF) {
382383
for (size_t i = 0; i < self->num_neighbours; i++) {
383384
NetworkChannel *chan = env->net_bundles[i]->net_channel;
@@ -390,7 +391,7 @@ static void StartupCoordinator_handle_start_time_request(StartupCoordinator *sel
390391

391392
// We now schedule a system event here, because otherwise we will never detect no other federates responding
392393
StartupCoordinator_schedule_system_self_event(self, self->env->get_physical_time(self->env) + MSEC(250),
393-
StartupCoordination_start_time_response_tag);
394+
StartupCoordination_start_time_response_tag);
394395
}
395396

396397
} else {
@@ -404,18 +405,16 @@ static void StartupCoordinator_handle_start_time_request(StartupCoordinator *sel
404405
self->env->get_elapsed_logical_time(self->env);
405406
msg->message.startup_coordination.message.start_time_response.federation_start_time = self->start_time_proposal;
406407
chan->send_blocking(chan, msg);
407-
LF_INFO(FED, "SENDING TIME start_tag: " PRINTF_TIME " elapsed_time: " PRINTF_TIME,
408-
msg->message.startup_coordination.message.start_time_response.federation_start_time,
409-
msg->message.startup_coordination.message.start_time_response.elapsed_logical_time);
408+
LF_INFO(FED, "SENDING TIME start_tag: " PRINTF_TIME " elapsed_time: " PRINTF_TIME,
409+
msg->message.startup_coordination.message.start_time_response.federation_start_time,
410+
msg->message.startup_coordination.message.start_time_response.elapsed_logical_time);
410411
break;
411412
}
412413
default:;
413414
}
414415
}
415416
}
416417

417-
418-
419418
static void StartupCoordinator_handle_start_time_response(StartupCoordinator *self, StartupEvent *payload) {
420419
if (self->start_time_proposal > 0) {
421420
return;
@@ -462,23 +461,23 @@ static void StartupCoordinator_handle_start_time_response(StartupCoordinator *se
462461
instant_t joining_time = 0;
463462

464463
if (self->joining_policy == JOIN_IMMEDIATELY) {
465-
joining_time = max_logical_time + MSEC(50);
466-
tag_t start_tag = {.time = joining_time, .microstep = 0};
467-
LF_INFO(FED, "Policy: IMMEDIATELY Scheduling join_time: " PRINTF_TIME, joining_time);
468-
self->env->scheduler->prepare_timestep(self->env->scheduler, NEVER_TAG);
469-
StartupCoordinator_schedule_startups(self, start_tag);
470-
StartupCoordinator_schedule_timers(self, self->env->main, start_tag);
471-
self->env->scheduler->prepare_timestep(self->env->scheduler, start_tag);
472-
self->env->scheduler->set_and_schedule_start_tag(self->env->scheduler, joining_time);
464+
joining_time = max_logical_time + MSEC(50);
465+
tag_t start_tag = {.time = joining_time, .microstep = 0};
466+
LF_INFO(FED, "Policy: IMMEDIATELY Scheduling join_time: " PRINTF_TIME, joining_time);
467+
self->env->scheduler->prepare_timestep(self->env->scheduler, NEVER_TAG);
468+
StartupCoordinator_schedule_startups(self, start_tag);
469+
StartupCoordinator_schedule_timers(self, self->env->main, start_tag);
470+
self->env->scheduler->prepare_timestep(self->env->scheduler, start_tag);
471+
self->env->scheduler->set_and_schedule_start_tag(self->env->scheduler, joining_time);
473472
} else if (self->joining_policy == JOIN_ALIGNED_WITH_SHORT_TIMER) {
474-
joining_time = max_logical_time + MSEC(50);
475-
tag_t start_tag = {.time = joining_time, .microstep = 0};
476-
LF_INFO(FED, "Policy: Timer Aligned Scheduling join_time: " PRINTF_TIME, joining_time);
477-
self->env->scheduler->prepare_timestep(self->env->scheduler, NEVER_TAG);
478-
StartupCoordinator_schedule_startups(self, start_tag);
479-
StartupCoordinator_schedule_timers_joining(self, self->env->main, start_time, joining_time);
480-
self->env->scheduler->prepare_timestep(self->env->scheduler, start_tag);
481-
self->env->scheduler->set_and_schedule_start_tag(self->env->scheduler, joining_time);
473+
joining_time = max_logical_time + MSEC(50);
474+
tag_t start_tag = {.time = joining_time, .microstep = 0};
475+
LF_INFO(FED, "Policy: Timer Aligned Scheduling join_time: " PRINTF_TIME, joining_time);
476+
self->env->scheduler->prepare_timestep(self->env->scheduler, NEVER_TAG);
477+
StartupCoordinator_schedule_startups(self, start_tag);
478+
StartupCoordinator_schedule_timers_joining(self, self->env->main, start_time, joining_time);
479+
self->env->scheduler->prepare_timestep(self->env->scheduler, start_tag);
480+
self->env->scheduler->set_and_schedule_start_tag(self->env->scheduler, joining_time);
482481
} else {
483482
validate(false);
484483
}
@@ -516,9 +515,8 @@ static void StartupCoordinator_handle_system_event(SystemEventHandler *_self, Sy
516515

517516
case StartupCoordination_joining_time_announcement_tag:
518517
LF_INFO(FED, "Handle: Announcement of Joining Tag");
519-
//TODO: here we then need to set the last message tag on all input ports connected to this transient federate
518+
// TODO: here we then need to set the last message tag on all input ports connected to this transient federate
520519
break;
521-
522520
}
523521

524522
_self->payload_pool.free(&_self->payload_pool, event->super.payload);

test/unit/request_shutdown_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ int main() {
3232
UNITY_BEGIN();
3333
RUN_TEST(test_run);
3434
return UNITY_END();
35-
}
35+
}

0 commit comments

Comments
 (0)