reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
Internal

API mainly used internally, but occasionally useful for users. More...

Files

file  environment.h
 API for the environment data structure.
file  lf_semaphore.h
 Semaphore utility for reactor C.
file  lf_token.h
 Definitions for token objects, reference-counted wrappers around dynamically-allocated messages.
file  lf_types.h
 Type definitions that are widely used across different parts of the runtime.
file  logging_macros.h
 Logging macros for the logging API.
file  mixed_radix.h
 Header file for permuted mixed-radix numbers used in Lingua Franca programs.
file  pqueue.h
 Priority queue definitions for queues where the priority is a number that can be compared with ordinary numerical comparisons.
file  pqueue_base.h
 Priority Queue function declarations used as a base for Lingua Franca priority queues.
file  pqueue_tag.h
 Priority queue that uses tags for sorting.
file  reactor_common.h
 Declarations of functions with implementations in reactor.c and reactor_threaded.c.
file  reactor_threaded.h
 Runtime infrastructure for the threaded version of the C target of Lingua Franca.
file  scheduler.h
 Scheduler API for the threaded C runtime.
file  scheduler_instance.h
 Common scheduler parameters.
file  scheduler_sync_tag_advance.h
 API used to advance tag globally.
file  tracepoint.h
 Definitions of tracepoint functions for use with the C code generator and any other code generator that uses the C infrastructure (such as the Python code generator).
file  util.h
 Core utility functions for Lingua Franca.
file  watchdog.h
 Declarations for watchdogs.

Data Structures

struct  allocation_record_t
 Allocation record to keep track of dynamically-allocated memory. More...
struct  environment_t
 Execution environment. More...
struct  event_t
 Event activation record to push onto the event queue. More...
struct  lf_action_base_t
 Base type for actions. More...
struct  lf_port_base_t
 Base type for ports. More...
struct  lf_scheduler_t
 Parameters used in schedulers of the threaded reactor C runtime. More...
struct  lf_semaphore_t
 A semaphore. More...
struct  lf_sparse_io_record_t
 A record of the subset of channels of a multiport that have present inputs. More...
struct  lf_tag_advancement_barrier_t
 A struct representing a barrier in threaded LF programs. More...
struct  mixed_radix_int_t
 Representation of a permuted mixed radix integer. More...
struct  pqueue_t
 The priority queue struct. More...
struct  reaction_t
 Reaction activation record to push onto the reaction queue. More...
struct  sched_params_t
 Struct representing the most common scheduler parameters. More...
struct  self_base_t
 The base type for all reactor self structs. More...
struct  token_template_t
 Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens. More...
struct  token_type_t
 Type information for tokens. More...
struct  trace_record_t
 A trace record that gets written in binary to the trace file in the default implementation. More...
struct  trigger_t
 Trigger struct representing an output, timer, action, or input. More...
struct  watchdog_t
 Typdef for watchdog_t struct, used to call watchdog handler. More...

Macros

#define CONCATENATE_THREE_STRINGS(__string1, __string2, __string3)
 A handy macro that can concatenate three strings.
#define GLOBAL_ENVIRONMENT   NULL
 The global environment.
#define LF_COND_BROADCAST(cond)
 Broadcast a condition variable with error checking.
#define LF_COND_INIT(cond, mutex)
 Initialize condition variable with error checking.
#define LF_COND_SIGNAL(cond)
 Signal a condition variable with error checking.
#define LF_COND_WAIT(cond)
 Wait on a condition variable with error checking.
#define LF_CRITICAL_SECTION_ENTER(env)
 Enter critical section with error checking.
#define LF_CRITICAL_SECTION_EXIT(env)
 Exit critical section with error checking.
#define LF_LEVEL(index)
 Macro for extracting the level from the index of a reaction.
#define LF_MAX(X, Y)
 Utility for finding the maximum of two values.
#define LF_MIN(X, Y)
 Utility for finding the minimum of two values.
#define LF_MUTEX_INIT(mutex)
 Initialize mutex with error checking.
#define LF_MUTEX_LOCK(mutex)
 Lock mutex with error checking.
#define LF_MUTEX_UNLOCK(mutex)
 Unlock mutex with error checking.
#define MIN_SLEEP_DURATION   USEC(10)
 Constant giving the minimum amount of time to sleep to wait for physical time to reach a logical time.
#define SCHED_ADAPTIVE   1
 Experimental adaptive scheduler.
#define SCHED_GEDF_NP   2
 Experimental GEDF-NP scheduler.
#define SCHED_NP   3
 Default non-preemptive scheduler.
#define tracepoint_reaction_deadline_missed(env, reaction, worker)
 Trace the occurrence of a deadline miss.
#define tracepoint_reaction_ends(env, reaction, worker)
 Trace the end of a reaction execution.
#define tracepoint_reaction_starts(env, reaction, worker)
 Trace the start of a reaction execution.
#define tracepoint_scheduler_advancing_time_ends(env)
 Trace the end of the scheduler waiting for logical time to advance or an event to appear on the event queue.
#define tracepoint_scheduler_advancing_time_starts(env)
 Trace the start of the scheduler waiting for logical time to advance or an event to appear on the event queue.
#define tracepoint_worker_wait_ends(env, worker)
 Trace the end of a worker waiting for something to change on the event or reaction queue.
#define tracepoint_worker_wait_starts(env, worker)
 Trace the start of a worker waiting for something to change on the reaction queue.

Typedefs

typedef struct allocation_record_t allocation_record_t
 Allocation record to keep track of dynamically-allocated memory.
typedef struct environment_t environment_t
 Execution environment.
typedef struct event_t event_t
 Event activation record for storing event queue entries.
typedef pqueue_pri_t index_t
 Topological order index for reactions.
typedef struct lf_port_base_t lf_port_base_t
 Base type for ports.
typedef struct lf_scheduler_t lf_scheduler_t
 Parameters used in schedulers of the threaded reactor C runtime.
typedef struct lf_sparse_io_record_t lf_sparse_io_record_t
 A record of the subset of channels of a multiport that have present inputs.
typedef struct lf_tag_advancement_barrier_t lf_tag_advancement_barrier_t
 A struct representing a barrier in threaded LF programs.
typedef struct mixed_radix_int_t mixed_radix_int_t
 Representation of a permuted mixed radix integer.
typedef int(* pqueue_cmp_pri_f) (pqueue_pri_t next, pqueue_pri_t curr)
 Callback to compare two priorities.
typedef int(* pqueue_eq_elem_f) (void *next, void *curr)
 Callback to determine whether two elements are equivalent.
typedef size_t(* pqueue_get_pos_f) (void *a)
 Callback functions to get the position of an element.
typedef pqueue_pri_t(* pqueue_get_pri_f) (void *a)
 Callback to get the priority of an element.
typedef unsigned long long pqueue_pri_t
 Priority data type.
typedef void(* pqueue_print_entry_f) (void *a)
 Debug callback function to print a entry.
typedef void(* pqueue_set_pos_f) (void *a, size_t pos)
 Callback functions to set the position of an element.
typedef struct pqueue_t pqueue_t
 The priority queue struct.
typedef pqueue_t pqueue_tag_t
 Type of a priority queue sorted by tags.
typedef void(* reaction_function_t) (void *)
 Reaction function type.
typedef struct self_base_t self_base_t
 The base type for all reactor self structs.
typedef enum token_freed token_freed
 Possible return values for _lf_done_using and _lf_free_token.
typedef struct token_template_t token_template_t
 Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens.
typedef struct token_type_t token_type_t
 Type information for tokens.
typedef INTERNAL struct trace_record_t trace_record_t
 A trace record that gets written in binary to the trace file in the default implementation.
typedef int trigger_handle_t
 Handles for scheduled triggers.
typedef unsigned short int ushort
 Unsigned short type.
typedef void(* watchdog_function_t) (void *)
 Watchdog function type.
typedef struct watchdog_t watchdog_t
 Typdef for watchdog_t struct, used to call watchdog handler.

Enumerations

enum  lf_spacing_policy_t { defer , drop , replace , update }
 Policy for handling scheduled events that violate the specified minimum interarrival time. More...
enum  port_status_t { absent = false , present = true , unknown }
 Status of a given port at a given logical time. More...
enum  reaction_status_t { inactive = 0 , queued , running }
 Status of a given reaction at a given logical time. More...
enum  token_freed { NOT_FREED = 0 , VALUE_FREED , TOKEN_FREED , TOKEN_AND_VALUE_FREED }
 Possible return values for _lf_done_using and _lf_free_token. More...

Functions

void _lf_advance_tag (environment_t *env, tag_t next_tag)
 Advance from the current tag to the next.
event_t_lf_create_dummy_events (environment_t *env, tag_t tag)
 Create a dummy event with the specified tag.
void _lf_decrement_tag_barrier_locked (environment_t *env)
 Decrement the total number of pending barrier requests for the environment tag barrier.
token_freed _lf_done_using (lf_token_t *token)
 Decrement the reference count of the specified token.
void _lf_free_all_tokens ()
 Free all tokens.
token_freed _lf_free_token (lf_token_t *token)
 Free the specified token, if appropriate.
void _lf_free_token_copies (void)
 Free token copies made for mutable inputs.
int _lf_get_environments (environment_t **envs)
 Update the argument to point to the beginning of the array of environments in this program.
lf_token_t_lf_get_token (token_template_t *tmplt)
 Get a token for the specified template.
void _lf_increment_tag_barrier (environment_t *env, tag_t future_tag)
 Raise a barrier to prevent the current tag for the specified environment from advancing to or beyond the value of the future_tag argument, if possible.
void _lf_increment_tag_barrier_locked (environment_t *env, tag_t future_tag)
 Version of _lf_increment_tag_barrier to call when the caller holds the mutex.
void _lf_initialize_template (token_template_t *tmplt, size_t element_size)
 Initialize the specified template to contain a token that is an.
bool _lf_initialize_timer (environment_t *env, trigger_t *timer)
 Initialize the given timer.
bool _lf_initialize_timers (environment_t *env)
 Initialize all the timers in the environment.
lf_token_t_lf_initialize_token (token_template_t *tmplt, size_t length)
 Return a token for storing an array of the specified length with new memory allocated (using calloc, so initialize to zero) for storing that array.
lf_token_t_lf_initialize_token_with_value (token_template_t *tmplt, void *value, size_t length)
 Return a token storing the specified value, which is assumed to be either a scalar (if length is 1) or an array of the specified length.
void _lf_initialize_trigger_objects ()
 Generated function that produces a table containing all triggers (i.e., inputs, timers, and actions).
void _lf_initialize_watchdogs (environment_t *env)
 Function to initialize mutexes for watchdogs.
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.
void _lf_invoke_reaction (environment_t *env, reaction_t *reaction, int worker)
 Invoke the specified reaction on the specified worker in the specified environment.
