Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Nov 18, 2024
1 parent 27a5ec5 commit 9a57000
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 146 deletions.
8 changes: 4 additions & 4 deletions include/reactor-uc/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
typedef struct Environment Environment;

struct Environment {
Reactor *main; // The top-level reactor of the program.
Scheduler* scheduler; // The scheduler in charge of executing the reactions.
Platform *platform; // The platform that provides the physical time and sleep functions.
Reactor *main; // The top-level reactor of the program.
Scheduler *scheduler; // The scheduler in charge of executing the reactions.
Platform *platform; // The platform that provides the physical time and sleep functions.
bool has_async_events;
BuiltinTrigger *startup; // A pointer to a startup trigger, if the program has one.
BuiltinTrigger *shutdown; // A pointer to a chain of shutdown triggers, if the program has one.
Expand Down Expand Up @@ -59,7 +59,7 @@ struct Environment {
void (*request_shutdown)(Environment *self);
};

void Environment_ctor(Environment *self, Scheduler* scheduler, Reactor *main);
void Environment_ctor(Environment *self, Scheduler *scheduler, Reactor *main);
void Environment_free(Environment *self);

#endif
2 changes: 1 addition & 1 deletion include/reactor-uc/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if (ret == LF_FATAL) { \
LF_ERR(TRIG, "Scheduling an value, that doesn't have value!"); \
Scheduler *sched = &(action)->super.super.parent->env->scheduler; \
sched->do_shutdown(sched, sched->current_tag(sched)); \
sched->do_shutdown(sched, sched->current_tag(sched)); \
throw("Tried to schedule a value onto an action without a type!"); \
} \
} while (0)
Expand Down
10 changes: 5 additions & 5 deletions include/reactor-uc/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ typedef struct Scheduler Scheduler;
typedef struct Environment Environment;

