reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
lf_types.h
Go to the documentation of this file.
1
17#ifndef TYPES_H
18#define TYPES_H
19
20#include <stdbool.h>
21
22#include "modal_models/modes.h" // Modal model support
23#include "utils/pqueue.h"
24#include "utils/pqueue_tag.h"
25#include "lf_token.h"
26#include "tag.h"
27#include "vector.h"
28
35#ifndef _SYS_TYPES_H
36typedef unsigned short int ushort;
37#endif
38
47#define SCHED_ADAPTIVE 1
48#define SCHED_GEDF_NP 2
49#define SCHED_NP 3
50
51/*
52 * A struct representing a barrier in threaded
53 * Lingua Franca programs that can prevent advancement
54 * of tag if
55 * 1- Number of requestors is larger than 0
56 * 2- Value of horizon is not (FOREVER, 0)
57 */
59 int requestors; // Used to indicate the number of
60 // requestors that have asked
61 // for a barrier to be raised
62 // on tag.
63 tag_t horizon; // If semaphore is larger than 0
64 // then the runtime should not
65 // advance its tag beyond the
66 // horizon.
68
82
95typedef enum { absent = false, present = true, unknown } port_status_t;
96
110
118
125#ifndef string
126typedef char* string;
127#else
128#warning "string typedef has been previously given."
129#endif
130
133
139typedef void (*reaction_function_t)(void*);
140
142typedef struct trigger_t trigger_t;
143
154typedef struct reaction_t reaction_t;
156 reaction_function_t function; // The reaction function. COMMON.
157 void* self; // Pointer to a struct with the reactor's state. INSTANCE.
158 int number; // The number of the reaction in the reactor (0 is the first reaction).
159 index_t index; // Inverse priority determined by dependency analysis. INSTANCE.
160 // Binary encoding of the branches that this reaction has upstream in the dependency graph. INSTANCE.
161 unsigned long long chain_id;
162 size_t pos; // Current position in the priority queue. RUNTIME.
164 last_enabling_reaction; // The last enabling reaction, or NULL if there is none. Used for optimization. INSTANCE.
165 size_t num_outputs; // Number of outputs that may possibly be produced by this function. COMMON.
166 bool** output_produced; // Array of pointers to booleans indicating whether outputs were produced. COMMON.
167 int* triggered_sizes; // Pointer to array of ints with number of triggers per output. INSTANCE.
168 trigger_t*** triggers; // Array of pointers to arrays of pointers to triggers triggered by each output. INSTANCE.
169 reaction_status_t status; // Indicator of whether the reaction is inactive, queued, or running. RUNTIME.
170 interval_t deadline; // Deadline relative to the time stamp for invocation of the reaction. INSTANCE.
171 bool is_STP_violated; // Indicator of STP violation in one of the input triggers to this reaction. default = false.
172 // Value of True indicates to the runtime that this reaction contains trigger(s)
173 // that are triggered at a later logical time that was originally anticipated.
174 // Currently, this is only possible if logical
175 // connections are used in a decentralized federated
176 // execution. COMMON.
177 reaction_function_t deadline_violation_handler; // Deadline violation handler. COMMON.
178 reaction_function_t STP_handler; // STP handler. Invoked when a trigger to this reaction
179 // was triggered at a later logical time than originally
180 // intended. Currently, this is only possible if logical
181 // connections are used in a decentralized federated
182 // execution. COMMON.
183 bool is_an_input_reaction; // Indicates whether this reaction is a network input reaction of a federate. Default is
184 // false.
185 size_t worker_affinity; // The worker number of the thread that scheduled this reaction. Used
186 // as a suggestion to the scheduler.
187 const char* name; // If logging is set to LOG or higher, then this will
188 // point to the full name of the reactor followed by
189 // the reaction number.
190 reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
191 // If enclosed in multiple, this will point to the innermost mode.
192};
193
195typedef struct event_t event_t;
196
198struct event_t {
199 pqueue_tag_element_t base; // Elements of pqueue_tag. It contains tag of release and position in the priority queue.
200 trigger_t* trigger; // Associated trigger, NULL if this is a dummy event.
201 lf_token_t* token; // Pointer to the token wrapping the value.
202#ifdef FEDERATED
203 tag_t intended_tag; // The intended tag.
204#endif
205};
206
210struct trigger_t {
211 token_template_t tmplt; // Type and token information (template is a C++ keyword).
212 reaction_t** reactions; // Array of pointers to reactions sensitive to this trigger.
213 int number_of_reactions; // Number of reactions sensitive to this trigger.
214 bool is_timer; // True if this is a timer (a special kind of action), false otherwise.
215 interval_t offset; // Minimum delay of an action. For a timer, this is also the maximum delay.
216 interval_t period; // Minimum interarrival time of an action. For a timer, this is also the maximal interarrival time.
217 bool is_physical; // Indicator that this denotes a physical action.
218 tag_t last_tag; // Tag of the last event that was scheduled for this action.
219 // This is only used for actions and will otherwise be NEVER.
220 lf_spacing_policy_t policy; // Indicates which policy to use when an event is scheduled too early.
221 port_status_t status; // Determines the status of the port at the current logical time. Therefore, this
222 // value needs to be reset at the beginning of each logical time.
223 //
224 // This status is especially needed for the distributed execution because the receiver logic
225 // will need to know what it should do if it receives a message with 'intended tag = current
226 // tag' from another federate.
227 // - If status is 'unknown', it means that the federate has still no idea what the status of
228 // this port is and thus has refrained from executing any reaction that has that port as its
229 // input. This means that the receiver logic can directly inject the triggered reactions into
230 // the reaction queue at the current logical time.
231 // - If the status is absent, it means that the federate has assumed that the port is 'absent'
232 // for the current logical time. Therefore, receiving a message with 'intended tag = current
233 // tag' is an error that should be handled, for example, as a violation of the STP offset in
234 // the decentralized coordination.
235 // - Finally, if status is 'present', then this is an error since multiple
236 // downstream messages have been produced for the same port for the same logical time.
237 reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
238 // If enclosed in multiple, this will point to the innermost mode.
239#ifdef FEDERATED
240 tag_t last_known_status_tag; // Last known status of the port, either via a timed message, a port absent, or a
241 // TAG from the RTI.
242 tag_t intended_tag; // The amount of discrepency in logical time between the original intended
243 // trigger time of this trigger and the actual trigger time. This currently
244 // can only happen when logical connections are used using a decentralized coordination
245 // mechanism (@see https://github.com/icyphy/lingua-franca/wiki/Logical-Connections).
246 instant_t physical_time_of_arrival; // The physical time at which the message has been received on the network
247 // according to the local clock. Note: The physical_time_of_arrival is only passed
248 // down one level of the hierarchy. Default: NEVER.
249#endif
250};
251
263
265
278typedef struct self_base_t {
280 struct reaction_t* executing_reaction; // The currently executing reaction of the reactor.
282#if !defined(LF_SINGLE_THREADED)
283 void* reactor_mutex; // If not null, this is expected to point to an lf_mutex_t.
284 // It is not declared as such to avoid a dependence on platform.h.
285#endif
286#if defined(MODAL_REACTORS)
287 reactor_mode_state_t _lf__mode_state; // The current mode (for modal models).
288#endif
290
297typedef struct {
298 token_template_t tmplt; // Type and token information (template is a C++ keyword).
300 trigger_t* trigger; // THIS HAS TO MATCH lf_action_internal_t
304
311
316typedef struct {
317 lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record.
318 int destination_channel; // -1 if there is no destination.
319 int num_destinations; // The number of destination reactors this port writes to.
320 self_base_t* source_reactor; // Pointer to the self struct of the reactor that provides data to this port.
321 // If this is an input, that reactor will normally be the container of the
322 // output port that sends it data.
324
325#endif
Definitions for token objects, reference-counted wrappers around dynamically-allocated messages.
lf_spacing_policy_t
Definition lf_types.h:81
@ drop
Definition lf_types.h:81
@ defer
Definition lf_types.h:81
@ replace
Definition lf_types.h:81
void(* reaction_function_t)(void *)
Definition lf_types.h:139
int trigger_handle_t
Definition lf_types.h:117
unsigned short int ushort
Definition lf_types.h:36
struct allocation_record_t allocation_record_t
pqueue_pri_t index_t
Definition lf_types.h:132
char * string
Definition lf_types.h:126
struct self_base_t self_base_t
The base type for all reactor self structs.
reaction_status_t
Definition lf_types.h:109
@ inactive
Definition lf_types.h:109
@ queued
Definition lf_types.h:109
@ running
Definition lf_types.h:109
port_status_t
Definition lf_types.h:95
@ absent
Definition lf_types.h:95
@ unknown
Definition lf_types.h:95
@ present
Definition lf_types.h:95
struct _lf_tag_advancement_barrier _lf_tag_advancement_barrier
void reactor_mode_t
Definition modes.h:142
Priority queue definitions for queues where the priority is a number that can be compared with ordina...
unsigned long long pqueue_pri_t
Definition pqueue_base.h:52
Priority queue that uses tags for sorting.
Definition lf_types.h:58
int requestors
Definition lf_types.h:59
tag_t horizon
Definition lf_types.h:63
Definition lf_types.h:259
struct allocation_record_t * next
Definition lf_types.h:261
void * allocated
Definition lf_types.h:260
Execution environment. This struct contains information about the execution environment....
Definition environment.h:69
Definition lf_types.h:198
trigger_t * trigger
Definition lf_types.h:200
pqueue_tag_element_t base
Definition lf_types.h:199
lf_token_t * token
Definition lf_types.h:201
Definition lf_types.h:297
token_template_t tmplt
Definition lf_types.h:298
bool is_present
Definition lf_types.h:299
bool has_value
Definition lf_types.h:302
trigger_t * trigger
Definition lf_types.h:300
self_base_t * parent
Definition lf_types.h:301
Definition lf_types.h:308
trigger_t * trigger
Definition lf_types.h:309
Internal part of the port structs. HAS TO MATCH lf_port_base_t after tmplt and is_present.
Definition lf_types.h:316
self_base_t * source_reactor
Definition lf_types.h:320
int num_destinations
Definition lf_types.h:319
int destination_channel
Definition lf_types.h:318
lf_sparse_io_record_t * sparse_record
Definition lf_types.h:317
Definition lf_token.h:110
Definition lf_token.h:94
The type for an element in a priority queue that is sorted by tag.
Definition pqueue_tag.h:52
Definition lf_types.h:155
unsigned long long chain_id
Definition lf_types.h:161
bool ** output_produced
Definition lf_types.h:166
bool is_STP_violated
Definition lf_types.h:171
reaction_status_t status
Definition lf_types.h:169
reaction_function_t deadline_violation_handler
Definition lf_types.h:177
void * self
Definition lf_types.h:157
const char * name
Definition lf_types.h:187
index_t index
Definition lf_types.h:159
trigger_t *** triggers
Definition lf_types.h:168
reaction_function_t STP_handler
Definition lf_types.h:178
size_t worker_affinity
Definition lf_types.h:185
int * triggered_sizes
Definition lf_types.h:167
interval_t deadline
Definition lf_types.h:170
size_t pos
Definition lf_types.h:162
bool is_an_input_reaction
Definition lf_types.h:183
int number
Definition lf_types.h:158
size_t num_outputs
Definition lf_types.h:165
reaction_t * last_enabling_reaction
Definition lf_types.h:164
reactor_mode_t * mode
Definition lf_types.h:190
reaction_function_t function
Definition lf_types.h:156
The base type for all reactor self structs.
Definition lf_types.h:278
struct reaction_t * executing_reaction
Definition lf_types.h:280
environment_t * environment
Definition lf_types.h:281
struct allocation_record_t * allocations
Definition lf_types.h:279
void * reactor_mutex
Definition lf_types.h:283
Definition tag.h:81
Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens....
Definition lf_token.h:121
Definition lf_types.h:210
interval_t period
Definition lf_types.h:216
reaction_t ** reactions
Definition lf_types.h:212
int number_of_reactions
Definition lf_types.h:213
tag_t last_tag
Definition lf_types.h:218
bool is_timer
Definition lf_types.h:214
token_template_t tmplt
Definition lf_types.h:211
reactor_mode_t * mode
Definition lf_types.h:237
lf_spacing_policy_t policy
Definition lf_types.h:220
port_status_t status
Definition lf_types.h:221
bool is_physical
Definition lf_types.h:217
interval_t offset
Definition lf_types.h:215
Time and tag definitions and functions for Lingua Franca.
int64_t instant_t
Definition tag.h:66
int64_t interval_t
Definition tag.h:71