lf_multiport_iterator_t _lf_multiport_iterator_impl (lf_port_base_t **port, int width)
 Given an array of pointers to port structs, return an iterator that can be used to iterate over the present channels.
lf_token_t_lf_new_token (token_type_t *type, void *value, size_t length)
 Return a new token with the specified type, value, and length.
void _lf_next_locked (environment_t *env)
 Advance the logical time.
void _lf_pop_events (environment_t *env)
 Pop all events from event_q with tag equal to current tag.
int _lf_register_trace_event (void *pointer1, void *pointer2, _lf_trace_object_t type, char *description)
 Register a trace object.
void _lf_replace_template_token (token_template_t *tmplt, lf_token_t *newtoken)
 Replace the token in the specified template, if there is one, with a new one.
bool _lf_sched_advance_tag_locked (lf_scheduler_t *sched)
 Advance the tag to the next tag on the event queue.
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).
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 value.
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_start_time_step (environment_t *env)
 Perform whatever is needed to start a time step.
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_shutdown_reactions (environment_t *env)
 Trigger all the shutdown reactions in the specified environment.
void _lf_trigger_startup_reactions (environment_t *env)
 Trigger all the startup reactions in the specified environment.
int _lf_wait_on_tag_barrier (environment_t *env, tag_t proposed_tag)
 Wait on the tag barrier for the environment.
void _lf_watchdog_terminate_all (environment_t *env)
 Terminates all watchdogs inside the environment.
void call_tracepoint (int event_type, void *reactor, tag_t tag, int worker, int src_id, int dst_id, instant_t *physical_time, trigger_t *trigger, interval_t extra_delay)
 Pass the provided info to the tracing module.
void environment_free (environment_t *env)
 Free the dynamically allocated memory on the environment struct.
int environment_init (environment_t *env, const char *name, int id, int num_workers, int num_timers, int num_startup_reactions, int num_shutdown_reactions, int num_reset_reactions, int num_is_present_fields, int num_modes, int num_state_resets, int num_watchdogs, const char *trace_file_name)
 Initialize an environment struct with parameters given in the arguments.
void environment_init_tags (environment_t *env, instant_t start_time, interval_t duration)
 Initialize the start and stop tags on the environment struct.
void environment_verify (environment_t *env)
 Verify that the environment is correctly set up.
void void void void error (const char *msg)
 Print the error defined by the errno variable with the specified message as a prefix, then exit with error code 1.
tag_t get_next_event_tag (environment_t *env)
 Return the tag of the next event on the event queue.
pqueue_pri_t get_reaction_index (void *reaction)
 Report a priority equal to the index of the given reaction.
size_t get_reaction_position (void *reaction)
 Return the given reaction's position in the queue.
int in_no_particular_order (pqueue_pri_t thiz, pqueue_pri_t that)
 Return 0 regardless of argument order.
int in_reverse_order (pqueue_pri_t thiz, pqueue_pri_t that)
 Return 1 if the first argument is greater than the second and zero otherwise.
void initialize_global ()
 Initialize global variables and start tracing before calling the _lf_initialize_trigger_objects() function.
void * lf_allocate (size_t count, size_t size, struct allocation_record_t **head)
 Allocate memory and record on the specified allocation record (a self struct).
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.
void lf_create_environments (void)
 Create and initialize the required number of environments for the program.
tag_t lf_delay_strict (tag_t tag, interval_t interval)
 Return the latest tag strictly less than the specified tag plus the interval, unless tag is NEVER or interval is negative (including NEVER),.
uint16_t lf_fed_id (void)
 Return the federate ID or -1 if this program is not part of a federation.
void lf_free (struct allocation_record_t **head)
 Free memory on the specified allocation record (a self struct).
void lf_free_all_reactors (void)
 Free all the reactors that are allocated with lf_new_reactor(size_t).
void lf_free_reactor (self_base_t *self)
 Free the specified reactor.
event_tlf_get_new_event (environment_t *env)
 Get a new event.
self_base_tlf_new_reactor (size_t size)
 Allocate memory for a new runtime instance of a reactor.
void lf_print_snapshot (environment_t *env)
 Print a snapshot of the priority queues used during execution (for debugging).
void lf_recycle_event (environment_t *env, event_t *e)
 Recycle the given event.
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_sched_done_with_reaction (size_t worker_number, reaction_t *done_reaction)
 Inform the scheduler that worker thread 'worker_number' is done executing the 'done_reaction'.
void lf_sched_free (lf_scheduler_t *scheduler)
 Free the memory used by the scheduler.
reaction_tlf_sched_get_ready_reaction (lf_scheduler_t *scheduler, int worker_number)
 Ask the scheduler for one more reaction.
void lf_sched_init (environment_t *env, size_t number_of_workers, sched_params_t *parameters)
 Initialize the scheduler.
trigger_handle_t lf_schedule_trigger (environment_t *env, trigger_t *trigger, interval_t delay, lf_token_t *token)
 Schedule the specified trigger to execute in the specified environment with given delay and token.
void lf_scheduler_trigger_reaction (lf_scheduler_t *scheduler, reaction_t *reaction, int worker_number)
 Inform the scheduler that worker thread 'worker_number' would like to trigger 'reaction' at the current tag.
void lf_semaphore_acquire (lf_semaphore_t *semaphore)
 Acquire the 'semaphore'.
void lf_semaphore_destroy (lf_semaphore_t *semaphore)
 Destroy the 'semaphore'.
lf_semaphore_tlf_semaphore_new (size_t count)
 Create a new semaphore.
void lf_semaphore_release (lf_semaphore_t *semaphore, size_t i)
 Release the 'semaphore' and add 'i' to its count.
void lf_semaphore_wait (lf_semaphore_t *semaphore)
 Wait on the 'semaphore' if count is 0.
void lf_set_default_command_line_options (void)
 Generated function that optionally sets default command-line options.
void lf_set_stop_tag (environment_t *env, tag_t tag)
 Set the stop tag if it is less than the stop tag of the specified environment.
tag_t lf_tag_latest_earlier (tag_t tag)
 Return the greatest tag earlier than the given tag.
void lf_terminate_execution (environment_t *env)
 Function that is called when the program is about to exit.
instant_t lf_time_logical (void *env)
 Return the current logical time in nanoseconds.
interval_t lf_time_logical_elapsed (void *env)
 Return the elapsed logical time in nanoseconds since the start of execution.
void lf_tracing_check_version ()
 Check if the tracing library is compatible with the current version of the runtime.
