reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
reactor.h File Reference

Definitions for the C target of Lingua Franca shared by threaded and unthreaded versions. More...

#include "lf_types.h"
#include "modes.h"
#include "port.h"
#include "tag.h"
#include "clock.h"
#include "tracepoint.h"
#include "util.h"

Go to the source code of this file.

Macros

#define SUPPRESS_UNUSED_WARNING(x)
 Macro to suppress warnings about unused variables.
 

Functions

bool lf_is_tag_after_stop_tag (environment_t *env, tag_t tag)
 Return true if the provided tag is after stop tag.
 
void lf_set_present (lf_port_base_t *port)
 Mark the given port's is_present field as true.
 
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.
 
void lf_print_snapshot (environment_t *env)
 Print a snapshot of the priority queues used during execution (for debugging).
 
void lf_request_stop (void)
 Request a stop to execution as soon as possible.
 
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).
 
self_base_tlf_new_reactor (size_t size)
 Allocate memory for a new runtime instance of a reactor.
 
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.
 

Detailed Description

Definitions for the C target of Lingua Franca shared by threaded and unthreaded versions.

Author
Edward A. Lee
Marten Lohstroh
Chris Gill
Mehrdad Niknami

This header file defines functions that programmers use in the body of reactions for reading and writing inputs and outputs and scheduling future events. Other functions that might be useful to application programmers are also defined here.

Many of these functions have macro wrappers defined in reaction_macros.h.

Macro Definition Documentation

◆ SUPPRESS_UNUSED_WARNING

#define SUPPRESS_UNUSED_WARNING ( x)
Value:
(void)(x)

Macro to suppress warnings about unused variables.

Function Documentation

◆ lf_allocate()

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).

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 free_reactor(self_base_t).

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

◆ lf_free_all_reactors()

void lf_free_all_reactors ( void )

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

◆ lf_free_reactor()

void lf_free_reactor ( self_base_t * self)

Free the specified reactor.

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

Parameters
selfThe self struct of the reactor.

◆ lf_is_tag_after_stop_tag()

bool lf_is_tag_after_stop_tag ( environment_t * env,
tag_t tag )

Return true if the provided tag is after stop tag.

Parameters
envEnvironment in which we are executing.
tagThe tag to check against stop tag

◆ lf_new_reactor()

self_base_t * lf_new_reactor ( size_t size)

Allocate memory for a new runtime instance of a reactor.

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

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

◆ lf_print_snapshot()

void lf_print_snapshot ( environment_t * env)

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

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

Parameters
envThe environment in which we are executing.

◆ lf_request_stop()

void lf_request_stop ( void )

Request a stop to execution as soon as possible.

In a non-federated execution with only a single enclave, this will occur one microstep later than the current tag. In a federated execution or when there is more than one enclave, it will likely occur at a later tag determined by the RTI so that all federates and enclaves stop at the same tag.

◆ lf_set_present()

void lf_set_present ( lf_port_base_t * port)

Mark the given port's is_present field as true.

Parameters
portA pointer to the port struct as an lf_port_base_t*.

◆ lf_set_stop_tag()

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.

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