Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 2
BreakConstructorInitializersBeforeComma: 'true'
PointerAlignment: Left
IncludeBlocks: Preserve
SortIncludes: false
ColumnLimit: 120
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
SortIncludes: false
26 changes: 13 additions & 13 deletions include/reactor-uc/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Action {
interval_t min_offset; // The minimum offset from the current time that an event can be scheduled on this action.
interval_t min_spacing; // The minimum spacing between two events scheduled on this action.
instant_t last_event_time; // Logical time of most recent event scheduled on this action.
void *value_ptr; // Pointer to the value associated with this action at the current logical tag.
void* value_ptr; // Pointer to the value associated with this action at the current logical tag.
TriggerEffects effects; // The reactions triggered by this Action.
TriggerSources sources; // The reactions that can write to this Action.
TriggerObservers observers; // The reactions that can observe this Action.
Expand All @@ -33,30 +33,30 @@ struct Action {
* @param offset The tag of the scheduled event will be the current tag plus the min_offset plus this offset.
* @param value A pointer to the value which should be scheduled with the event.
*/
lf_ret_t (*schedule)(Action *self, interval_t offset, const void *value);
lf_ret_t (*schedule)(Action* self, interval_t offset, const void* value);
};

void Action_ctor(Action *self, ActionType type, interval_t min_offset, interval_t min_spacing, Reactor *parent,
Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size, Reaction **observers,
size_t observers_size, void *value_ptr, size_t value_size, void *payload_buf, bool *payload_used_buf,
void Action_ctor(Action* self, ActionType type, interval_t min_offset, interval_t min_spacing, Reactor* parent,
Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size, Reaction** observers,
size_t observers_size, void* value_ptr, size_t value_size, void* payload_buf, bool* payload_used_buf,
size_t event_bound);

struct LogicalAction {
Action super;
};

void LogicalAction_ctor(LogicalAction *self, interval_t min_offset, interval_t min_spacing, Reactor *parent,
Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size,
Reaction **observers, size_t observers_size, void *value_ptr, size_t value_size,
void *payload_buf, bool *payload_used_buf, size_t event_bound);
void LogicalAction_ctor(LogicalAction* self, interval_t min_offset, interval_t min_spacing, Reactor* parent,
Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size,
Reaction** observers, size_t observers_size, void* value_ptr, size_t value_size,
void* payload_buf, bool* payload_used_buf, size_t event_bound);

struct PhysicalAction {
Action super;
MUTEX_T mutex;
};

void PhysicalAction_ctor(PhysicalAction *self, interval_t min_offset, interval_t min_spacing, Reactor *parent,
Reaction **sources, size_t sources_size, Reaction **effects, size_t effects_size,
Reaction **observers, size_t observers_size, void *value_ptr, size_t value_size,
void *payload_buf, bool *payload_used_buf, size_t event_bound);
void PhysicalAction_ctor(PhysicalAction* self, interval_t min_offset, interval_t min_spacing, Reactor* parent,
Reaction** sources, size_t sources_size, Reaction** effects, size_t effects_size,
Reaction** observers, size_t observers_size, void* value_ptr, size_t value_size,
void* payload_buf, bool* payload_used_buf, size_t event_bound);
#endif
6 changes: 3 additions & 3 deletions include/reactor-uc/builtin_triggers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ struct BuiltinTrigger {
Trigger super;
TriggerEffects effects;
TriggerObservers observers;
BuiltinTrigger *next;
BuiltinTrigger* next;
};

void BuiltinTrigger_ctor(BuiltinTrigger *self, TriggerType type, Reactor *parent, Reaction **effects,
size_t effects_size, Reaction **observers, size_t observers_size);
void BuiltinTrigger_ctor(BuiltinTrigger* self, TriggerType type, Reactor* parent, Reaction** effects,
size_t effects_size, Reaction** observers, size_t observers_size);

#endif
12 changes: 6 additions & 6 deletions include/reactor-uc/clock_synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ typedef struct {

struct ClockSynchronization {
SystemEventHandler super; // ClockSynchronization is a subclass of SystemEventHandler
Environment *env;
NeighborClock *neighbor_clock; // Pointer to an array of neighbor clocks, one for each neighbor.
Environment* env;
NeighborClock* neighbor_clock; // Pointer to an array of neighbor clocks, one for each neighbor.
size_t num_neighbours; // Number of neighbors, length of the neighbor_clock array.
bool is_grandmaster; // Whether this node is the grandmaster.
bool has_initial_sync; // Whether the initial sync has been completed.
Expand All @@ -55,12 +55,12 @@ struct ClockSynchronization {
interval_t period; // The period between sync request messages are sent to the neighbor master.
ClockSyncTimestamps timestamps; // The timestamps used to compute clock offset.
ClockServo servo; // The PID controller
void (*handle_message_callback)(ClockSynchronization *self, const ClockSyncMessage *msg, size_t bundle_idx);
void (*handle_message_callback)(ClockSynchronization* self, const ClockSyncMessage* msg, size_t bundle_idx);
};

void ClockSynchronization_ctor(ClockSynchronization *self, Environment *env, NeighborClock *neighbor_clock,
size_t num_neighbors, bool is_grandmaster, size_t payload_size, void *payload_buf,
bool *payload_used_buf, size_t payload_buf_capacity, interval_t period,
void ClockSynchronization_ctor(ClockSynchronization* self, Environment* env, NeighborClock* neighbor_clock,
size_t num_neighbors, bool is_grandmaster, size_t payload_size, void* payload_buf,
bool* payload_used_buf, size_t payload_buf_capacity, interval_t period,
interval_t max_adj, float servo_kp, float servo_ki);

#endif // REACTOR_UC_CLOCK_SYNCHRONIZATION_H
26 changes: 13 additions & 13 deletions include/reactor-uc/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ typedef enum { LOGICAL_CONNECTION, PHYSICAL_CONNECTION } ConnectionType;

struct Connection {
Trigger super;
Port *upstream; // Single upstream port
Port **downstreams; // Pointer to array of pointers of downstream ports
Port* upstream; // Single upstream port
Port** downstreams; // Pointer to array of pointers of downstream ports
size_t downstreams_size; // Size of downstreams array
size_t downstreams_registered; // Number of downstreams currently registered
void (*register_downstream)(Connection *, Port *);
Port *(*get_final_upstream)(Connection *);
void (*trigger_downstreams)(Connection *, const void *value_ptr, size_t value_size);
void (*register_downstream)(Connection*, Port*);
Port* (*get_final_upstream)(Connection*);
void (*trigger_downstreams)(Connection*, const void* value_ptr, size_t value_size);
};

void Connection_ctor(Connection *self, TriggerType type, Reactor *parent, Port **downstreams, size_t num_downstreams,
EventPayloadPool *payload_pool, void (*prepare)(Trigger *, Event *), void (*cleanup)(Trigger *),
void (*trigger_downstreams)(Connection *, const void *, size_t));
void Connection_ctor(Connection* self, TriggerType type, Reactor* parent, Port** downstreams, size_t num_downstreams,
EventPayloadPool* payload_pool, void (*prepare)(Trigger*, Event*), void (*cleanup)(Trigger*),
void (*trigger_downstreams)(Connection*, const void*, size_t));

struct LogicalConnection {
Connection super;
};

void LogicalConnection_ctor(LogicalConnection *self, Reactor *parent, Port **downstreams, size_t num_downstreams);
void LogicalConnection_ctor(LogicalConnection* self, Reactor* parent, Port** downstreams, size_t num_downstreams);

struct DelayedConnection {
Connection super;
interval_t delay;
ConnectionType type;
EventPayloadPool payload_pool;
void *staged_payload_ptr;
void* staged_payload_ptr;
};

void DelayedConnection_ctor(DelayedConnection *self, Reactor *parent, Port **downstreams, size_t num_downstreams,
interval_t delay, ConnectionType type, size_t payload_size, void *payload_buf,
bool *payload_used_buf, size_t payload_buf_capacity);
void DelayedConnection_ctor(DelayedConnection* self, Reactor* parent, Port** downstreams, size_t num_downstreams,
interval_t delay, ConnectionType type, size_t payload_size, void* payload_buf,
bool* payload_used_buf, size_t payload_buf_capacity);

#endif
6 changes: 3 additions & 3 deletions include/reactor-uc/coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ typedef struct Coordinator Coordinator;

struct Coordinator {
SystemEventHandler super;
Environment *env;
Environment* env;

void (*logical_tag_complete)(Coordinator *self, tag_t next_local_event_tag);
void (*handle_message_callback)(Coordinator *self, const void *msg, size_t bundle_idx);
void (*logical_tag_complete)(Coordinator* self, tag_t next_local_event_tag);
void (*handle_message_callback)(Coordinator* self, const void* msg, size_t bundle_idx);
};

#endif // REACTOR_UC_COORDINATOR_H
44 changes: 22 additions & 22 deletions include/reactor-uc/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@

typedef struct Platform Platform;
typedef struct Environment Environment;
extern Environment *_lf_environment; // NOLINT
extern Environment* _lf_environment; // NOLINT

struct Environment {
Reactor *main; // The top-level reactor of the program.
Scheduler *scheduler; // The scheduler in charge of executing the reactions.
Platform *platform;
Reactor* main; // The top-level reactor of the program.
Scheduler* scheduler; // The scheduler in charge of executing the reactions.
Platform* platform;
bool has_async_events; // Whether the program has multiple execution contexts and can receive async events and thus
// need critical sections.
bool fast_mode; // Whether the program is executing in fast mode where we do not wait for physical time to elapse
// before handling 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.
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.
/**
* @private
* @brief Assemble the program by computing levels for each reaction and setting up the scheduler.
*/
void (*assemble)(Environment *self);
void (*assemble)(Environment* self);

/**
* @private
* @brief Start the program.
*/
void (*start)(Environment *self);
void (*start)(Environment* self);

/**
* @private
Expand All @@ -50,15 +50,15 @@ struct Environment {
* This function must be called from a critical section.
*
*/
lf_ret_t (*wait_until)(Environment *self, instant_t wakeup_time);
lf_ret_t (*wait_until)(Environment* self, instant_t wakeup_time);

/**
* @brief Sleep for a duration.
* @param self The environment.
* @param wait_time The time duration to wait
*
*/
lf_ret_t (*wait_for)(Environment *self, interval_t wait_time);
lf_ret_t (*wait_for)(Environment* self, interval_t wait_time);

/**
* @brief Get the elapsed logical time since the start of the program.
Expand All @@ -69,7 +69,7 @@ struct Environment {

* @returns The elapsed logical time.
*/
interval_t (*get_elapsed_logical_time)(Environment *self);
interval_t (*get_elapsed_logical_time)(Environment* self);

/**
* @brief Get the current logical time of the program.AbstractEvent
Expand All @@ -79,7 +79,7 @@ struct Environment {
*
* @returns The current logical time.
*/
instant_t (*get_logical_time)(Environment *self);
instant_t (*get_logical_time)(Environment* self);

/**
* @brief Get the elapsed physical time since the start of the program.
Expand All @@ -90,7 +90,7 @@ struct Environment {
*
* @returns The elapsed physical time.
*/
interval_t (*get_elapsed_physical_time)(Environment *self);
interval_t (*get_elapsed_physical_time)(Environment* self);

/**
* @brief Get the current physical time.
Expand All @@ -101,7 +101,7 @@ struct Environment {
*
* @returns The current physical time.
*/
instant_t (*get_physical_time)(Environment *self);
instant_t (*get_physical_time)(Environment* self);

/**
* @brief Get the current lag.
Expand All @@ -111,7 +111,7 @@ struct Environment {
* current logical time. Deadlines are bounds on the release lag of a reaction.
*
*/
interval_t (*get_lag)(Environment *self);
interval_t (*get_lag)(Environment* self);

/**
* @brief Request the termination of the program.
Expand All @@ -122,7 +122,7 @@ struct Environment {
* If the program is not federated, then the shutdown will occur at the next microstep.
* If the program is federated, then the shutdown tag will be negotiated with the other federates.
*/
void (*request_shutdown)(Environment *self);
void (*request_shutdown)(Environment* self);

/**
* @private
Expand All @@ -134,7 +134,7 @@ struct Environment {
* In a federated setting, we might have to wait before doing this. We might
* wait for a STA offset or send out a coordination message to the upstream.
*/
lf_ret_t (*acquire_tag)(Environment *self, tag_t tag);
lf_ret_t (*acquire_tag)(Environment* self, tag_t tag);

/**
* @private
Expand All @@ -144,13 +144,13 @@ struct Environment {
* This function should only be supplied in a federated environment. It should
* poll all the PolledNetworkChannels that the federate has.
*/
lf_ret_t (*poll_network_channels)(Environment *self);
lf_ret_t (*poll_network_channels)(Environment* self);
};

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

void Environment_schedule_startups(const Environment *self, tag_t start_tag);
void Environment_schedule_timers(Environment *self, const Reactor *reactor, tag_t start_tag);
void Environment_schedule_startups(const Environment* self, tag_t start_tag);
void Environment_schedule_timers(Environment* self, const Reactor* reactor, tag_t start_tag);

#endif
16 changes: 8 additions & 8 deletions include/reactor-uc/environments/federated_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
#include "reactor-uc/physical_clock.h"

typedef struct FederatedEnvironment FederatedEnvironment;
extern Environment *_lf_environment; // NOLINT
extern Environment* _lf_environment; // NOLINT

struct FederatedEnvironment {
Environment super;
PhysicalClock clock; // The physical clock that provides the physical time.
bool do_clock_sync;
FederatedConnectionBundle **net_bundles; // A pointer to an array of NetworkChannel pointers that are used to
FederatedConnectionBundle** net_bundles; // A pointer to an array of NetworkChannel pointers that are used to
// communicate with other federates running in different environments.
size_t net_bundles_size; // The number of NetworkChannels in the net_channels array.
size_t federation_longest_path; // The longest path in the federation.
StartupCoordinator *startup_coordinator; // A pointer to the startup coordinator, if the program has one.
ClockSynchronization *clock_sync; // A pointer to the clock synchronization module, if the program has one.
StartupCoordinator* startup_coordinator; // A pointer to the startup coordinator, if the program has one.
ClockSynchronization* clock_sync; // A pointer to the clock synchronization module, if the program has one.
};

void FederatedEnvironment_ctor(FederatedEnvironment *self, Reactor *main, Scheduler *scheduler, bool fast_mode,
FederatedConnectionBundle **net_bundles, size_t net_bundles_size,
StartupCoordinator *startup_coordinator, ClockSynchronization *clock_sync);
void FederatedEnvironment_free(FederatedEnvironment *self);
void FederatedEnvironment_ctor(FederatedEnvironment* self, Reactor* main, Scheduler* scheduler, bool fast_mode,
FederatedConnectionBundle** net_bundles, size_t net_bundles_size,
StartupCoordinator* startup_coordinator, ClockSynchronization* clock_sync);
void FederatedEnvironment_free(FederatedEnvironment* self);

#endif
Loading
Loading