reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
lf_types.h
Go to the documentation of this file.
1
41#ifndef TYPES_H
42#define TYPES_H
43
44#include <stdbool.h>
45
46#include "modal_models/modes.h" // Modal model support
47#include "utils/pqueue.h"
48#include "lf_token.h"
49#include "tag.h"
50#include "vector.h"
51
58#ifndef _SYS_TYPES_H
59typedef unsigned short int ushort;
60#endif
61
70#define SCHED_ADAPTIVE 1
71#define SCHED_GEDF_NP 2
72#define SCHED_NP 3
73
74/*
75 * A struct representing a barrier in threaded
76 * Lingua Franca programs that can prevent advancement
77 * of tag if
78 * 1- Number of requestors is larger than 0
79 * 2- Value of horizon is not (FOREVER, 0)
80 */
82 int requestors; // Used to indicate the number of
83 // requestors that have asked
84 // for a barrier to be raised
85 // on tag.
86 tag_t horizon; // If semaphore is larger than 0
87 // then the runtime should not
88 // advance its tag beyond the
89 // horizon.
91
105
118typedef enum {absent = false, present = true, unknown} port_status_t;
119
133
141
148#ifndef string
149typedef char* string;
150#else
151#warning "string typedef has been previously given."
152#endif
153
156
162typedef void(*reaction_function_t)(void*);
163
165typedef struct trigger_t trigger_t;
166
177typedef struct reaction_t reaction_t;
179 reaction_function_t function; // The reaction function. COMMON.
180 void* self; // Pointer to a struct with the reactor's state. INSTANCE.
181 int number; // The number of the reaction in the reactor (0 is the first reaction).
182 index_t index; // Inverse priority determined by dependency analysis. INSTANCE.
183 // Binary encoding of the branches that this reaction has upstream in the dependency graph. INSTANCE.
184 unsigned long long chain_id;
185 size_t pos; // Current position in the priority queue. RUNTIME.
186 reaction_t* last_enabling_reaction; // The last enabling reaction, or NULL if there is none. Used for optimization. INSTANCE.
187 size_t num_outputs; // Number of outputs that may possibly be produced by this function. COMMON.
188 bool** output_produced; // Array of pointers to booleans indicating whether outputs were produced. COMMON.
189 int* triggered_sizes; // Pointer to array of ints with number of triggers per output. INSTANCE.
190 trigger_t ***triggers; // Array of pointers to arrays of pointers to triggers triggered by each output. INSTANCE.
191 reaction_status_t status; // Indicator of whether the reaction is inactive, queued, or running. RUNTIME.
192 interval_t deadline; // Deadline relative to the time stamp for invocation of the reaction. INSTANCE.
193 bool is_STP_violated; // Indicator of STP violation in one of the input triggers to this reaction. default = false.
194 // Value of True indicates to the runtime that this reaction contains trigger(s)
195 // that are triggered at a later logical time that was originally anticipated.
196 // Currently, this is only possible if logical
197 // connections are used in a decentralized federated
198 // execution. COMMON.
199 reaction_function_t deadline_violation_handler; // Deadline violation handler. COMMON.
200 reaction_function_t STP_handler; // STP handler. Invoked when a trigger to this reaction
201 // was triggered at a later logical time than originally
202 // intended. Currently, this is only possible if logical
203 // connections are used in a decentralized federated
204 // execution. COMMON.
205 bool is_an_input_reaction; // Indicates whether this reaction is a network input reaction of a federate. Default is false.
206 size_t worker_affinity; // The worker number of the thread that scheduled this reaction. Used
207 // as a suggestion to the scheduler.
208 const char* name; // If logging is set to LOG or higher, then this will
209 // point to the full name of the reactor followed by
210 // the reaction number.
211 reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
212 // If enclosed in multiple, this will point to the innermost mode.
213};
214
216typedef struct event_t event_t;
217
219struct event_t {
220 instant_t time; // Time of release.
221 trigger_t* trigger; // Associated trigger, NULL if this is a dummy event.
222 size_t pos; // Position in the priority queue.
223 lf_token_t* token; // Pointer to the token wrapping the value.
224 bool is_dummy; // Flag to indicate whether this event is merely a placeholder or an actual event.
225#ifdef FEDERATED
226 tag_t intended_tag; // The intended tag.
227#endif
228 event_t* next; // Pointer to the next event lined up in superdense time.
229};
230
234struct trigger_t {
235 token_template_t tmplt; // Type and token information (template is a C++ keyword).
236 reaction_t** reactions; // Array of pointers to reactions sensitive to this trigger.
237 int number_of_reactions; // Number of reactions sensitive to this trigger.
238 bool is_timer; // True if this is a timer (a special kind of action), false otherwise.
239 interval_t offset; // Minimum delay of an action. For a timer, this is also the maximum delay.
240 interval_t period; // Minimum interarrival time of an action. For a timer, this is also the maximal interarrival time.
241 bool is_physical; // Indicator that this denotes a physical action.
242 event_t* last; // Pointer to the last event that was scheduled for this action.
243 lf_spacing_policy_t policy; // Indicates which policy to use when an event is scheduled too early.
244 port_status_t status; // Determines the status of the port at the current logical time. Therefore, this
245 // value needs to be reset at the beginning of each logical time.
246 //
247 // This status is especially needed for the distributed execution because the receiver logic will need
248 // to know what it should do if it receives a message with 'intended tag = current tag' from another
249 // federate.
250 // - If status is 'unknown', it means that the federate has still no idea what the status of
251 // this port is and thus has refrained from executing any reaction that has that port as its input.
252 // This means that the receiver logic can directly inject the triggered reactions into the reaction
253 // queue at the current logical time.
254 // - If the status is absent, it means that the federate has assumed that the port is 'absent'
255 // for the current logical time. Therefore, receiving a message with 'intended tag = current tag'
256 // is an error that should be handled, for example, as a violation of the STP offset in the decentralized
257 // coordination.
258 // - Finally, if status is 'present', then this is an error since multiple
259 // downstream messages have been produced for the same port for the same logical time.
260 reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
261 // If enclosed in multiple, this will point to the innermost mode.
262#ifdef FEDERATED
263 tag_t last_known_status_tag; // Last known status of the port, either via a timed message, a port absent, or a
264 // TAG from the RTI.
265 tag_t intended_tag; // The amount of discrepency in logical time between the original intended
266 // trigger time of this trigger and the actual trigger time. This currently
267 // can only happen when logical connections are used using a decentralized coordination
268 // mechanism (@see https://github.com/icyphy/lingua-franca/wiki/Logical-Connections).
269 instant_t physical_time_of_arrival; // The physical time at which the message has been received on the network according to the local clock.
270 // Note: The physical_time_of_arrival is only passed down one level of the hierarchy. Default: NEVER.
271#endif
272};
273
285
286
297typedef struct self_base_t {
299 struct reaction_t *executing_reaction; // The currently executing reaction of the reactor.
301#if !defined(LF_SINGLE_THREADED)
302 void* reactor_mutex; // If not null, this is expected to point to an lf_mutex_t.
303 // It is not declared as such to avoid a dependence on platform.h.
304#endif
305#if defined(MODAL_REACTORS)
306 reactor_mode_state_t _lf__mode_state; // The current mode (for modal models).
307#endif
309
316typedef struct {
317 token_template_t tmplt; // Type and token information (template is a C++ keyword).
319 trigger_t* trigger; // THIS HAS TO MATCH lf_action_internal_t
323
330
335typedef struct {
336 lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record.
337 int destination_channel; // -1 if there is no destination.
338 int num_destinations; // The number of destination reactors this port writes to.
339 self_base_t* source_reactor; // Pointer to the self struct of the reactor that provides data to this port.
340 // If this is an input, that reactor will normally be the container of the
341 // output port that sends it data.
343
344#endif
lf_spacing_policy_t
Definition lf_types.h:104
@ drop
Definition lf_types.h:104
@ defer
Definition lf_types.h:104
@ replace
Definition lf_types.h:104
void(* reaction_function_t)(void *)
Definition lf_types.h:162
int trigger_handle_t
Definition lf_types.h:140
unsigned short int ushort
Definition lf_types.h:59
pqueue_pri_t index_t
Definition lf_types.h:155
char * string
Definition lf_types.h:149
reaction_status_t
Definition lf_types.h:132
@ inactive
Definition lf_types.h:132
@ queued
Definition lf_types.h:132
@ running
Definition lf_types.h:132
port_status_t
Definition lf_types.h:118
@ absent
Definition lf_types.h:118
@ unknown
Definition lf_types.h:118
@ present
Definition lf_types.h:118
void reactor_mode_t
Definition modes.h:167
Priority queue declarations for the event queue and reaction queue.
unsigned long long pqueue_pri_t
Definition pqueue_base.h:45
Definition lf_types.h:81
int requestors
Definition lf_types.h:82
tag_t horizon
Definition lf_types.h:86
Definition lf_types.h:281
struct allocation_record_t * next
Definition lf_types.h:283
void * allocated
Definition lf_types.h:282
Execution environment. This struct contains information about the execution environment....
Definition environment.h:68
Definition lf_types.h:219
trigger_t * trigger
Definition lf_types.h:221
bool is_dummy
Definition lf_types.h:224
event_t * next
Definition lf_types.h:228
size_t pos
Definition lf_types.h:222
lf_token_t * token
Definition lf_types.h:223
instant_t time
Definition lf_types.h:220
Definition lf_types.h:316
token_template_t tmplt
Definition lf_types.h:317
bool is_present
Definition lf_types.h:318
bool has_value
Definition lf_types.h:321
trigger_t * trigger
Definition lf_types.h:319
self_base_t * parent
Definition lf_types.h:320
Definition lf_types.h:327
trigger_t * trigger
Definition lf_types.h:328
Internal part of the port structs. HAS TO MATCH lf_port_base_t after tmplt and is_present.
Definition lf_types.h:335
self_base_t * source_reactor
Definition lf_types.h:339
int num_destinations
Definition lf_types.h:338
int destination_channel
Definition lf_types.h:337
lf_sparse_io_record_t * sparse_record
Definition lf_types.h:336
Definition lf_token.h:132
Definition lf_token.h:116
Definition lf_types.h:178
unsigned long long chain_id
Definition lf_types.h:184
bool ** output_produced
Definition lf_types.h:188
bool is_STP_violated
Definition lf_types.h:193
reaction_status_t status
Definition lf_types.h:191
reaction_function_t deadline_violation_handler
Definition lf_types.h:199
void * self
Definition lf_types.h:180
const char * name
Definition lf_types.h:208
index_t index
Definition lf_types.h:182
trigger_t *** triggers
Definition lf_types.h:190
reaction_function_t STP_handler
Definition lf_types.h:200
size_t worker_affinity
Definition lf_types.h:206
int * triggered_sizes
Definition lf_types.h:189
interval_t deadline
Definition lf_types.h:192
size_t pos
Definition lf_types.h:185
bool is_an_input_reaction
Definition lf_types.h:205
int number
Definition lf_types.h:181
size_t num_outputs
Definition lf_types.h:187
reaction_t * last_enabling_reaction
Definition lf_types.h:186
reactor_mode_t * mode
Definition lf_types.h:211
reaction_function_t function
Definition lf_types.h:179
Definition lf_types.h:297
struct reaction_t * executing_reaction
Definition lf_types.h:299
environment_t * environment
Definition lf_types.h:300
struct allocation_record_t * allocations
Definition lf_types.h:298
void * reactor_mutex
Definition lf_types.h:302
Definition tag.h:73
Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens....
Definition lf_token.h:143
Definition lf_types.h:234
interval_t period
Definition lf_types.h:240
reaction_t ** reactions
Definition lf_types.h:236
int number_of_reactions
Definition lf_types.h:237
bool is_timer
Definition lf_types.h:238
token_template_t tmplt
Definition lf_types.h:235
event_t * last
Definition lf_types.h:242
reactor_mode_t * mode
Definition lf_types.h:260
lf_spacing_policy_t policy
Definition lf_types.h:243
port_status_t status
Definition lf_types.h:244
bool is_physical
Definition lf_types.h:241
interval_t offset
Definition lf_types.h:239
Time and tag definitions and functions for Lingua Franca.
int64_t instant_t
Definition tag.h:58
int64_t interval_t
Definition tag.h:63