![]() |
reactor-c 1.0
C Runtime for Lingua Franca
|
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_t * | lf_get_new_event (environment_t *env) |
| Get a new event. | |
| self_base_t * | lf_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_t * | lf_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_t * | lf_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_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) |
| 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_t * | pqueue_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_t * | pqueue_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_t * | pqueue_tag_init (size_t initial_size) |
| Create a priority queue sorted by tags. | |
| 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) |
| 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_t * | pqueue_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_t * | pqueue_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. | |
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.
| #define CONCATENATE_THREE_STRINGS | ( | __string1, | |
| __string2, | |||
| __string3 ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
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.
| #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.
| #define LF_COND_BROADCAST | ( | cond | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Broadcast a condition variable with error checking.
This is optimized away if the NDEBUG flag is defined.
| cond | Pointer to the condition variable. |
| #define LF_COND_INIT | ( | cond, | |
| mutex ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Initialize condition variable with error checking.
This is optimized away if the NDEBUG flag is defined.
| cond | Pointer to the condition variable to initialize. |
| mutex | Pointer to the mutex to associate with the condition variable. |
| #define LF_COND_SIGNAL | ( | cond | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Signal a condition variable with error checking.
This is optimized away if the NDEBUG flag is defined.
| cond | Pointer to the condition variable. |
| #define LF_COND_WAIT | ( | cond | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Wait on a condition variable with error checking.
This is optimized away if the NDEBUG flag is defined.
| cond | Pointer to the condition variable. |
| #define LF_CRITICAL_SECTION_ENTER | ( | env | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Enter critical section with error checking.
This is optimized away if the NDEBUG flag is defined.
| env | Pointer to the environment. |
| #define LF_CRITICAL_SECTION_EXIT | ( | env | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Exit critical section with error checking.
This is optimized away if the NDEBUG flag is defined.
| env | Pointer to the environment. |
| #define LF_LEVEL | ( | index | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
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.
| #define LF_MAX | ( | X, | |
| Y ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Utility for finding the maximum of two values.
| #define LF_MIN | ( | X, | |
| Y ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Utility for finding the minimum of two values.
| #define LF_MUTEX_INIT | ( | mutex | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Initialize mutex with error checking.
This is optimized away if the NDEBUG flag is defined.
| mutex | Pointer to the mutex to initialize. |
| #define LF_MUTEX_LOCK | ( | mutex | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Lock mutex with error checking.
This is optimized away if the NDEBUG flag is defined.
| mutex | Pointer to the mutex to lock. |
| #define LF_MUTEX_UNLOCK | ( | mutex | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/util.h>
Unlock mutex with error checking.
This is optimized away if the NDEBUG flag is defined.
| mutex | Pointer to the mutex to unlock. |
| #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.
| #define SCHED_ADAPTIVE 1 |
#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>
Experimental adaptive scheduler.
| #define SCHED_GEDF_NP 2 |
#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>
Experimental GEDF-NP scheduler.
| #define SCHED_NP 3 |
#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>
Default non-preemptive scheduler.
| #define tracepoint_reaction_deadline_missed | ( | env, | |
| reaction, | |||
| worker ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the occurrence of a deadline miss.
| env | The environment in which we are executing |
| reaction | Pointer to the reaction_t struct for the reaction. |
| worker | The thread number of the worker thread or 0 for single-threaded execution. |
| #define tracepoint_reaction_ends | ( | env, | |
| reaction, | |||
| worker ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the end of a reaction execution.
| env | The environment in which we are executing |
| reaction | Pointer to the reaction_t struct for the reaction. |
| worker | The thread number of the worker thread or 0 for single-threaded execution. |
| #define tracepoint_reaction_starts | ( | env, | |
| reaction, | |||
| worker ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the start of a reaction execution.
| env | The environment in which we are executing |
| reaction | Pointer to the reaction_t struct for the reaction. |
| worker | The thread number of the worker thread or 0 for single-threaded execution. |
| #define tracepoint_scheduler_advancing_time_ends | ( | env | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the end of the scheduler waiting for logical time to advance or an event to appear on the event queue.
| env | The environment in which we are executing |
| #define tracepoint_scheduler_advancing_time_starts | ( | env | ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the start of the scheduler waiting for logical time to advance or an event to appear on the event queue.
| env | The environment in which we are executing |
| #define tracepoint_worker_wait_ends | ( | env, | |
| worker ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the end of a worker waiting for something to change on the event or reaction queue.
| env | The environment in which we are executing |
| worker | The thread number of the worker thread or 0 for single-threaded execution. |
| #define tracepoint_worker_wait_starts | ( | env, | |
| worker ) |
#include </Users/runner/work/reactor-c/reactor-c/include/core/tracepoint.h>
Trace the start of a worker waiting for something to change on the reaction queue.
| env | The environment in which we are executing |
| worker | The thread number of the worker thread or 0 for single-threaded execution. |
| 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).
| 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.
| 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.
| typedef pqueue_pri_t index_t |
#include </Users/runner/work/reactor-c/reactor-c/include/core/lf_types.h>
Topological order index for reactions.
| 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().
| 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.
| 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.
| 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).
| 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.
| 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.
| 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.
| 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.
| 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.
| typedef unsigned long long pqueue_pri_t |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>
Priority data type.
| 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.
| 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.
| typedef struct pqueue_t pqueue_t |
#include </Users/runner/work/reactor-c/reactor-c/include/core/utils/pqueue_base.h>
The priority queue struct.
| typedef 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.
| 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.
| 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.
| typedef enum token_freed 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| enum 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 | |
| enum 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).
| Enumerator | |
|---|---|
| absent | |
| present | |
| unknown | |
| enum 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.
| Enumerator | |
|---|---|
| inactive | |
| queued | |
| running | |
| enum 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 | |
| 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.
| env | The environment in which we are executing |
| next_tag | The tag step to advance to. |
| 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.
| env | Environment in which we are executing. |
| tag | The tag of that event. |
| 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.
| env | The environment in which we are executing. |
| 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.
| token | Pointer to a token. |
| 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.
| 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.
| token | Pointer to a token. |
| 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.
| 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.
| envs | A double pointer which will be dereferenced and modified |
| 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.
| tmplt | The template. // template is a C++ keyword. |
| 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.
| env | Environment within which we are executing. |
| future_tag | A 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. |
| 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.
| env | Environment within which we are executing. |
| future_tag | A 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. |
| 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.
| tmplt | The template. // template is a C++ keyword. |
| element_size | The element size. |
| 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.
| env | Environment in which we are executing. |
| timer | The timer to initialize. |
| 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.
| env | Environment in which we are executing. |
| 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.
| tmplt | The token template (must not be NULL). // template is a C++ keyword. |
| length | The length of the array, or 1 if it is not an array. |
| 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.
| tmplt | A template for the token. // template is a C++ keyword. |
| value | The value of the array. |
| length | The length of the array, or 1 if it is not an array. |
| 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).
| 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.
| env | The environment to initialize the watchdogs for. |
| 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.
| env | Environment in which we are executing. |
| trigger | The trigger. |
| token | The token wrapping the payload or NULL for no payload. |
| 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.
| env | The environment in which we are executing. |
| reaction | The reaction. |
| worker | The worker number. |
| 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.
| port | An array of pointers to port structs. |
| width | The width of the multiport (or a negative number if not a multiport). |
| 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.
| type | The type of the token. |
| value | The value, or NULL to have no value. |
| length | The array length of the value, 1 to not be an array, or 0 to have no value. |
| 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.
| env | Environment within which we are executing. |
| 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.
| env | The environment in which we are executing |
| 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.
| pointer1 | Pointer that identifies the object, typically to a reactor self struct. |
| pointer2 | Further identifying pointer, typically to a trigger (action or timer) or NULL if irrelevant. |
| type | The type of trace object. |
| description | The human-readable description of the object. |
| 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.
| tmplt | Pointer to a template. // template is a C++ keyword. |
| newtoken | The replacement token. |
| 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.
| sched | The scheduler instance to check. |
| 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:
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.
| env | Environment in which we are executing. |
| trigger | The trigger to be invoked at a later logical time. |
| tag | Logical tag of the event |
| token | The token wrapping the payload or NULL for no payload. |
| 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.
| env | Environment in which we are executing. |
| action | The action to be triggered (a pointer to an lf_action_base_t). |
| offset | The time offset over and above that in the action. |
| value | A pointer to the value to copy. |
| length | The length, if an array, 1 if a scalar, and 0 if value is NULL. |
| 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.
| env | Environment in which we are executing. |
| action | The action to be triggered (a pointer to an lf_action_base_t). |
| extra_delay | Extra offset of the event release above that in the action. |
| token | The token to carry the payload or null for no payload. |
| 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.
| env | The environment in which we are executing |
| 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.
| env | Environment in which we are executing. |
| reaction | The reaction. |
| worker_number | The 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). |
| 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.
| env | Environment in which we are executing. |
| 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.
| env | Environment in which we are executing. |
| 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.
| env | Environment within which we are executing. |
| proposed_tag | The tag that the runtime wants to advance to. |
| 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.
| env | The environment to terminate the watchdogs for. |
| 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.
| event_type | The kind of tracepoint. |
| reactor | A pointer used as an opaque ID of the source reactor, if one exists. |
| tag | The tag associated with the tracepoint. |
| worker | The worker thread where the tracepoint was reached. |
| src_id | The ID of the source federate/enclave, if applicable. |
| dst_id | The ID of the destination federate/enclave, if applicable. |
| physical_time | The time at which the tracepoint was reached, or NULL if not applicable. |
| trigger | The trigger, if this tracepoint signifies scheduling of an event. |
| extra_delay | The delay passed to schedule(), if applicable. |
| 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.
| env | The environment in which we are executing. |
| 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.
| env | The environment to initialize. |
| name | The name of the environment. |
| id | The ID of the environment. |
| num_workers | The number of worker threads in the environment. |
| num_timers | The number of timer triggers in the environment. |
| num_startup_reactions | The number of startup reactions in the environment. |
| num_shutdown_reactions | The number of shutdown reactions in the environment. |
| num_reset_reactions | The number of reset reactions in the environment. |
| num_is_present_fields | The number of is_present fields in the environment. |
| num_modes | The number of modes in the environment. |
| num_state_resets | The number of state resets in the environment. |
| num_watchdogs | The number of watchdogs in the environment. |
| trace_file_name | The name of the trace file to use. |
| 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.
| env | The environment to initialize. |
| start_time | The start time of the environment. |
| duration | The duration of the environment. |
| 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.
| env | The environment to verify. |
| 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.
| msg | The prefix to the message. |
| 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.
| env | Environment within which we are executing. |
| 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.
| reaction | A pointer to a reaction_t. |
| 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.
| reaction | A pointer to a reaction_t. |
| 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.
| thiz | First argument. |
| that | Second argument. |
| 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.
| thiz | First argument. |
| that | Second argument. |
| 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.
| 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.
| count | The number of items of size 'size' to accomodate. |
| size | The size of each item. |
| head | Pointer to the head of a list on which to record the allocation, or NULL to not record it (an allocation_record_t**). |
| 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.
| deadline | THe deadline. |
| level | The level in the reaction graph. |
| 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.
| 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:
| tag | The tag to increment. |
| interval | The time interval. |
| 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.
| 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.
| head | Pointer to the head of a list on which allocations are recorded. |
| 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).
| 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.
| self | The self struct of the reactor. |
| 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.
| env | Environment in which we are executing. |
| 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.
| size | The size of the self struct, obtained with sizeof(). |
| 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.
| env | The environment in which we are executing, which you can access in a reaction body with self->base.environment. |
| 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.
| env | Environment in which we are executing. |
| e | The event to recycle. |
| 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.
| event | The event. |
| token | The token. |
| 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'.
| worker_number | The worker number for the worker thread that has finished executing 'done_reaction'. |
| done_reaction | The reaction that is done. |
| 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.
| scheduler | The scheduler |
This must be called when the scheduler is no longer needed.
| 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.
| scheduler | The scheduler |
| worker_number | For the calling worker thread. |
| 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.
| env | The environment in which we should initialize the scheduler |
| number_of_workers | Indicate how many workers this scheduler will be managing. |
| parameters | Pointer to a sched_params_t struct containing additional scheduler parameters. Can be NULL. |
| 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.
| env | The environment in which to schedule the event. |
| trigger | The action or timer to be triggered. |
| delay | Offset of the event release. |
| token | The token payload. |
| 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.
| scheduler | The scheduler. |
| reaction | The reaction to trigger at the current tag. |
| worker_number | The 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). |
| 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.
| semaphore | Instance of a semaphore. |
| 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'.
| semaphore | Instance of a semaphore. |
| 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.
| count | The count to start with. |
| 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.
| semaphore | Instance of a semaphore |
| i | The count to add. |
| 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.
| semaphore | Instance of a semaphore. |
| 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.
| 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.
#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.
| tag | The tag. |
| 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.
| env | The environment in which we are executing |
| 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.
| env | The environment from which we want the current logical time. |
| 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.
| env | The environment from which we want the elapsed logical time. |
| 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.
| 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"
| 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"
| 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"
| 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"
| 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"
| 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"
| 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.
| tag_to_send | The tag to send. |
| 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.
| mixed | A pointer to the mixed-radix number. |
| 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.
| mixed | A pointer to the mixed-radix number. |
| n | The number of digits to drop, which is assumed to be greater than or equal to 0. |
| 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.
| mixed | A pointer to the mixed-radix number. |
#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'.
| dest | The queue to fill up |
| src | The queue to empty |
| 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.
| q | The queue |
| e | The entry to compare against |
| 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.
| q | The queue |
| e | The entry to compare against |
| 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.
| q | The queue |
| 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.
| n | The initial estimate of the number of queue items for which memory should be preallocated |
| cmppri | The 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 |
| getpri | The callback function to run to set a score to an element |
| getpos | The callback function to get the current element's position |
| setpos | The callback function to set the current element's position |
| eqelem | the callback function to check equivalence of entries |
| prt | the callback function to print an element |
| 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.
| q | The queue |
| d | The data to insert |
| 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.
| q | The queue |
| 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.
| q | The queue |
| 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.
| q | The queue. |
| The callback function to print the entry or NULL to use the default. |
| 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.
| q | The queue |
| e | The entry |
| 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.
| q | The queue |
| 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.
| priority1 | A pointer to a pqueue_tag_element_t, cast to pqueue_pri_t. |
| priority2 | A pointer to a pqueue_tag_element_t, cast to pqueue_pri_t. |
| 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.
| q | The queue. |
| e | The element. |
| 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.
| q | The queue. |
| t | The tag. |
| 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.
| q | The queue. |
| 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.
| initial_size | The initial size of the priority queue. |
| 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.
| initial_size | The initial size of the priority queue. |
| cmppri | The callback function to compare priorities. |
| eqelem | The callback function to check equivalence of payloads. |
| prt | The callback function to print elements. |
| 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.
| q | The queue. |
| d | The element to insert. |
| 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.
| q | The queue. |
| t | The tag to insert. |
| 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.
| q | The queue. |
| t | The tag to insert. |
| 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.
| q | The queue. |
| 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.
| q | The queue. |
| 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.
| q | The queue. |
| 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.
| q | The queue. |
| 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.
| q | The queue. |
| e | The entry to remove. |
| 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.
| q | The queue. |
| t | The specified tag. |
| 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.
| q | The queue. |
| 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.
| reaction | A pointer to a reaction_t. |
| 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.
| argc | The number of command-line arguments. |
| argv | The command-line arguments. |
| 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.
| a | First argument. |
| b | Second argument. |
| 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.
| env | The environment in which we are executing. |
| reaction | The reaction. |
| worker | The worker number. |
| 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.
| env | Environment within which we are executing. |
| tag | The tag to which to advance. |
| wait_for_reply | If true, wait for the RTI to respond. |
| 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.
| reaction | A pointer to a reaction_t. |
| pos | The position. |
| 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.
| sched | The scheduler instance to check. |
| 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.
| 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.
| env | The environment in which we are executing |
| trigger | Pointer to the trigger_t struct for the trigger. |
| extra_delay | The extra delay passed to schedule(). |
| 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.
| wait_until_time | The time to wait until physical time matches it. |
| condition | A condition variable that can interrupt the wait. The mutex associated with this condition variable will be released during the wait. |
|
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.
|
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.