reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
reactor_common.h
Go to the documentation of this file.
1
19
20#ifndef REACTOR_COMMON_H
21#define REACTOR_COMMON_H
22
23#include "lf_types.h"
24#include "environment.h"
25#include "tag.h"
26#include "pqueue.h"
27#include "vector.h"
28#include "util.h"
29#include "modes.h"
30#include "port.h"
31
33
46
55typedef struct {
56 const char* name;
58 void* value;
59 bool* given;
60 const char* description;
61 bool is_width;
63
65extern int _lf_cli_params_count;
66
68
81#define MIN_SLEEP_DURATION USEC(10)
82
84
85// The following variables are defined in reactor_common.c and used in reactor.c,
86// reactor_threaded.c, modes.c, and by the code generator.
87extern bool _lf_normal_termination;
88extern unsigned int _lf_number_of_workers;
89extern int default_argc;
90extern const char** default_argv;
91extern instant_t duration;
92extern bool fast;
93extern bool keepalive_specified;
94
95#ifdef FEDERATED_DECENTRALIZED
97#endif
98
99// The following is defined by the code generator.
101
103
114
122
132void lf_free(struct allocation_record_t** head);
133
143
153
163
169
178
190
197
206void termination(void);
207
219void _lf_trigger_reaction(environment_t* env, reaction_t* reaction, int worker_number);
220
235
245
253
261
273
303
318
335trigger_handle_t _lf_schedule_copy(environment_t* env, void* action, interval_t offset, void* value, size_t length);
336
348
360
371
380void _lf_invoke_reaction(environment_t* env, reaction_t* reaction, int worker);
381
390void schedule_output_reactions(environment_t* env, reaction_t* reaction, int worker);
391
399int process_args(int argc, const char* argv[]);
400
415int process_user_args(int argc, const char* argv[], int* newargc, const char** newargv);
416
424void usage(int argc, const char* argv[]);
425
432
433#endif
API for the environment data structure.
int64_t instant_t
Time instant.
Definition tag.h:101
int64_t interval_t
Interval of time.
Definition tag.h:107
int process_user_args(int argc, const char *argv[], int *newargc, const char **newargv)
Process user-defined main reactor parameters from the command line.
void lf_recycle_event(environment_t *env, event_t *e)
Recycle the given event.
void _lf_trigger_shutdown_reactions(environment_t *env)
Trigger all the shutdown reactions in the specified environment.
void lf_set_default_command_line_options(void)
Generated function that optionally sets default command-line options.
int trigger_handle_t
Handles for scheduled triggers.
Definition lf_types.h:146
bool _lf_initialize_timers(environment_t *env)
Initialize all the timers in the environment.
void lf_replace_token(event_t *event, lf_token_t *token)
Replace the token on the specified event with the specified token and free the old token.
void _lf_pop_events(environment_t *env)
Pop all events from event_q with tag equal to current tag.
void initialize_global()
Initialize global variables and start tracing before calling the _lf_initialize_trigger_objects() fun...
pqueue_pri_t index_t
Topological order index for reactions.
Definition lf_types.h:166
void _lf_advance_tag(environment_t *env, tag_t next_tag)
Advance from the current tag to the next.
void _lf_initialize_trigger_objects()
Generated function that produces a table containing all triggers (i.e., inputs, timers,...
bool _lf_initialize_timer(environment_t *env, trigger_t *timer)
Initialize the given timer.
event_t * _lf_create_dummy_events(environment_t *env, tag_t tag)
Create a dummy event with the specified tag.
index_t lf_combine_deadline_and_level(interval_t deadline, int level)
Combine a deadline and a level into a single index for sorting in the reaction queue.
trigger_handle_t _lf_schedule_token(environment_t *env, void *action, interval_t extra_delay, lf_token_t *token)
Schedule the specified action at a later tag with the specified token as a payload.
void _lf_invoke_reaction(environment_t *env, reaction_t *reaction, int worker)
Invoke the specified reaction on the specified worker in the specified environment.
int process_args(int argc, const char *argv[])
Process the command-line arguments.
trigger_handle_t _lf_schedule_at_tag(environment_t *env, trigger_t *trigger, tag_t tag, lf_token_t *token)
Schedule an event at a specific tag (time, microstep).
void lf_free(struct allocation_record_t **head)
Free memory on the specified allocation record (a self struct).
void termination(void)
Perform final wrap-up on exit.
void _lf_start_time_step(environment_t *env)
Perform whatever is needed to start a time step.
lf_cli_type_t
Type tag for a user-defined CLI parameter.
Definition reactor_common.h:38
void lf_terminate_execution(environment_t *env)
Function that is called when the program is about to exit.
void schedule_output_reactions(environment_t *env, reaction_t *reaction, int worker)
Schedule the output reactions for the specified reaction in the specified environment.
trigger_handle_t _lf_insert_reactions_for_trigger(environment_t *env, trigger_t *trigger, lf_token_t *token)
Insert reactions triggered by trigger to the reaction queue.
event_t * lf_get_new_event(environment_t *env)
Get a new event.
void lf_create_environments(void)
Create and initialize the required number of environments for the program.
trigger_handle_t _lf_schedule_copy(environment_t *env, void *action, interval_t offset, void *value, size_t length)
Schedule an action to occur with the specified value and time offset with a copy of the specified val...
void _lf_trigger_reaction(environment_t *env, reaction_t *reaction, int worker_number)
Trigger the specified reaction on the specified worker in the specified environment.
void _lf_trigger_startup_reactions(environment_t *env)
Trigger all the startup reactions in the specified environment.
@ CLI_TIME
interval_t, parsed as value + units (e.g., "500 msec").
Definition reactor_common.h:39
@ CLI_STRING
const char*, set directly from the argument string.
Definition reactor_common.h:44
@ CLI_INT
int, parsed with atoi.
Definition reactor_common.h:40
@ CLI_DOUBLE
double, parsed with strtod.
Definition reactor_common.h:41
@ CLI_BOOL
bool, parsed as "true"/"false" or "1"/"0".
Definition reactor_common.h:43
@ CLI_FLOAT
float, parsed with strtof.
Definition reactor_common.h:42
void usage()
Print a usage message.
Type definitions that are widely used across different parts of the runtime.
Header file of the runtime infrastructure for modes in the C target of Lingua Franca.
Support for optimizing sparse input through multiports.
Priority queue definitions for queues where the priority is a number that can be compared with ordina...
unsigned int _lf_number_of_workers
interval_t lf_fed_STA_offset
bool _lf_normal_termination
bool keepalive_specified
instant_t duration
bool fast
int default_argc
lf_cli_param_t * _lf_cli_params
int _lf_cli_params_count
const char ** default_argv
struct allocation_record_t * _lf_reactors_to_free
Allocation record to keep track of dynamically-allocated memory.
Definition lf_types.h:499
Execution environment.
Definition environment.h:52
Event activation record to push onto the event queue.
Definition lf_types.h:354
Descriptor for a user-defined main reactor parameter overridable from the command line.
Definition reactor_common.h:55
const char * name
Parameter name (e.g., "period").
Definition reactor_common.h:56
bool is_width
True if this parameter is used for multiport/bank widths (not overridable).
Definition reactor_common.h:61
bool * given
Pointer to a bool that is set to true when the arg is provided.
Definition reactor_common.h:59
lf_cli_type_t type
The type of the parameter value.
Definition reactor_common.h:57
void * value
Pointer to the storage variable.
Definition reactor_common.h:58
const char * description
Description for the help message (e.g., "time value (default: 1 sec)").
Definition reactor_common.h:60
Token type for dynamically allocated arrays and structs sent as messages.
Definition lf_token.h:99
Reaction activation record to push onto the reaction queue.
Definition lf_types.h:195
A tag is a time, microstep pair.
Definition tag.h:119
Trigger struct representing an output, timer, action, or input.
Definition lf_types.h:391
Time and tag definitions and functions for Lingua Franca.
Core utility functions for Lingua Franca.