struct Scheduler {
long int start_time;
long int start_time;

/**
* @brief Schedules an event on trigger at a specified tag. This function will
Expand Down Expand Up @@ -62,13 +62,13 @@ struct Scheduler {

void (*acquire_and_schedule_start_tag)(Scheduler *self);

void (*set_duration)(Scheduler* self, interval_t duration);
void (*set_duration)(Scheduler *self, interval_t duration);

lf_ret_t (*add_to_reaction_queue)(Scheduler *self, Reaction* reaction);
lf_ret_t (*add_to_reaction_queue)(Scheduler *self, Reaction *reaction);

tag_t (*current_tag)(Scheduler* self);
tag_t (*current_tag)(Scheduler *self);
};

void Scheduler_ctor(Scheduler* self);
void Scheduler_ctor(Scheduler *self);

#endif
2 changes: 1 addition & 1 deletion include/reactor-uc/schedulers/dynamic/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ struct DynamicScheduler {

void DynamicScheduler_ctor(DynamicScheduler *self, Environment *env);

#endif //SCHEDULER_H
#endif // SCHEDULER_H
65 changes: 26 additions & 39 deletions include/reactor-uc/schedulers/static/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,31 @@
*/
void push_pop_peek_pqueue(void *self);

void execute_inst_ADD(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_ADDI(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BEQ(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BGE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BNE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_DU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_EXE(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WLT(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WU(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JAL(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JALR(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_STP(Platform* platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc,
Reaction **returned_reaction, bool *exit_loop);
void execute_inst_ADD(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_ADDI(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3,
bool debug, size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BEQ(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BGE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_BNE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_DU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_EXE(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WLT(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_WU(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JAL(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_JALR(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3,
bool debug, size_t *pc, Reaction **returned_reaction, bool *exit_loop);
void execute_inst_STP(Platform *platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3, bool debug,
size_t *pc, Reaction **returned_reaction, bool *exit_loop);

#endif
8 changes: 4 additions & 4 deletions include/reactor-uc/schedulers/static/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ typedef struct StaticScheduler StaticScheduler;
typedef struct Environment Environment;

struct StaticScheduler {
Scheduler* scheduler;
Scheduler *scheduler;
Environment *env;
const inst_t** static_schedule;
size_t* pc;
const inst_t **static_schedule;
size_t *pc;
};

void StaticScheduler_ctor(StaticScheduler *self, Environment *env);

#endif //STATIC_SCHEDULER_H
#endif // STATIC_SCHEDULER_H
6 changes: 3 additions & 3 deletions include/reactor-uc/schedulers/static/scheduler_instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ typedef union {
/**
* @brief Virtual instruction function pointer
*/
typedef void (*function_virtual_instruction_t)(
Platform* platform, size_t worker_number, operand_t op1, operand_t op2, operand_t op3,
bool debug, size_t *pc, Reaction **returned_reaction, bool *exit_loop);
typedef void (*function_virtual_instruction_t)(Platform *platform, size_t worker_number, operand_t op1, operand_t op2,
operand_t op3, bool debug, size_t *pc, Reaction **returned_reaction,
bool *exit_loop);

/**
* @brief This struct represents a PRET VM instruction for C platforms.
Expand Down
6 changes: 4 additions & 2 deletions src/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ lf_ret_t Environment_wait_until(Environment *self, instant_t wakeup_time) {
}
}

interval_t Environment_get_logical_time(Environment *self) { return self->scheduler->current_tag(self->scheduler).time; }
interval_t Environment_get_logical_time(Environment *self) {
return self->scheduler->current_tag(self->scheduler).time;
}
interval_t Environment_get_elapsed_logical_time(Environment *self) {
return self->scheduler->current_tag(self->scheduler).time - self->scheduler->start_time;
}
Expand All @@ -63,7 +65,7 @@ void Environment_leave_critical_section(Environment *self) {

void Environment_request_shutdown(Environment *self) { self->scheduler->request_shutdown(self->scheduler); }

void Environment_ctor(Environment *self, Scheduler* scheduler, Reactor *main) {
void Environment_ctor(Environment *self, Scheduler *scheduler, Reactor *main) {
self->main = main;
self->scheduler = scheduler;
self->platform = Platform_new();
Expand Down
4 changes: 1 addition & 3 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
#include "schedulers/dynamic/dynamic.c"
#include "schedulers/static/scheduler.c"

void Scheduler_ctor(Scheduler* self) {
(void)self;
}
void Scheduler_ctor(Scheduler *self) { (void)self; }
42 changes: 20 additions & 22 deletions src/schedulers/dynamic/dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void Scheduler_prepare_builtin(Event *event) {
* `next_tag` and prepare the associated triggers.
*/
static void Scheduler_pop_events_and_prepare(Scheduler *untyped_self, tag_t next_tag) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

do {
Event event = self->event_queue.pop(&self->event_queue);
Expand All @@ -50,7 +50,7 @@ static void Scheduler_pop_events_and_prepare(Scheduler *untyped_self, tag_t next
* @return lf_ret_t
*/
static lf_ret_t Scheduler_federated_acquire_tag(Scheduler *untyped_self, tag_t next_tag) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

LF_DEBUG(SCHED, "Acquiring tag %" PRId64 ":%" PRIu32, next_tag.time, next_tag.microstep);
Environment *env = self->env;
Expand Down Expand Up @@ -82,7 +82,7 @@ static lf_ret_t Scheduler_federated_acquire_tag(Scheduler *untyped_self, tag_t n
}

void Scheduler_register_for_cleanup(Scheduler *untyped_self, Trigger *trigger) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

LF_DEBUG(SCHED, "Registering trigger %p for cleanup", trigger);
if (trigger->is_registered_for_cleanup) {
Expand All @@ -101,15 +101,15 @@ void Scheduler_register_for_cleanup(Scheduler *untyped_self, Trigger *trigger) {
}

void Scheduler_prepare_timestep(Scheduler *untyped_self, tag_t tag) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

LF_DEBUG(SCHED, "Preparing timestep for tag %" PRId64 ":%" PRIu32, tag.time, tag.microstep);
self->current_tag = tag;
self->reaction_queue.reset(&self->reaction_queue);
}

void Scheduler_clean_up_timestep(Scheduler *untyped_self) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

assert(self->reaction_queue.empty(&self->reaction_queue));

Expand All @@ -132,7 +132,7 @@ void Scheduler_clean_up_timestep(Scheduler *untyped_self) {
}

void Scheduler_run_timestep(Scheduler *untyped_self) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

while (!self->reaction_queue.empty(&self->reaction_queue)) {
Reaction *reaction = self->reaction_queue.pop(&self->reaction_queue);
Expand All @@ -142,8 +142,8 @@ void Scheduler_run_timestep(Scheduler *untyped_self) {
}
}

void Scheduler_do_shutdown(Scheduler* untyped_self, tag_t shutdown_tag) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
void Scheduler_do_shutdown(Scheduler *untyped_self, tag_t shutdown_tag) {
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

LF_INFO(SCHED, "Scheduler terminating at tag %" PRId64 ":%" PRIu32, shutdown_tag.time, shutdown_tag.microstep);
Environment *env = self->env;
Expand All @@ -161,7 +161,7 @@ void Scheduler_do_shutdown(Scheduler* untyped_self, tag_t shutdown_tag) {
}

void Scheduler_schedule_startups(Scheduler *self, tag_t start_tag) {
Environment *env = ((DynamicScheduler*)self)->env;
Environment *env = ((DynamicScheduler *)self)->env;
if (env->startup) {
Event event = EVENT_INIT(start_tag, &env->startup->super, NULL);
self->schedule_at_locked(self, &event);
Expand All @@ -184,7 +184,7 @@ void Scheduler_schedule_timers(Scheduler *self, Reactor *reactor, tag_t start_ta
}

void Scheduler_acquire_and_schedule_start_tag(Scheduler *untyped_self) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

Environment *env = self->env;
env->enter_critical_section(env);
Expand Down Expand Up @@ -215,7 +215,7 @@ void Scheduler_acquire_and_schedule_start_tag(Scheduler *untyped_self) {
}

void Scheduler_run(Scheduler *untyped_self) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

Environment *env = self->env;
lf_ret_t res;
Expand Down Expand Up @@ -287,7 +287,7 @@ void Scheduler_run(Scheduler *untyped_self) {
}

lf_ret_t Scheduler_schedule_at_locked(Scheduler *untyped_self, Event *event) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

// Check if we are trying to schedule past stop tag
if (lf_tag_compare(event->tag, self->stop_tag) > 0) {
Expand All @@ -314,7 +314,7 @@ lf_ret_t Scheduler_schedule_at_locked(Scheduler *untyped_self, Event *event) {
}

lf_ret_t Scheduler_schedule_at(Scheduler *self, Event *event) {
Environment *env = ((DynamicScheduler*)self)->env;
Environment *env = ((DynamicScheduler *)self)->env;

env->enter_critical_section(env);

Expand All @@ -325,10 +325,10 @@ lf_ret_t Scheduler_schedule_at(Scheduler *self, Event *event) {
return res;
}

void Scheduler_set_duration(Scheduler *self, interval_t duration) { ((DynamicScheduler*)self)->duration = duration; }
void Scheduler_set_duration(Scheduler *self, interval_t duration) { ((DynamicScheduler *)self)->duration = duration; }

void Scheduler_request_shutdown(Scheduler *untyped_self) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

Environment *env = self->env;
env->enter_critical_section(env);
Expand All @@ -339,17 +339,15 @@ void Scheduler_request_shutdown(Scheduler *untyped_self) {
env->leave_critical_section(env);
}

lf_ret_t Scheduler_add_to_reaction_queue(Scheduler* untyped_self, Reaction* reaction) {
DynamicScheduler* self = (DynamicScheduler*)untyped_self;
lf_ret_t Scheduler_add_to_reaction_queue(Scheduler *untyped_self, Reaction *reaction) {
DynamicScheduler *self = (DynamicScheduler *)untyped_self;

return self->reaction_queue.insert(&self->reaction_queue, reaction);
}

tag_t Scheduler_current_tag(Scheduler* untyped_self) {
return ((DynamicScheduler*)untyped_self)->current_tag;
}
tag_t Scheduler_current_tag(Scheduler *untyped_self) { return ((DynamicScheduler *)untyped_self)->current_tag; }

void DynamicScheduler_ctor(DynamicScheduler* self, Environment *env) {
void DynamicScheduler_ctor(DynamicScheduler *self, Environment *env) {
self->env = env;

self->keep_alive = false;
Expand All @@ -371,7 +369,7 @@ void DynamicScheduler_ctor(DynamicScheduler* self, Environment *env) {
self->scheduler.register_for_cleanup = Scheduler_register_for_cleanup;
self->scheduler.request_shutdown = Scheduler_request_shutdown;
self->scheduler.acquire_and_schedule_start_tag = Scheduler_acquire_and_schedule_start_tag;
self->scheduler.set_duration = Scheduler_set_duration;
self->scheduler.set_duration = Scheduler_set_duration;
self->scheduler.add_to_reaction_queue = Scheduler_add_to_reaction_queue;
self->scheduler.current_tag = Scheduler_current_tag;

Expand Down
Loading

0 comments on commit 9a57000

Please sign in to comment.