void lf_vprint (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 varargs alternative of "lf_print"
void void void lf_vprint_debug (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 varargs alternative of "lf_print_debug"
void lf_vprint_error (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 varargs alternative of "lf_print_error"
void void void lf_vprint_error_and_exit (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 varargs alternative of "lf_print_error_and_exit"
void void lf_vprint_log (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 varargs alternative of "lf_print_log"
void void lf_vprint_warning (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 varargs alternative of "lf_print_warning"
void logical_tag_complete (tag_t tag_to_send)
 Placeholder for code-generated function that will, in a federated execution, be used to coordinate the advancement of tag.
void mixed_radix_incr (mixed_radix_int_t *mixed)
 Increment the mixed radix number by one according to the permutation matrix.
int mixed_radix_parent (mixed_radix_int_t *mixed, int n)
 Return the int value of a mixed-radix number after dropping the first n digits.
int mixed_radix_to_int (mixed_radix_int_t *mixed)
 Return the int value of a mixed-radix number.
void pqueue_empty_into (pqueue_t **dest, pqueue_t **src)
 Empty 'src' into 'dest'.
void * pqueue_find_equal_same_priority (pqueue_t *q, void *e)
 Return an entry with the same priority (determined by cmppri) that matches the supplied entry (determined by eqelem) or NULL if there is no such entry.
void * pqueue_find_same_priority (pqueue_t *q, void *e)
 Return an entry with the same priority as the specified entry or NULL if there is no such entry.
void pqueue_free (pqueue_t *q)
 Free all memory used by the queue.
pqueue_tpqueue_init (size_t n, pqueue_cmp_pri_f cmppri, pqueue_get_pri_f getpri, pqueue_get_pos_f getpos, pqueue_set_pos_f setpos, pqueue_eq_elem_f eqelem, pqueue_print_entry_f prt)
 Allocate and initialize a priority queue.
int pqueue_insert (pqueue_t *q, void *d)
 Insert an element into the queue.
void * pqueue_peek (pqueue_t *q)
 Access highest-ranking item without removing it.
void * pqueue_pop (pqueue_t *q)
 Pop the highest-ranking item from the queue.
void pqueue_print (pqueue_t *q, pqueue_print_entry_f print)
 Print the contents of the queue.
int pqueue_remove (pqueue_t *q, void *e)
 Remove an item from the queue.
size_t pqueue_size (pqueue_t *q)
 Return the size of the queue.
int pqueue_tag_compare (pqueue_pri_t priority1, pqueue_pri_t priority2)
 Callback comparison function for the tag-based priority queue.
pqueue_tag_element_tpqueue_tag_find_equal_same_tag (pqueue_tag_t *q, pqueue_tag_element_t *e)
 Return an item with the same tag (cmppri returns 0) that matches the supplied element (eqelem returns non-zero) or NULL if there is none.
pqueue_tag_element_tpqueue_tag_find_with_tag (pqueue_tag_t *q, tag_t t)
 Return the first item with the specified tag or NULL if there is none.
void pqueue_tag_free (pqueue_tag_t *q)
 Free all memory used by the queue including elements that are marked dynamic.
pqueue_tag_tpqueue_tag_init (size_t initial_size)
 Create a priority queue sorted by tags.
pqueue_tag_tpqueue_tag_init_customize (size_t initial_size, pqueue_cmp_pri_f cmppri, pqueue_eq_elem_f eqelem, pqueue_print_entry_f prt)
 Create a priority queue that stores elements with a particular payload.
int pqueue_tag_insert (pqueue_tag_t *q, pqueue_tag_element_t *d)
 Insert an element into the queue.
int pqueue_tag_insert_if_no_match (pqueue_tag_t *q, tag_t t)
 Insert a tag into the queue if the tag is not already in the queue.
int pqueue_tag_insert_tag (pqueue_tag_t *q, tag_t t)
 Insert a tag into the queue.
pqueue_tag_element_tpqueue_tag_peek (pqueue_tag_t *q)
 Return highest-ranking item (the one with the least tag) without removing it.
tag_t pqueue_tag_peek_tag (pqueue_tag_t *q)
 Return the least tag in the queue or FOREVER if the queue is empty.
pqueue_tag_element_tpqueue_tag_pop (pqueue_tag_t *q)
 Pop the least-tag element from the queue.
tag_t pqueue_tag_pop_tag (pqueue_tag_t *q)
 Pop the least-tag element from the queue and return its tag.
void pqueue_tag_remove (pqueue_tag_t *q, pqueue_tag_element_t *e)
 Remove an item from the queue.
void pqueue_tag_remove_up_to (pqueue_tag_t *q, tag_t t)
 Remove items from the queue with tags up to and including the specified tag.
size_t pqueue_tag_size (pqueue_tag_t *q)
 Return the size of the queue.
void print_reaction (void *reaction)
 Print some information about the given reaction.
int process_args (int argc, const char *argv[])
 Process the command-line arguments.
int reaction_matches (void *a, void *b)
 Return 1 if the two arguments are identical pointers.
void schedule_output_reactions (environment_t *env, reaction_t *reaction, int worker)
 Schedule the output reactions for the specified reaction in the specified environment.
tag_t send_next_event_tag (environment_t *env, tag_t tag, bool wait_for_reply)
 Send the next event tag.
void set_reaction_position (void *reaction, size_t pos)
 Set the given reaction's position in the queue.
bool should_stop_locked (lf_scheduler_t *sched)
 Return true if the worker should stop now; false otherwise.
void termination (void)
 Perform final wrap-up on exit.
void tracepoint_schedule (environment_t *env, trigger_t *trigger, interval_t extra_delay)
 Trace a call to schedule.
bool wait_until (instant_t wait_until_time, lf_cond_t *condition)
 Wait until physical time matches or exceeds the time of the specified tag.

Variables

int _lf_count_token_allocations
 Counter used to issue a warning if memory is allocated for tokens and never freed.
uint16_t _lf_my_fed_id
 The ID of this federate.

Detailed Description

API mainly used internally, but occasionally useful for users.

These functions and types are not meant to be used directly by users, but are useful for developers.

Macro Definition Documentation

◆ CONCATENATE_THREE_STRINGS

#define CONCATENATE_THREE_STRINGS ( __string1,
__string2,
__string3 )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
__string1 __string2 __string3

A handy macro that can concatenate three strings.

Useful in the LF_PRINT_DEBUG macro and lf_print_error functions that want to concatenate a "DEBUG: " or "ERROR: " to the beginning of the message and a new line format
at the end.

◆ GLOBAL_ENVIRONMENT

#define GLOBAL_ENVIRONMENT   NULL

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

The global environment.

Some operations are not specific to a particular scheduling enclave and therefore have no associated environment. When invoking a function such as lf_critical_section_enter, which requires an environment argument, it may be possible to pass this GLOBAL_ENVIRONMENT. For lf_critical_section_enter, for example, this may acquire a global mutex instead of a mutex specific to a particular scheduling enclave. Most functions that take environment arguments, however, cannot accept the GLOBAL_ENVIRONMENT argument, and passing it will result in an assertion violation.

◆ LF_COND_BROADCAST

#define LF_COND_BROADCAST ( cond)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_cond_broadcast(cond), "Condition variable broadcast failed.")
#define LF_ASSERTN(condition, format,...)
Assert that a condition is false.
Definition logging_macros.h:124
int lf_cond_broadcast(lf_cond_t *cond)
Wake up all threads waiting for condition variable cond.

Broadcast a condition variable with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable.

◆ LF_COND_INIT

#define LF_COND_INIT ( cond,
mutex )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_cond_init(cond, mutex), "Condition variable init failed.")
int lf_cond_init(lf_cond_t *cond, lf_mutex_t *mutex)
Initialize a conditional variable.

Initialize condition variable with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable to initialize.
mutexPointer to the mutex to associate with the condition variable.

◆ LF_COND_SIGNAL

#define LF_COND_SIGNAL ( cond)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_cond_signal(cond), "Condition variable signal failed.")
int lf_cond_signal(lf_cond_t *cond)
Wake up one thread waiting for condition variable cond.

Signal a condition variable with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable.

◆ LF_COND_WAIT

#define LF_COND_WAIT ( cond)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_cond_wait(cond), "Condition variable wait failed.")
int lf_cond_wait(lf_cond_t *cond)
Wait for condition variable "cond" to be signaled or broadcast.

Wait on a condition variable with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable.

◆ LF_CRITICAL_SECTION_ENTER

#define LF_CRITICAL_SECTION_ENTER ( env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERT(!lf_critical_section_enter(env), "Could not enter critical section")
#define LF_ASSERT(condition, format,...)
Assert that a condition is true.
Definition logging_macros.h:101
int lf_critical_section_enter(environment_t *env)
Enter critical section within an environment.

Enter critical section with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
envPointer to the environment.

◆ LF_CRITICAL_SECTION_EXIT

#define LF_CRITICAL_SECTION_EXIT ( env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERT(!lf_critical_section_exit(env), "Could not exit critical section")
int lf_critical_section_exit(environment_t *env)
Leave a critical section within an environment.

Exit critical section with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
envPointer to the environment.

◆ LF_LEVEL

#define LF_LEVEL ( index)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
(index & 0xffffLL)

Macro for extracting the level from the index of a reaction.

A reaction that has no upstream reactions has level 0. Other reactions have a level that is the length of the longest upstream chain to a reaction with level 0 (inclusive). This is used, along with the deadline, to sort reactions in the reaction queue. It ensures that reactions that are upstream in the dependence graph execute before reactions that are downstream.

◆ LF_MAX

#define LF_MAX ( X,
Y )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
(((X) > (Y)) ? (X) : (Y))

Utility for finding the maximum of two values.

◆ LF_MIN

#define LF_MIN ( X,
Y )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
(((X) < (Y)) ? (X) : (Y))

Utility for finding the minimum of two values.

◆ LF_MUTEX_INIT

#define LF_MUTEX_INIT ( mutex)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_mutex_init(mutex), "Mutex init failed.")
int lf_mutex_init(lf_mutex_t *mutex)
Initialize a mutex.

Initialize mutex with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
mutexPointer to the mutex to initialize.

◆ LF_MUTEX_LOCK

#define LF_MUTEX_LOCK ( mutex)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_mutex_lock(mutex), "Mutex lock failed.")
int lf_mutex_lock(lf_mutex_t *mutex)
Lock the specified mutex.

Lock mutex with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
mutexPointer to the mutex to lock.

◆ LF_MUTEX_UNLOCK

#define LF_MUTEX_UNLOCK ( mutex)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Value:
LF_ASSERTN(lf_mutex_unlock(mutex), "Mutex unlock failed.")
int lf_mutex_unlock(lf_mutex_t *mutex)
Unlock the specified mutex.

Unlock mutex with error checking.

This is optimized away if the NDEBUG flag is defined.

Parameters
mutexPointer to the mutex to unlock.

◆ MIN_SLEEP_DURATION

#define MIN_SLEEP_DURATION   USEC(10)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Constant giving the minimum amount of time to sleep to wait for physical time to reach a logical time.

Unless the "fast" option is given, an LF program will wait until physical time matches logical time before handling an event with a given logical time. The amount of time is less than this given threshold, then no wait will occur. The purpose of this is to prevent unnecessary delays caused by simply setting up and performing the wait.

◆ SCHED_ADAPTIVE

#define SCHED_ADAPTIVE   1

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Experimental adaptive scheduler.

◆ SCHED_GEDF_NP

#define SCHED_GEDF_NP   2

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Experimental GEDF-NP scheduler.

◆ SCHED_NP

#define SCHED_NP   3

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Default non-preemptive scheduler.

◆ tracepoint_reaction_deadline_missed

#define tracepoint_reaction_deadline_missed ( env,
reaction,
worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(reaction_deadline_missed, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, \
NULL, 0)
void call_tracepoint(int event_type, void *reactor, tag_t tag, int worker, int src_id, int dst_id, instant_t *physical_time, trigger_t *trigger, interval_t extra_delay)
Pass the provided info to the tracing module.
@ reaction_deadline_missed
Definition trace_types.h:23

Trace the occurrence of a deadline miss.

Parameters
envThe environment in which we are executing
reactionPointer to the reaction_t struct for the reaction.
workerThe thread number of the worker thread or 0 for single-threaded execution.

◆ tracepoint_reaction_ends

#define tracepoint_reaction_ends ( env,
reaction,
worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(reaction_ends, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, \
reaction->deadline)
@ reaction_ends
Definition trace_types.h:22

Trace the end of a reaction execution.

Parameters
envThe environment in which we are executing
reactionPointer to the reaction_t struct for the reaction.
workerThe thread number of the worker thread or 0 for single-threaded execution.

◆ tracepoint_reaction_starts

#define tracepoint_reaction_starts ( env,
reaction,
worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(reaction_starts, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, \
reaction->deadline)
@ reaction_starts
Definition trace_types.h:21

Trace the start of a reaction execution.

Parameters
envThe environment in which we are executing
reactionPointer to the reaction_t struct for the reaction.
workerThe thread number of the worker thread or 0 for single-threaded execution.

◆ tracepoint_scheduler_advancing_time_ends

#define tracepoint_scheduler_advancing_time_ends ( env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(scheduler_advancing_time_ends, NULL, env->current_tag, -1, -1, -1, NULL, NULL, 0)
@ scheduler_advancing_time_ends
Definition trace_types.h:30

Trace the end of the scheduler waiting for logical time to advance or an event to appear on the event queue.

Parameters
envThe environment in which we are executing

◆ tracepoint_scheduler_advancing_time_starts

#define tracepoint_scheduler_advancing_time_starts ( env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(scheduler_advancing_time_starts, NULL, env->current_tag, -1, -1, -1, NULL, NULL, 0);
@ scheduler_advancing_time_starts
Definition trace_types.h:29

Trace the start of the scheduler waiting for logical time to advance or an event to appear on the event queue.

Parameters
envThe environment in which we are executing

◆ tracepoint_worker_wait_ends

#define tracepoint_worker_wait_ends ( env,
worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(worker_wait_ends, NULL, env->current_tag, worker, worker, -1, NULL, NULL, 0)
@ worker_wait_ends
Definition trace_types.h:28

Trace the end of a worker waiting for something to change on the event or reaction queue.

Parameters
envThe environment in which we are executing
workerThe thread number of the worker thread or 0 for single-threaded execution.

◆ tracepoint_worker_wait_starts

#define tracepoint_worker_wait_starts ( env,
worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Value:
call_tracepoint(worker_wait_starts, NULL, env->current_tag, worker, worker, -1, NULL, NULL, 0)
@ worker_wait_starts
Definition trace_types.h:27

Trace the start of a worker waiting for something to change on the reaction queue.

Parameters
envThe environment in which we are executing
workerThe thread number of the worker thread or 0 for single-threaded execution.

Typedef Documentation

◆ allocation_record_t

typedef struct allocation_record_t allocation_record_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Allocation record to keep track of dynamically-allocated memory.

An allocation record that is used by a destructor for a reactor to free memory that has been dynamically allocated for the particular instance of the reactor. This will be an element of linked list. The allocated pointer points to the allocated memory, and the next pointer points to the next allocation record (or NULL if there are no more).

◆ environment_t

typedef struct environment_t environment_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

Execution environment.

This struct contains information about the execution environment. An execution environment maintains a notion of a "current tag" and has its own event queue and scheduler. Normally, there is only one execution environment, but if you use scheduling enclaves, then there will be one for each enclave.

◆ event_t

typedef struct event_t event_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Event activation record for storing event queue entries.

This type is used for storing activation records in the event queue. Each event represents a scheduled trigger with its associated data.

◆ index_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Topological order index for reactions.

◆ lf_port_base_t

typedef struct lf_port_base_t lf_port_base_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Base type for ports.

Port structs are customized types because their payloads are type specific. This struct represents their common features. Given any pointer to a port struct, it can be cast to lf_port_base_t and then these common fields can be accessed.

IMPORTANT: If this is changed, it must also be changed in CPortGenerator.java generateAuxiliaryStruct().

◆ lf_scheduler_t

typedef struct lf_scheduler_t lf_scheduler_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler_instance.h>

Parameters used in schedulers of the threaded reactor C runtime.

Note
Members of this struct are added based on existing schedulers' needs. These should be expanded to accommodate new schedulers.

◆ lf_sparse_io_record_t

typedef struct lf_sparse_io_record_t lf_sparse_io_record_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

A record of the subset of channels of a multiport that have present inputs.

This struct is used to efficiently track which channels of a multiport have present inputs, particularly useful for sparse I/O operations where only a small subset of channels are active.

◆ lf_tag_advancement_barrier_t

typedef struct lf_tag_advancement_barrier_t lf_tag_advancement_barrier_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

A struct representing a barrier in threaded LF programs.

This will prevent advancement of the current tag if the number of requestors is larger than 0 or the value of horizon is not (FOREVER, 0).

◆ mixed_radix_int_t

typedef struct mixed_radix_int_t mixed_radix_int_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/mixed_radix.h>

Representation of a permuted mixed radix integer.

The three arrays (digits, radixes, and permutation) are all assumed to have the same size as given by the size field.

◆ pqueue_cmp_pri_f

typedef int(* pqueue_cmp_pri_f) (pqueue_pri_t next, pqueue_pri_t curr)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Callback to compare two priorities.

◆ pqueue_eq_elem_f

typedef int(* pqueue_eq_elem_f) (void *next, void *curr)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Callback to determine whether two elements are equivalent.

◆ pqueue_get_pos_f

typedef size_t(* pqueue_get_pos_f) (void *a)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Callback functions to get the position of an element.

◆ pqueue_get_pri_f

typedef pqueue_pri_t(* pqueue_get_pri_f) (void *a)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Callback to get the priority of an element.

◆ pqueue_pri_t

typedef unsigned long long pqueue_pri_t

◆ pqueue_print_entry_f

typedef void(* pqueue_print_entry_f) (void *a)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Debug callback function to print a entry.

◆ pqueue_set_pos_f

typedef void(* pqueue_set_pos_f) (void *a, size_t pos)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Callback functions to set the position of an element.

◆ pqueue_t

typedef struct pqueue_t pqueue_t

◆ pqueue_tag_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Type of a priority queue sorted by tags.

◆ reaction_function_t

typedef void(* reaction_function_t) (void *)

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Reaction function type.

The argument passed to one of these reaction functions is a pointer to the self struct for the reactor.

◆ self_base_t

typedef struct self_base_t self_base_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

The base type for all reactor self structs.

The first element of every self struct defined in generated code will be a pointer to an allocation record, which is either NULL or the head of a NULL-terminated linked list of allocation records. This list is used to free memory that has been dynamically allocated. This struct also provides a pointer to the currently executing reaction, to the environment in which the reaction is executing, and to the mutex that is used to protect the reactor. If modal models are being used, it also records the current mode.

◆ token_freed

◆ token_template_t

typedef struct token_template_t token_template_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens.

The structs lf_port_base_t and trigger_t should start with an instance of this struct so that they can be cast to this struct to access these fields in a uniform way. This template provides the common structure for handling tokens in both ports and actions, ensuring consistent token management across different types of connections.

◆ token_type_t

typedef struct token_type_t token_type_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Type information for tokens.

Specifically, this struct contains the fields needed to support token types, which carry dynamically allocated data.

◆ trace_record_t

typedef INTERNAL struct trace_record_t trace_record_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

A trace record that gets written in binary to the trace file in the default implementation.

◆ trigger_handle_t

typedef int trigger_handle_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Handles for scheduled triggers.

These handles are returned by lf_schedule() functions. The intent is that the handle can be used to cancel a future scheduled event, but this is not implemented yet.

◆ ushort

typedef unsigned short int ushort

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Unsigned short type.

Redefine here for portability if sys/types.h is not included.

See also
sys/types.h
Note
using sizeof(ushort) should be okay but not sizeof ushort.

◆ watchdog_function_t

typedef void(* watchdog_function_t) (void *)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/watchdog.h>

Watchdog function type.

The argument passed to one of these watchdog functions is a pointer to the self struct for the reactor.

◆ watchdog_t

typedef struct watchdog_t watchdog_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/watchdog.h>

Typdef for watchdog_t struct, used to call watchdog handler.

Enumeration Type Documentation

◆ lf_spacing_policy_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Policy for handling scheduled events that violate the specified minimum interarrival time.

The default policy is defer: adjust the tag to that the minimum interarrival time is satisfied. The drop policy simply drops events that are scheduled too early. The replace policy will attempt to replace the payload of the preceding event. Unless the preceding event has already been handled, it gets assigned the value of the new event. If the preceding event has already been popped off the event queue, the defer policy is fallen back to. The update policy drops the preceding event, if it is still in the event queue, and updates it with the newly scheduled event.

Enumerator
defer 
drop 
replace 
update 

◆ port_status_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Status of a given port at a given logical time.

If the value is 'present', it is an indicator that the port is present at the given logical time. If the value is 'absent', it is an indicator that the port is absent at the given logical time. If the value is 'unknown', it is unknown whether the port is present or absent (e.g., in a distributed application).

Note
For non-network ports, unknown is unused.
The absent and present fields need to be compatible with false and true respectively because for non-network ports, the status can either be present or absent (no possibility of unknown).
Enumerator
absent 
present 
unknown 

◆ reaction_status_t

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>

Status of a given reaction at a given logical time.

If a reaction is 'inactive', it is neither running nor queued. If a reaction is 'queued', it is going to be executed at the current logical time, but it has not started running yet. If a reaction is 'running', its body is being executed.

Note
inactive must equal zero because it should be possible to allocate a reaction with default values using calloc.
The running state does not seem to be read.
Enumerator
inactive 
queued 
running 

◆ token_freed

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Possible return values for _lf_done_using and _lf_free_token.

Enumerator
NOT_FREED 
VALUE_FREED 
TOKEN_FREED 
TOKEN_AND_VALUE_FREED 

Function Documentation

◆ _lf_advance_tag()

void _lf_advance_tag ( environment_t * env,
tag_t next_tag )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Advance from the current tag to the next.

If the given next_time is equal to the current time, then increase the microstep. Otherwise, update the current time and set the microstep to zero.

Parameters
envThe environment in which we are executing
next_tagThe tag step to advance to.

◆ _lf_create_dummy_events()

event_t * _lf_create_dummy_events ( environment_t * env,
tag_t tag )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Create a dummy event with the specified tag.

A dummy event is an event with no triggers that can be put on the event queue to trigger a tag advance to the specified tag.

Parameters
envEnvironment in which we are executing.
tagThe tag of that event.
Returns
A pointer to the dummy event.

◆ _lf_decrement_tag_barrier_locked()

void _lf_decrement_tag_barrier_locked ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Decrement the total number of pending barrier requests for the environment tag barrier.

If the total number of requests reaches zero, this function resets the tag barrier to FOREVER_TAG and notifies all threads that are waiting on the barrier that the number of requests has reached zero.

This function assumes that the caller already holds the mutex lock on env.

Note
This function is only useful in threaded applications to facilitate certain non-blocking functionalities such as receiving timed messages over the network or handling stop in the federated execution.
Parameters
envThe environment in which we are executing.

◆ _lf_done_using()

token_freed _lf_done_using ( lf_token_t * token)

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Decrement the reference count of the specified token.

If the reference count hits 0, free the memory for the value carried by the token, and, if the token is not also the template token of its trigger, free the token.

Parameters
tokenPointer to a token.
Returns
NOT_FREED if nothing was freed, VALUE_FREED if the value was freed, TOKEN_FREED if only the token was freed, and TOKEN_AND_VALUE_FREED if both the value and the token were freed.

◆ _lf_free_all_tokens()

void _lf_free_all_tokens ( )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Free all tokens.

Free tokens on the _lf_token_recycling_bin hashset and all template tokens.

◆ _lf_free_token()

token_freed _lf_free_token ( lf_token_t * token)

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Free the specified token, if appropriate.

If the reference count is greater than 0, then do not free anything. Otherwise, the token value (payload) will be freed, if there is one. Then the token itself will be freed. The freed token will be put on the recycling bin unless that bin has reached the designated capacity, in which case free() will be used.

Parameters
tokenPointer to a token.
Returns
NOT_FREED if nothing was freed, VALUE_FREED if the value was freed, TOKEN_FREED if only the token was freed, and TOKEN_AND_VALUE_FREED if both the value and the token were freed.

◆ _lf_free_token_copies()

void _lf_free_token_copies ( void )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Free token copies made for mutable inputs.

This function should be called at the beginning of each time step to avoid memory leaks.

◆ _lf_get_environments()

int _lf_get_environments ( environment_t ** envs)

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

Update the argument to point to the beginning of the array of environments in this program.

Note
Is code-generated by the compiler
Parameters
envsA double pointer which will be dereferenced and modified
Returns
int The number of environments in the array

◆ _lf_get_token()

lf_token_t * _lf_get_token ( token_template_t * tmplt)

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Get a token for the specified template.

If the template already has a token and the reference count is 1, then return that token. Otherwise, create a new token, make it the new template, and dissociate or free the previous template token.

Parameters
tmpltThe template. // template is a C++ keyword.
Returns
A new or recycled lf_token_t struct.

◆ _lf_increment_tag_barrier()

void _lf_increment_tag_barrier ( environment_t * env,
tag_t future_tag )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Raise a barrier to prevent the current tag for the specified environment from advancing to or beyond the value of the future_tag argument, if possible.

If the current tag is already at or beyond future_tag, then prevent any further advances. This function will increment the total number of pending barrier requests. For each call to this function, there should always be a subsequent call to _lf_decrement_tag_barrier_locked() to release the barrier.

If there is already a barrier raised at a tag later than future_tag, this function will change the barrier to future_tag or the current tag, whichever is larger. If the existing barrier is earlier than future_tag, this function will not change the barrier. If there are no existing barriers and future_tag is in the past relative to the current tag, this function will raise a barrier to the current tag plus one microstep.

This function acquires the mutex on the specified environment.

Note
This function is only useful in threaded applications to facilitate certain non-blocking functionalities such as receiving timed messages over the network or handling stop in a federated execution.
Parameters
envEnvironment within which we are executing.
future_tagA desired tag for the barrier. This function will guarantee that current logical time will not go past future_tag if it is in the future. If future_tag is in the past (or equals to current logical time), the runtime will freeze advancement of logical time.

◆ _lf_increment_tag_barrier_locked()

void _lf_increment_tag_barrier_locked ( environment_t * env,
tag_t future_tag )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Version of _lf_increment_tag_barrier to call when the caller holds the mutex.

This version does not acquire the mutex belonging to env.

Parameters
envEnvironment within which we are executing.
future_tagA desired tag for the barrier. This function will guarantee that current logical time will not go past future_tag if it is in the future. If future_tag is in the past (or equals to current logical time), the runtime will freeze advancement of logical time.

◆ _lf_initialize_template()

void _lf_initialize_template ( token_template_t * tmplt,
size_t element_size )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Initialize the specified template to contain a token that is an.

array with the specified element size. If the template already has a token with a reference count greater than 1 or a non-matching type, it will be replaced and that token will be freed. The length of the returned token will be 0, its value will be NULL, and its reference count will be 1.

Parameters
tmpltThe template. // template is a C++ keyword.
element_sizeThe element size.

◆ _lf_initialize_timer()

bool _lf_initialize_timer ( environment_t * env,
trigger_t * timer )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Initialize the given timer.

If this timer has a zero offset, enqueue the reactions it triggers. If this timer is to trigger reactions at a future tag as well, schedule it accordingly.

Parameters
envEnvironment in which we are executing.
timerThe timer to initialize.
Returns
true if the timer has an offset of 0, in which case the reaction is triggered rather than scheduled.

◆ _lf_initialize_timers()

bool _lf_initialize_timers ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Initialize all the timers in the environment.

Parameters
envEnvironment in which we are executing.
Returns
true if any timer has an offset of 0, in which case the reaction is triggered rather than scheduled.

◆ _lf_initialize_token()

lf_token_t * _lf_initialize_token ( token_template_t * tmplt,
size_t length )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Return a token for storing an array of the specified length with new memory allocated (using calloc, so initialize to zero) for storing that array.

If the template's token is available (it is non-null and its reference count is 1), then reuse it. Otherwise, create a new token and replace the template token with the new one, freeing the previous token from its template association. The element_size for elements of the array is specified by the specified template. The caller should populate the value and ref_count field of the returned token after this returns.

Parameters
tmpltThe token template (must not be NULL). // template is a C++ keyword.
lengthThe length of the array, or 1 if it is not an array.
Returns
Either the template's token or a new one, in each case with a value field pointing to newly allocated memory.

◆ _lf_initialize_token_with_value()

lf_token_t * _lf_initialize_token_with_value ( token_template_t * tmplt,
void * value,
size_t length )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Return a token storing the specified value, which is assumed to be either a scalar (if length is 1) or an array of the specified length.

If the token in the specified template is available (it non-null and its reference count is 1), then return it. Otherwise, create a new token and replace the template token with the new one, freeing the previous token from its template association. The element_size for elements of the array is specified by the specified template.

Parameters
tmpltA template for the token. // template is a C++ keyword.
valueThe value of the array.
lengthThe length of the array, or 1 if it is not an array.
Returns
Either the specified token or a new one, in each case with a value field pointing to newly allocated memory.

◆ _lf_initialize_trigger_objects()

void _lf_initialize_trigger_objects ( )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Generated function that produces a table containing all triggers (i.e., inputs, timers, and actions).

◆ _lf_initialize_watchdogs()

void _lf_initialize_watchdogs ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/watchdog.h>

Function to initialize mutexes for watchdogs.

This function is used to initialize the mutexes for the watchdogs.

Parameters
envThe environment to initialize the watchdogs for.

◆ _lf_insert_reactions_for_trigger()

trigger_handle_t _lf_insert_reactions_for_trigger ( environment_t * env,
trigger_t * trigger,
lf_token_t * token )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Insert reactions triggered by trigger to the reaction queue.

Parameters
envEnvironment in which we are executing.
triggerThe trigger.
tokenThe token wrapping the payload or NULL for no payload.
Returns
1 if successful, or 0 if no new reaction was scheduled because the function was called incorrectly.

◆ _lf_invoke_reaction()

void _lf_invoke_reaction ( environment_t * env,
reaction_t * reaction,
int worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Invoke the specified reaction on the specified worker in the specified environment.

Parameters
envThe environment in which we are executing.
reactionThe reaction.
workerThe worker number.

◆ _lf_multiport_iterator_impl()

lf_multiport_iterator_t _lf_multiport_iterator_impl ( lf_port_base_t ** port,
int width )

#include </Users/runner/work/reactor-c/reactor-c/include/core/port.h>

Given an array of pointers to port structs, return an iterator that can be used to iterate over the present channels.

Parameters
portAn array of pointers to port structs.
widthThe width of the multiport (or a negative number if not a multiport).

◆ _lf_new_token()

lf_token_t * _lf_new_token ( token_type_t * type,
void * value,
size_t length )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Return a new token with the specified type, value, and length.

This will attempt to get one from the recyling bin, and, if the recycling bin is empty, will allocate a new token using calloc and set its type to point to the specified type. The returned token will indicate that it is not a template token, and its reference count will be 0.

Parameters
typeThe type of the token.
valueThe value, or NULL to have no value.
lengthThe array length of the value, 1 to not be an array, or 0 to have no value.
Returns
lf_token_t*

◆ _lf_next_locked()

void _lf_next_locked ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Advance the logical time.

If there is at least one event in the event queue, then wait until physical time matches or exceeds the time of the least tag on the event queue; pop the next event(s) from the event queue that all have the same tag; extract from those events the reactions that are to be invoked at this logical time and insert them into the reaction queue. The event queue is sorted by time tag.

If there is no event in the queue and the keepalive command-line option was not given, and this is not a federated execution with centralized coordination, set the stop tag to the current tag. If keepalive was given, then wait for either lf_request_stop() to be called or an event appears in the event queue and then return.

Every time tag is advanced, it is checked against stop tag and if they are equal, shutdown reactions are triggered.

This does not acquire the mutex lock. It assumes the lock is already held.

Parameters
envEnvironment within which we are executing.

◆ _lf_pop_events()

void _lf_pop_events ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Pop all events from event_q with tag equal to current tag.

This will extract all the reactions triggered by these events and stick them onto the reaction queue.

Parameters
envThe environment in which we are executing

◆ _lf_register_trace_event()

int _lf_register_trace_event ( void * pointer1,
void * pointer2,
_lf_trace_object_t type,
char * description )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Register a trace object.

Parameters
pointer1Pointer that identifies the object, typically to a reactor self struct.
pointer2Further identifying pointer, typically to a trigger (action or timer) or NULL if irrelevant.
typeThe type of trace object.
descriptionThe human-readable description of the object.
Returns
1 if successful, 0 if the trace object table is full.

◆ _lf_replace_template_token()

void _lf_replace_template_token ( token_template_t * tmplt,
lf_token_t * newtoken )

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Replace the token in the specified template, if there is one, with a new one.

If the new token is the same as the token in the template, then this does nothing. Otherwise, it frees the previous template token.

Parameters
tmpltPointer to a template. // template is a C++ keyword.
newtokenThe replacement token.

◆ _lf_sched_advance_tag_locked()

bool _lf_sched_advance_tag_locked ( lf_scheduler_t * sched)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler_sync_tag_advance.h>

Advance the tag to the next tag on the event queue.

This will also pop events for the newly acquired tag and trigger the enabled reactions using the scheduler.

This function assumes the caller holds the environment mutex lock.

Parameters
schedThe scheduler instance to check.
Returns
True if the worker thread should exit. False otherwise.

◆ _lf_schedule_at_tag()

trigger_handle_t _lf_schedule_at_tag ( environment_t * env,
trigger_t * trigger,
tag_t tag,
lf_token_t * token )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Schedule an event at a specific tag (time, microstep).

If there is an event found at the requested tag, the payload is replaced and 0 is returned.

Note that this function is an internal API that must be called with a tag that is in the future relative to the current tag (or the environment has not started executing). Also, it must be called with tags that are in order for a given trigger. This means that the following order is illegal:

_lf_schedule_at_tag(env, trigger1, bigger_tag, ...);
_lf_schedule_at_tag(env, trigger1, smaller_tag, ...);
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).

where bigger_tag > smaller_tag. This function is primarily used for network communication (which is assumed to be in order).

This function assumes the caller holds the mutex lock.

Parameters
envEnvironment in which we are executing.
triggerThe trigger to be invoked at a later logical time.
tagLogical tag of the event
tokenThe token wrapping the payload or NULL for no payload.
Returns
A positive trigger handle for success, 0 if no new event was scheduled (instead, the payload was updated), or -1 for error (the tag is equal to or less than the current tag).

◆ _lf_schedule_copy()

trigger_handle_t _lf_schedule_copy ( environment_t * env,
void * action,
interval_t offset,
void * value,
size_t length )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Schedule an action to occur with the specified value and time offset with a copy of the specified value.

This is an internal API that is identical to lf_schedule_copy except that it takes an environment as an argument.

Parameters
envEnvironment in which we are executing.
actionThe action to be triggered (a pointer to an lf_action_base_t).
offsetThe time offset over and above that in the action.
valueA pointer to the value to copy.
lengthThe length, if an array, 1 if a scalar, and 0 if value is NULL.
Returns
A handle to the event, or 0 if no event was scheduled, or -1 for error.

◆ _lf_schedule_token()

trigger_handle_t _lf_schedule_token ( environment_t * env,
void * action,
interval_t extra_delay,
lf_token_t * token )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Schedule the specified action at a later tag with the specified token as a payload.

This is an internal API that is identical to lf_schedule_token except that it takes an environment as an argument.

Parameters
envEnvironment in which we are executing.
actionThe action to be triggered (a pointer to an lf_action_base_t).
extra_delayExtra offset of the event release above that in the action.
tokenThe token to carry the payload or null for no payload.
Returns
A handle to the event, or 0 if no event was scheduled, or -1 for error.

◆ _lf_start_time_step()

void _lf_start_time_step ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Perform whatever is needed to start a time step.

For example, this function resets outputs to be absent at the start of a new time step.

Parameters
envThe environment in which we are executing

◆ _lf_trigger_reaction()

void _lf_trigger_reaction ( environment_t * env,
reaction_t * reaction,
int worker_number )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Trigger the specified reaction on the specified worker in the specified environment.

Parameters
envEnvironment in which we are executing.
reactionThe reaction.
worker_numberThe ID of the worker that is making this call. 0 should be used if there is only one worker (e.g., when the program is using the single-threaded C runtime). -1 is used for an anonymous call in a context where a worker number does not make sense (e.g., the caller is not a worker thread).

◆ _lf_trigger_shutdown_reactions()

void _lf_trigger_shutdown_reactions ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Trigger all the shutdown reactions in the specified environment.

Parameters
envEnvironment in which we are executing.

◆ _lf_trigger_startup_reactions()

void _lf_trigger_startup_reactions ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Trigger all the startup reactions in the specified environment.

Parameters
envEnvironment in which we are executing.

◆ _lf_wait_on_tag_barrier()

int _lf_wait_on_tag_barrier ( environment_t * env,
tag_t proposed_tag )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Wait on the tag barrier for the environment.

If the proposed_tag is greater than or equal to a barrier tag that has been set by a call to _lf_increment_tag_barrier or _lf_increment_tag_barrier_locked, and if there are requestors still pending on that barrier, then wait until all requestors have been satisfied. This is used in federated execution when an incoming timed message has been partially read so that we know its tag, but the rest of message has not yet been read and hence the event has not yet appeared on the event queue. To prevent tardiness, this function blocks the advancement of time until to the proposed tag until the message has been put onto the event queue.

If the proposed_tag is greater than the stop tag, then use the stop tag instead.

This function assumes the mutex is already locked. Thus, it unlocks the mutex while it's waiting to allow the tag barrier to change.

Parameters
envEnvironment within which we are executing.
proposed_tagThe tag that the runtime wants to advance to.
Returns
0 if no wait was needed and 1 if a wait actually occurred.

◆ _lf_watchdog_terminate_all()

void _lf_watchdog_terminate_all ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/watchdog.h>

Terminates all watchdogs inside the environment.

This function is used to terminate all the watchdogs inside the environment.

Parameters
envThe environment to terminate the watchdogs for.

◆ call_tracepoint()

void call_tracepoint ( int event_type,
void * reactor,
tag_t tag,
int worker,
int src_id,
int dst_id,
instant_t * physical_time,
trigger_t * trigger,
interval_t extra_delay )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Pass the provided info to the tracing module.

Parameters
event_typeThe kind of tracepoint.
reactorA pointer used as an opaque ID of the source reactor, if one exists.
tagThe tag associated with the tracepoint.
workerThe worker thread where the tracepoint was reached.
src_idThe ID of the source federate/enclave, if applicable.
dst_idThe ID of the destination federate/enclave, if applicable.
physical_timeThe time at which the tracepoint was reached, or NULL if not applicable.
triggerThe trigger, if this tracepoint signifies scheduling of an event.
extra_delayThe delay passed to schedule(), if applicable.

◆ environment_free()

void environment_free ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

Free the dynamically allocated memory on the environment struct.

Parameters
envThe environment in which we are executing.

◆ environment_init()

int environment_init ( environment_t * env,
const char * name,
int id,
int num_workers,
int num_timers,
int num_startup_reactions,
int num_shutdown_reactions,
int num_reset_reactions,
int num_is_present_fields,
int num_modes,
int num_state_resets,
int num_watchdogs,
const char * trace_file_name )

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

Initialize an environment struct with parameters given in the arguments.

Parameters
envThe environment to initialize.
nameThe name of the environment.
idThe ID of the environment.
num_workersThe number of worker threads in the environment.
num_timersThe number of timer triggers in the environment.
num_startup_reactionsThe number of startup reactions in the environment.
num_shutdown_reactionsThe number of shutdown reactions in the environment.
num_reset_reactionsThe number of reset reactions in the environment.
num_is_present_fieldsThe number of is_present fields in the environment.
num_modesThe number of modes in the environment.
num_state_resetsThe number of state resets in the environment.
num_watchdogsThe number of watchdogs in the environment.
trace_file_nameThe name of the trace file to use.
Returns
int 0 on success, -1 on failure.

◆ environment_init_tags()

void environment_init_tags ( environment_t * env,
instant_t start_time,
interval_t duration )

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

Initialize the start and stop tags on the environment struct.

Parameters
envThe environment to initialize.
start_timeThe start time of the environment.
durationThe duration of the environment.

◆ environment_verify()

void environment_verify ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/environment.h>

Verify that the environment is correctly set up.

Parameters
envThe environment to verify.

◆ error()

void void void void error ( const char * msg)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Print the error defined by the errno variable with the specified message as a prefix, then exit with error code 1.

Parameters
msgThe prefix to the message.

◆ get_next_event_tag()

tag_t get_next_event_tag ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Return the tag of the next event on the event queue.

If the event queue is empty then return either FOREVER_TAG or, is a stop_time (timeout time) has been set, the stop time.

Parameters
envEnvironment within which we are executing.

◆ get_reaction_index()

pqueue_pri_t get_reaction_index ( void * reaction)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Report a priority equal to the index of the given reaction.

Used for sorting pointers to reaction_t structs in the blocked and executing queues.

Parameters
reactionA pointer to a reaction_t.

◆ get_reaction_position()

size_t get_reaction_position ( void * reaction)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Return the given reaction's position in the queue.

Parameters
reactionA pointer to a reaction_t.

◆ in_no_particular_order()

int in_no_particular_order ( pqueue_pri_t thiz,
pqueue_pri_t that )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Return 0 regardless of argument order.

Parameters
thizFirst argument.
thatSecond argument.

◆ in_reverse_order()

int in_reverse_order ( pqueue_pri_t thiz,
pqueue_pri_t that )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Return 1 if the first argument is greater than the second and zero otherwise.

Parameters
thizFirst argument.
thatSecond argument.

◆ initialize_global()

void initialize_global ( )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Initialize global variables and start tracing before calling the _lf_initialize_trigger_objects() function.

◆ lf_allocate()

void * lf_allocate ( size_t count,
size_t size,
struct allocation_record_t ** head )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor.h>

Allocate memory and record on the specified allocation record (a self struct).

This will allocate memory using calloc (so the allocated memory is zeroed out) and record the allocated memory on the specified self struct so that it will be freed when calling lf_free_reactor().

In a reaction body, you can access the head of the allocation records for the current reactor with &self->base.allocations.

Parameters
countThe number of items of size 'size' to accomodate.
sizeThe size of each item.
headPointer to the head of a list on which to record the allocation, or NULL to not record it (an allocation_record_t**).
Returns
A pointer to the allocated memory.

◆ lf_combine_deadline_and_level()

index_t lf_combine_deadline_and_level ( interval_t deadline,
int level )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Combine a deadline and a level into a single index for sorting in the reaction queue.

This shifts the deadline right by 16 bits and inserts the level in the low-order 16 bits. If the deadline is larger than ULLONG_MAX >> 16, then it is treated as the largest possible deadline.

Parameters
deadlineTHe deadline.
levelThe level in the reaction graph.

◆ lf_create_environments()

void lf_create_environments ( void )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Create and initialize the required number of environments for the program.

Note
This function will be code generated by the compiler.

◆ lf_delay_strict()

tag_t lf_delay_strict ( tag_t tag,
interval_t interval )

#include </Users/runner/work/reactor-c/reactor-c/tag/api/tag.h>

Return the latest tag strictly less than the specified tag plus the interval, unless tag is NEVER or interval is negative (including NEVER),.

in which case return the tag unmodified. Any interval less than 0 (including NEVER) is interpreted as "no delay", whereas an interval equal to 0 is interpreted as one microstep delay. If the time sum overflows, saturate the time value at FOREVER. For example:

  • if tag = (t, 0) and interval = 10, return (t + 10 - 1, UINT_MAX)
  • if tag = (t, 0) and interval = 0, return (t, 0)
  • if tag = (t, 0) and interval = NEVER, return (t, 0)
  • if tag = (FOREVER, 0) and interval = 10, return (FOREVER, 0)
Parameters
tagThe tag to increment.
intervalThe time interval.

◆ lf_fed_id()

uint16_t lf_fed_id ( void )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

Return the federate ID or -1 if this program is not part of a federation.

◆ lf_free()

void lf_free ( struct allocation_record_t ** head)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Free memory on the specified allocation record (a self struct).

This will mark the allocation record empty by setting *head to NULL. If the argument is NULL, do nothing.

Parameters
headPointer to the head of a list on which allocations are recorded.

◆ lf_free_all_reactors()

void lf_free_all_reactors ( void )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor.h>

Free all the reactors that are allocated with lf_new_reactor(size_t).

◆ lf_free_reactor()

void lf_free_reactor ( self_base_t * self)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor.h>

Free the specified reactor.

This will free the memory recorded on the allocations list of the specified reactor and then free the specified self struct.

Parameters
selfThe self struct of the reactor.

◆ lf_get_new_event()

event_t * lf_get_new_event ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Get a new event.

If there is a recycled event available, use that. If not, allocate a new one. In either case, all fields will be zero'ed out.

Parameters
envEnvironment in which we are executing.

◆ lf_new_reactor()

self_base_t * lf_new_reactor ( size_t size)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor.h>

Allocate memory for a new runtime instance of a reactor.

This records the reactor on the list of reactors to be freed at termination of the program. If you plan to free the reactor before termination of the program, use lf_allocate(size_t, size_t, allocation_record_t**) with a null last argument instead.

Parameters
sizeThe size of the self struct, obtained with sizeof().

◆ lf_print_snapshot()

void lf_print_snapshot ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor.h>

Print a snapshot of the priority queues used during execution (for debugging).

This function implementation will be empty if the NDEBUG macro is defined; that macro is normally defined for release builds.

Parameters
envThe environment in which we are executing, which you can access in a reaction body with self->base.environment.

◆ lf_recycle_event()

void lf_recycle_event ( environment_t * env,
event_t * e )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Recycle the given event.

This will zero out the event and push it onto the recycle queue.

Parameters
envEnvironment in which we are executing.
eThe event to recycle.

◆ lf_replace_token()

void lf_replace_token ( event_t * event,
lf_token_t * token )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Replace the token on the specified event with the specified token and free the old token.

Parameters
eventThe event.
tokenThe token.

◆ lf_sched_done_with_reaction()

void lf_sched_done_with_reaction ( size_t worker_number,
reaction_t * done_reaction )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler.h>

Inform the scheduler that worker thread 'worker_number' is done executing the 'done_reaction'.

Parameters
worker_numberThe worker number for the worker thread that has finished executing 'done_reaction'.
done_reactionThe reaction that is done.

◆ lf_sched_free()

void lf_sched_free ( lf_scheduler_t * scheduler)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler.h>

Free the memory used by the scheduler.

Parameters
schedulerThe scheduler

This must be called when the scheduler is no longer needed.

◆ lf_sched_get_ready_reaction()

reaction_t * lf_sched_get_ready_reaction ( lf_scheduler_t * scheduler,
int worker_number )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler.h>

Ask the scheduler for one more reaction.

This function blocks until it can return a ready reaction for worker thread 'worker_number' or it is time for the worker thread to stop and exit (where a NULL value would be returned). This function assumes that the environment mutex is not locked.

Parameters
schedulerThe scheduler
worker_numberFor the calling worker thread.
Returns
reaction_t* A reaction for the worker to execute. NULL if the calling worker thread should exit.

◆ lf_sched_init()

void lf_sched_init ( environment_t * env,
size_t number_of_workers,
sched_params_t * parameters )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler.h>

Initialize the scheduler.

This has to be called before other functions of the scheduler can be used. If the scheduler is already initialized, this will be a no-op.

Parameters
envThe environment in which we should initialize the scheduler
number_of_workersIndicate how many workers this scheduler will be managing.
parametersPointer to a sched_params_t struct containing additional scheduler parameters. Can be NULL.

◆ lf_schedule_trigger()

trigger_handle_t lf_schedule_trigger ( environment_t * env,
trigger_t * trigger,
interval_t delay,
lf_token_t * token )

#include </Users/runner/work/reactor-c/reactor-c/include/api/schedule.h>

Schedule the specified trigger to execute in the specified environment with given delay and token.

This is the most flexible version of the schedule functions and is used in the implementation of many of the others. End users would rarely use it.

This will schedule the specified trigger at env->current_tag.time plus the offset of the specified trigger plus the delay. The value is required to be either NULL or a pointer to a token wrapping the payload. The token carries a reference count, and when the reference count decrements to 0, the will be freed. Hence, it is essential that the payload be in memory allocated using malloc.

There are several conditions under which this function will not actually put an event on the event queue and decrement the reference count of the token (if there is one), which could result in the payload being freed. In all cases, this function returns 0. Otherwise, it returns a handle to the scheduled trigger, which is an integer greater than 0.

The first condition is that a stop has been requested and the trigger offset plus the extra delay is greater than zero. The second condition is that the trigger offset plus the extra delay is greater that the requested stop time (timeout). A third condition is that the trigger argument is null. Also, an event might not be scheduled if the trigger is an action with a min_spacing parameter. See the documentation.

Parameters
envThe environment in which to schedule the event.
triggerThe action or timer to be triggered.
delayOffset of the event release.
tokenThe token payload.
Returns
A handle to the event, or 0 if no event was scheduled, or -1 for error.

◆ lf_scheduler_trigger_reaction()

void lf_scheduler_trigger_reaction ( lf_scheduler_t * scheduler,
reaction_t * reaction,
int worker_number )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler.h>

Inform the scheduler that worker thread 'worker_number' would like to trigger 'reaction' at the current tag.

If a worker number is not available (e.g., this function is not called by a worker thread), -1 should be passed as the 'worker_number'.

The scheduler will ensure that the same reaction is not triggered twice in the same tag.

Parameters
schedulerThe scheduler.
reactionThe reaction to trigger at the current tag.
worker_numberThe ID of the worker that is making this call. 0 should be used if there is only one worker (e.g., when the program is using the single-threaded C runtime). -1 is used for an anonymous call in a context where a worker number does not make sense (e.g., the caller is not a worker thread).

◆ lf_semaphore_acquire()

void lf_semaphore_acquire ( lf_semaphore_t * semaphore)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/lf_semaphore.h>

Acquire the 'semaphore'.

Will block if count is 0.

Parameters
semaphoreInstance of a semaphore.

◆ lf_semaphore_destroy()

void lf_semaphore_destroy ( lf_semaphore_t * semaphore)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/lf_semaphore.h>

Destroy the 'semaphore'.

Parameters
semaphoreInstance of a semaphore.

◆ lf_semaphore_new()

lf_semaphore_t * lf_semaphore_new ( size_t count)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/lf_semaphore.h>

Create a new semaphore.

Parameters
countThe count to start with.
Returns
lf_semaphore_t* Can be NULL on error.

◆ lf_semaphore_release()

void lf_semaphore_release ( lf_semaphore_t * semaphore,
size_t i )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/lf_semaphore.h>

Release the 'semaphore' and add 'i' to its count.

Parameters
semaphoreInstance of a semaphore
iThe count to add.

◆ lf_semaphore_wait()

void lf_semaphore_wait ( lf_semaphore_t * semaphore)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/lf_semaphore.h>

Wait on the 'semaphore' if count is 0.

Parameters
semaphoreInstance of a semaphore.

◆ lf_set_default_command_line_options()

void lf_set_default_command_line_options ( void )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Generated function that optionally sets default command-line options.

◆ lf_set_stop_tag()

void lf_set_stop_tag ( environment_t * env,
tag_t tag )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor.h>

Set the stop tag if it is less than the stop tag of the specified environment.

Note
In threaded programs, the environment's mutex must be locked before calling this function.

◆ lf_tag_latest_earlier()

tag_t lf_tag_latest_earlier ( tag_t tag)

#include </Users/runner/work/reactor-c/reactor-c/tag/api/tag.h>

Return the greatest tag earlier than the given tag.

If the given tag is FOREVER_TAG or NEVER_TAG, however, just return the given tag.

Parameters
tagThe tag.

◆ lf_terminate_execution()

void lf_terminate_execution ( environment_t * env)

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Function that is called when the program is about to exit.

This function will be invoked after all shutdown actions have completed. For non-federated programs, the code generator generates an empty function to implement this. For federated programs, the function is implemented in federate.c.

Parameters
envThe environment in which we are executing

◆ lf_time_logical()

instant_t lf_time_logical ( void * env)

#include </Users/runner/work/reactor-c/reactor-c/tag/api/tag.h>

Return the current logical time in nanoseconds.

On many platforms, this is the number of nanoseconds since January 1, 1970, but it is actually platform dependent.

Parameters
envThe environment from which we want the current logical time.
Returns
A time instant.

◆ lf_time_logical_elapsed()

interval_t lf_time_logical_elapsed ( void * env)

#include </Users/runner/work/reactor-c/reactor-c/tag/api/tag.h>

Return the elapsed logical time in nanoseconds since the start of execution.

Parameters
envThe environment from which we want the elapsed logical time.
Returns
A time interval.

◆ lf_tracing_check_version()

void lf_tracing_check_version ( )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Check if the tracing library is compatible with the current version of the runtime.

◆ lf_vprint()

void lf_vprint ( const char * format,
va_list args )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

varargs alternative of "lf_print"

◆ lf_vprint_debug()

void void void lf_vprint_debug ( const char * format,
va_list args )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

varargs alternative of "lf_print_debug"

◆ lf_vprint_error()

void lf_vprint_error ( const char * format,
va_list args )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

varargs alternative of "lf_print_error"

◆ lf_vprint_error_and_exit()

void void void lf_vprint_error_and_exit ( const char * format,
va_list args )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

varargs alternative of "lf_print_error_and_exit"

◆ lf_vprint_log()

void void lf_vprint_log ( const char * format,
va_list args )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

varargs alternative of "lf_print_log"

◆ lf_vprint_warning()

void void lf_vprint_warning ( const char * format,
va_list args )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

varargs alternative of "lf_print_warning"

◆ logical_tag_complete()

void logical_tag_complete ( tag_t tag_to_send)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler_sync_tag_advance.h>

Placeholder for code-generated function that will, in a federated execution, be used to coordinate the advancement of tag.

It will notify the runtime infrastructure (RTI) that all reactions at the specified logical tag have completed.

This function should be called only while holding the mutex lock.

Parameters
tag_to_sendThe tag to send.

◆ mixed_radix_incr()

void mixed_radix_incr ( mixed_radix_int_t * mixed)

#include </Users/runner/work/reactor-c/reactor-c/include/core/mixed_radix.h>

Increment the mixed radix number by one according to the permutation matrix.

Parameters
mixedA pointer to the mixed-radix number.

◆ mixed_radix_parent()

int mixed_radix_parent ( mixed_radix_int_t * mixed,
int n )

#include </Users/runner/work/reactor-c/reactor-c/include/core/mixed_radix.h>

Return the int value of a mixed-radix number after dropping the first n digits.

If n is larger than or equal to the size of the mixed-radix number, then return 0.

Parameters
mixedA pointer to the mixed-radix number.
nThe number of digits to drop, which is assumed to be greater than or equal to 0.

◆ mixed_radix_to_int()

int mixed_radix_to_int ( mixed_radix_int_t * mixed)

#include </Users/runner/work/reactor-c/reactor-c/include/core/mixed_radix.h>

Return the int value of a mixed-radix number.

Parameters
mixedA pointer to the mixed-radix number.

◆ pqueue_empty_into()

void pqueue_empty_into ( pqueue_t ** dest,
pqueue_t ** src )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Empty 'src' into 'dest'.

As an optimization, this function might swap 'src' and 'dest'.

Parameters
destThe queue to fill up
srcThe queue to empty

◆ pqueue_find_equal_same_priority()

void * pqueue_find_equal_same_priority ( pqueue_t * q,
void * e )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Return an entry with the same priority (determined by cmppri) that matches the supplied entry (determined by eqelem) or NULL if there is no such entry.

Parameters
qThe queue
eThe entry to compare against
Returns
NULL if no matching event has been found, otherwise the entry

◆ pqueue_find_same_priority()

void * pqueue_find_same_priority ( pqueue_t * q,
void * e )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Return an entry with the same priority as the specified entry or NULL if there is no such entry.

Parameters
qThe queue
eThe entry to compare against
Returns
NULL if no matching event has been found, otherwise the entry

◆ pqueue_free()

void pqueue_free ( pqueue_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Free all memory used by the queue.

Parameters
qThe queue

◆ pqueue_init()

pqueue_t * pqueue_init ( size_t n,
pqueue_cmp_pri_f cmppri,
pqueue_get_pri_f getpri,
pqueue_get_pos_f getpos,
pqueue_set_pos_f setpos,
pqueue_eq_elem_f eqelem,
pqueue_print_entry_f prt )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Allocate and initialize a priority queue.

Parameters
nThe initial estimate of the number of queue items for which memory should be preallocated
cmppriThe callback function to run to compare two elements This callback should return -1 for 'lower', 0 for 'same', and 1 for 'higher', or vice versa if reverse priority is desired
getpriThe callback function to run to set a score to an element
getposThe callback function to get the current element's position
setposThe callback function to set the current element's position
eqelemthe callback function to check equivalence of entries
prtthe callback function to print an element
Returns
The handle or NULL for insufficent memory.

◆ pqueue_insert()

int pqueue_insert ( pqueue_t * q,
void * d )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Insert an element into the queue.

Parameters
qThe queue
dThe data to insert
Returns
0 on success

◆ pqueue_peek()

void * pqueue_peek ( pqueue_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Access highest-ranking item without removing it.

Parameters
qThe queue
Returns
NULL on error, otherwise the entry

◆ pqueue_pop()

void * pqueue_pop ( pqueue_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Pop the highest-ranking item from the queue.

Parameters
qThe queue
Returns
NULL on error, otherwise the entry

◆ pqueue_print()

void pqueue_print ( pqueue_t * q,
pqueue_print_entry_f print )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Print the contents of the queue.

Parameters
qThe queue.
printThe callback function to print the entry or NULL to use the default.

◆ pqueue_remove()

int pqueue_remove ( pqueue_t * q,
void * e )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Remove an item from the queue.

Parameters
qThe queue
eThe entry
Returns
0 on success

◆ pqueue_size()

size_t pqueue_size ( pqueue_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>

Return the size of the queue.

Parameters
qThe queue

◆ pqueue_tag_compare()

int pqueue_tag_compare ( pqueue_pri_t priority1,
pqueue_pri_t priority2 )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Callback comparison function for the tag-based priority queue.

Parameters
priority1A pointer to a pqueue_tag_element_t, cast to pqueue_pri_t.
priority2A pointer to a pqueue_tag_element_t, cast to pqueue_pri_t.
Returns
-1 if the first argument is less than second, 0 if the two arguments are the same, and 1 otherwise.

◆ pqueue_tag_find_equal_same_tag()

pqueue_tag_element_t * pqueue_tag_find_equal_same_tag ( pqueue_tag_t * q,
pqueue_tag_element_t * e )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Return an item with the same tag (cmppri returns 0) that matches the supplied element (eqelem returns non-zero) or NULL if there is none.

Parameters
qThe queue.
eThe element.
Returns
An entry with the specified tag or NULL if there isn't one.

◆ pqueue_tag_find_with_tag()

pqueue_tag_element_t * pqueue_tag_find_with_tag ( pqueue_tag_t * q,
tag_t t )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Return the first item with the specified tag or NULL if there is none.

Parameters
qThe queue.
tThe tag.
Returns
An entry with the specified tag or NULL if there isn't one.

◆ pqueue_tag_free()

void pqueue_tag_free ( pqueue_tag_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Free all memory used by the queue including elements that are marked dynamic.

Parameters
qThe queue.

◆ pqueue_tag_init()

pqueue_tag_t * pqueue_tag_init ( size_t initial_size)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Create a priority queue sorted by tags.

The elements of the priority queue will be of type pqueue_tag_element_t. The caller should call pqueue_tag_free() when finished with the queue.

Parameters
initial_sizeThe initial size of the priority queue.
Returns
A dynamically allocated priority queue or NULL if memory allocation fails.

◆ pqueue_tag_init_customize()

pqueue_tag_t * pqueue_tag_init_customize ( size_t initial_size,
pqueue_cmp_pri_f cmppri,
pqueue_eq_elem_f eqelem,
pqueue_print_entry_f prt )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Create a priority queue that stores elements with a particular payload.

The elements of the priority queue will be of type pqueue_tag_element_t. The caller should call pqueue_tag_free() when finished with the queue.

Parameters
initial_sizeThe initial size of the priority queue.
cmppriThe callback function to compare priorities.
eqelemThe callback function to check equivalence of payloads.
prtThe callback function to print elements.
Returns
A dynamically allocated priority queue or NULL if memory allocation fails.

◆ pqueue_tag_insert()

int pqueue_tag_insert ( pqueue_tag_t * q,
pqueue_tag_element_t * d )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Insert an element into the queue.

Parameters
qThe queue.
dThe element to insert.
Returns
0 on success

◆ pqueue_tag_insert_if_no_match()

int pqueue_tag_insert_if_no_match ( pqueue_tag_t * q,
tag_t t )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Insert a tag into the queue if the tag is not already in the queue.

This automatically creates a dynamically allocated element in the queue and ensures that if the element is still on the queue when pqueue_tag_free is called, then that memory will be freed.

Parameters
qThe queue.
tThe tag to insert.
Returns
0 on success, 1 otherwise.

◆ pqueue_tag_insert_tag()

int pqueue_tag_insert_tag ( pqueue_tag_t * q,
tag_t t )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Insert a tag into the queue.

This automatically creates a dynamically allocated element in the queue and ensures that if the element is still on the queue when pqueue_tag_free is called, then that memory will be freed.

Parameters
qThe queue.
tThe tag to insert.
Returns
0 on success

◆ pqueue_tag_peek()

pqueue_tag_element_t * pqueue_tag_peek ( pqueue_tag_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Return highest-ranking item (the one with the least tag) without removing it.

Parameters
qThe queue.
Returns
NULL on if the queue is empty, otherwise the entry.

◆ pqueue_tag_peek_tag()

tag_t pqueue_tag_peek_tag ( pqueue_tag_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Return the least tag in the queue or FOREVER if the queue is empty.

Parameters
qThe queue.
Returns
The least tag in the queue or FOREVER if the queue is empty.

◆ pqueue_tag_pop()

pqueue_tag_element_t * pqueue_tag_pop ( pqueue_tag_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Pop the least-tag element from the queue.

If the entry was dynamically allocated, then it is now up to the caller to ensure that it is freed. It will not be freed by pqueue_tag_free.

Parameters
qThe queue.
Returns
NULL on error, otherwise the entry

◆ pqueue_tag_pop_tag()

tag_t pqueue_tag_pop_tag ( pqueue_tag_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Pop the least-tag element from the queue and return its tag.

If the queue is empty, return FOREVER_TAG. This function handles freeing the element struct if it was dynamically allocated.

Parameters
qThe queue.
Returns
NULL on error, otherwise the entry

◆ pqueue_tag_remove()

void pqueue_tag_remove ( pqueue_tag_t * q,
pqueue_tag_element_t * e )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Remove an item from the queue.

Parameters
qThe queue.
eThe entry to remove.

◆ pqueue_tag_remove_up_to()

void pqueue_tag_remove_up_to ( pqueue_tag_t * q,
tag_t t )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Remove items from the queue with tags up to and including the specified tag.

If the specified tag is FOREVER_TAG, then all items will be removed.

Parameters
qThe queue.
tThe specified tag.

◆ pqueue_tag_size()

size_t pqueue_tag_size ( pqueue_tag_t * q)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_tag.h>

Return the size of the queue.

Parameters
qThe queue.

◆ print_reaction()

void print_reaction ( void * reaction)

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Print some information about the given reaction.

This only prints something if logging is set to DEBUG.

Parameters
reactionA pointer to a reaction_t.

◆ process_args()

int process_args ( int argc,
const char * argv[] )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Process the command-line arguments.

Parameters
argcThe number of command-line arguments.
argvThe command-line arguments.

◆ reaction_matches()

int reaction_matches ( void * a,
void * b )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Return 1 if the two arguments are identical pointers.

Parameters
aFirst argument.
bSecond argument.

◆ schedule_output_reactions()

void schedule_output_reactions ( environment_t * env,
reaction_t * reaction,
int worker )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Schedule the output reactions for the specified reaction in the specified environment.

Parameters
envThe environment in which we are executing.
reactionThe reaction.
workerThe worker number.

◆ send_next_event_tag()

tag_t send_next_event_tag ( environment_t * env,
tag_t tag,
bool wait_for_reply )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Send the next event tag.

In a federated execution with centralized coordination, this function returns a tag that is less than or equal to the specified tag when, as far as the federation is concerned, it is safe to commit to advancing to the returned tag. That is, all incoming network messages with tags less than the returned tag have been received. In unfederated execution or in federated execution with decentralized control, this function returns the specified tag immediately.

Parameters
envEnvironment within which we are executing.
tagThe tag to which to advance.
wait_for_replyIf true, wait for the RTI to respond.
Returns
The tag to which it is safe to advance.

◆ set_reaction_position()

void set_reaction_position ( void * reaction,
size_t pos )

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue.h>

Set the given reaction's position in the queue.

Parameters
reactionA pointer to a reaction_t.
posThe position.

◆ should_stop_locked()

bool should_stop_locked ( lf_scheduler_t * sched)

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/scheduler_sync_tag_advance.h>

Return true if the worker should stop now; false otherwise.

This function assumes the caller holds the mutex lock.

Parameters
schedThe scheduler instance to check.

◆ termination()

void termination ( void )

#include </Users/runner/work/reactor-c/reactor-c/include/core/reactor_common.h>

Perform final wrap-up on exit.

This function will be registered to execute on exit. It reports elapsed logical and physical times and reports if any memory allocated for tokens has not been freed.

◆ tracepoint_schedule()

void tracepoint_schedule ( environment_t * env,
trigger_t * trigger,
interval_t extra_delay )

#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>

Trace a call to schedule.

Parameters
envThe environment in which we are executing
triggerPointer to the trigger_t struct for the trigger.
extra_delayThe extra delay passed to schedule().

◆ wait_until()

bool wait_until ( instant_t wait_until_time,
lf_cond_t * condition )

#include </Users/runner/work/reactor-c/reactor-c/include/core/threaded/reactor_threaded.h>

Wait until physical time matches or exceeds the time of the specified tag.

If -fast is given, there will be no wait.

If an event is put on the event queue during the wait, then the wait is interrupted and this function returns false. It also returns false if the timeout time is reached before the wait has completed. Note this this could return true even if the a new event was placed on the queue. This will occur if that event time matches or exceeds the specified time.

The mutex lock associated with the condition argument is assumed to be held by the calling thread. This mutex is released while waiting. If the current physical time has already passed the specified time, then this function immediately returns true and the mutex is not released.

Parameters
wait_until_timeThe time to wait until physical time matches it.
conditionA condition variable that can interrupt the wait. The mutex associated with this condition variable will be released during the wait.
Returns
Return false if the wait is interrupted either because of an event queue signal or if the wait time was interrupted early by reaching the stop time, if one was specified. Return true if the full wait time was reached.

Variable Documentation

◆ _lf_count_token_allocations

int _lf_count_token_allocations
extern

#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_token.h>

Counter used to issue a warning if memory is allocated for tokens and never freed.

Note that every trigger will have one token allocated for it. That token is not counted because it is not expected to be freed.

◆ _lf_my_fed_id

uint16_t _lf_my_fed_id
extern

#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>

The ID of this federate.

For a non-federated execution, this will be -1. For a federated execution, it will be assigned when the generated function _lf_initialize_trigger_objects() is called.

See also
xtext/org.icyphy.linguafranca/src/org/icyphy/generator/CGenerator.xtend.