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 size_t pos; // Current position in the priority queue. RUNTIME.
162 last_enabling_reaction; // The last enabling reaction, or NULL if there is none. Used for optimization. INSTANCE.
163 size_t num_outputs; // Number of outputs that may possibly be produced by this function. COMMON.
164 bool** output_produced; // Array of pointers to booleans indicating whether outputs were produced. COMMON.
165 int* triggered_sizes; // Pointer to array of ints with number of triggers per output. INSTANCE.
166 trigger_t*** triggers; // Array of pointers to arrays of pointers to triggers triggered by each output. INSTANCE.
167 reaction_status_t status; // Indicator of whether the reaction is inactive, queued, or running. RUNTIME.
168 interval_t deadline; // Deadline relative to the time stamp for invocation of the reaction. INSTANCE.
169 bool is_STP_violated; // Indicator of STP violation in one of the input triggers to this reaction. default = false.
170 // Value of True indicates to the runtime that this reaction contains trigger(s)
171 // that are triggered at a later logical time that was originally anticipated.
172 // Currently, this is only possible if logical
173 // connections are used in a decentralized federated
174 // execution. COMMON.
175 reaction_function_t deadline_violation_handler; // Deadline violation handler. COMMON.
176 reaction_function_t STP_handler; // STP handler. Invoked when a trigger to this reaction
177 // was triggered at a later logical time than originally
178 // intended. Currently, this is only possible if logical
179 // connections are used in a decentralized federated
180 // execution. COMMON.
181 bool is_an_input_reaction; // Indicates whether this reaction is a network input reaction of a federate. Default is
182 // false.
183 size_t worker_affinity; // The worker number of the thread that scheduled this reaction. Used
184 // as a suggestion to the scheduler.
185 const char* name; // If logging is set to LOG or higher, then this will
186 // point to the full name of the reactor followed by
187 // the reaction number.
188 reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
189 // If enclosed in multiple, this will point to the innermost mode.
190};
191
193typedef struct event_t event_t;
194
196struct event_t {
197 pqueue_tag_element_t base; // Elements of pqueue_tag. It contains tag of release and position in the priority queue.
198 trigger_t* trigger; // Associated trigger, NULL if this is a dummy event.
199 lf_token_t* token; // Pointer to the token wrapping the value.
200#ifdef FEDERATED
201 tag_t intended_tag; // The intended tag.
202#endif
203};
204
208struct trigger_t {
209 token_template_t tmplt; // Type and token information (template is a C++ keyword).
210 reaction_t** reactions; // Array of pointers to reactions sensitive to this trigger.
211 int number_of_reactions; // Number of reactions sensitive to this trigger.
212 bool is_timer; // True if this is a timer (a special kind of action), false otherwise.
213 interval_t offset; // Minimum delay of an action. For a timer, this is also the maximum delay.
214 interval_t period; // Minimum interarrival time of an action. For a timer, this is also the maximal interarrival time.
215 bool is_physical; // Indicator that this denotes a physical action.
216 tag_t last_tag; // Tag of the last event that was scheduled for this action.
217 // This is only used for actions and will otherwise be NEVER.
218 lf_spacing_policy_t policy; // Indicates which policy to use when an event is scheduled too early.
219 port_status_t status; // Determines the status of the port at the current logical time. Therefore, this
220 // value needs to be reset at the beginning of each logical time.
221 //
222 // This status is especially needed for the distributed execution because the receiver logic
223 // will need to know what it should do if it receives a message with 'intended tag = current
224 // tag' from another federate.
225 // - If status is 'unknown', it means that the federate has still no idea what the status of
226 // this port is and thus has refrained from executing any reaction that has that port as its
227 // input. This means that the receiver logic can directly inject the triggered reactions into
228 // the reaction queue at the current logical time.
229 // - If the status is absent, it means that the federate has assumed that the port is 'absent'
230 // for the current logical time. Therefore, receiving a message with 'intended tag = current
231 // tag' is an error that should be handled, for example, as a violation of the STP offset in
232 // the decentralized coordination.
233 // - Finally, if status is 'present', then this is an error since multiple
234 // downstream messages have been produced for the same port for the same logical time.
235 reactor_mode_t* mode; // The enclosing mode of this reaction (if exists).
236 // If enclosed in multiple, this will point to the innermost mode.
237#ifdef FEDERATED
238 tag_t last_known_status_tag; // Last known status of the port, either via a timed message, a port absent, or a
239 // TAG from the RTI.
240 tag_t intended_tag; // The amount of discrepency in logical time between the original intended
241 // trigger time of this trigger and the actual trigger time. This currently
242 // can only happen when logical connections are used using a decentralized coordination
243 // mechanism (@see https://github.com/icyphy/lingua-franca/wiki/Logical-Connections).
244 instant_t physical_time_of_arrival; // The physical time at which the message has been received on the network
245 // according to the local clock. Note: The physical_time_of_arrival is only passed
246 // down one level of the hierarchy. Default: NEVER.
247#endif
248};
249
261
263
276typedef struct self_base_t {
278 struct reaction_t* executing_reaction; // The currently executing reaction of the reactor.
280#if !defined(LF_SINGLE_THREADED)
281 void* reactor_mutex; // If not null, this is expected to point to an lf_mutex_t.
282 // It is not declared as such to avoid a dependence on platform.h.
283#endif
284#if defined(MODAL_REACTORS)
285 reactor_mode_state_t _lf__mode_state; // The current mode (for modal models).
286#endif
288
295typedef struct {
296 token_template_t tmplt; // Type and token information (template is a C++ keyword).
298 trigger_t* trigger; // THIS HAS TO MATCH lf_action_internal_t
302
309
314typedef struct {
315 lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record.
316 int destination_channel; // -1 if there is no destination.
317 int num_destinations; // The number of destination reactors this port writes to.
318 self_base_t* source_reactor; // Pointer to the self struct of the reactor that provides data to this port.
319 // If this is an input, that reactor will normally be the container of the
320 // output port that sends it data.
322
323#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:257
struct allocation_record_t * next
Definition lf_types.h:259
void * allocated
Definition lf_types.h:258
Execution environment. This struct contains information about the execution environment....
Definition environment.h:49
Definition lf_types.h:196
trigger_t * trigger
Definition lf_types.h:198
pqueue_tag_element_t base
Definition lf_types.h:197
lf_token_t * token
Definition lf_types.h:199
Definition lf_types.h:295
token_template_t tmplt
Definition lf_types.h:296
bool is_present
Definition lf_types.h:297
bool has_value
Definition lf_types.h:300
trigger_t * trigger
Definition lf_types.h:298
self_base_t * parent
Definition lf_types.h:299
Definition lf_types.h:306
trigger_t * trigger
Definition lf_types.h:307
Internal part of the port structs. HAS TO MATCH lf_port_base_t after tmplt and is_present.
Definition lf_types.h:314
self_base_t * source_reactor
Definition lf_types.h:318
int num_destinations
Definition lf_types.h:317
int destination_channel
Definition lf_types.h:316
lf_sparse_io_record_t * sparse_record
Definition lf_types.h:315
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
bool ** output_produced
Definition lf_types.h:164
bool is_STP_violated
Definition lf_types.h:169
reaction_status_t status
Definition lf_types.h:167
reaction_function_t deadline_violation_handler
Definition lf_types.h:175
void * self
Definition lf_types.h:157
const char * name
Definition lf_types.h:185
index_t index
Definition lf_types.h:159
trigger_t *** triggers
Definition lf_types.h:166
reaction_function_t STP_handler
Definition lf_types.h:176
size_t worker_affinity
Definition lf_types.h:183
int * triggered_sizes
Definition lf_types.h:165
interval_t deadline
Definition lf_types.h:168
size_t pos
Definition lf_types.h:160
bool is_an_input_reaction
Definition lf_types.h:181
int number
Definition lf_types.h:158
size_t num_outputs
Definition lf_types.h:163
reaction_t * last_enabling_reaction
Definition lf_types.h:162
reactor_mode_t * mode
Definition lf_types.h:188
reaction_function_t function
Definition lf_types.h:156
The base type for all reactor self structs.
Definition lf_types.h:276
struct reaction_t * executing_reaction
Definition lf_types.h:278
environment_t * environment
Definition lf_types.h:279
struct allocation_record_t * allocations
Definition lf_types.h:277
void * reactor_mutex
Definition lf_types.h:281
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:208
interval_t period
Definition lf_types.h:214
reaction_t ** reactions
Definition lf_types.h:210
int number_of_reactions
Definition lf_types.h:211
tag_t last_tag
Definition lf_types.h:216
bool is_timer
Definition lf_types.h:212
token_template_t tmplt
Definition lf_types.h:209
reactor_mode_t * mode
Definition lf_types.h:235
lf_spacing_policy_t policy
Definition lf_types.h:218
port_status_t status
Definition lf_types.h:219
bool is_physical
Definition lf_types.h:215
interval_t offset
Definition lf_types.h:213
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