reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
lf_token.h
Go to the documentation of this file.
1
40#ifndef LF_TOKEN_H
41#define LF_TOKEN_H
42
43#include <stdlib.h> // Defines size_t
44
45// Forward declarations
46struct environment_t;
47
50
52typedef enum token_freed {
53 NOT_FREED = 0, // Nothing was freed.
54 VALUE_FREED, // The value (payload) was freed.
55 TOKEN_FREED, // The token was freed but not the value.
56 TOKEN_AND_VALUE_FREED // Both were freed
58
61
67typedef struct token_type_t {
71 void (*destructor)(void* value);
73 void* (*copy_constructor)(void* value);
75
106
110typedef struct lf_sparse_io_record_t {
111 int size; // -1 if overflowed. 0 if empty.
112 size_t capacity; // Max number of writes to be considered sparse.
113 size_t* present_channels; // Array of channel indices that are present.
115
121typedef struct token_template_t {
125 size_t length; // The token's length, for convenient access in reactions.
127
128// Forward declaration for self_base_t
130
140typedef struct lf_port_base_t {
141 token_template_t tmplt; // Type and token information (template is a C++ keyword).
143 lf_sparse_io_record_t* sparse_record; // NULL if there is no sparse record.
144 int destination_channel; // -1 if there is no destination.
145 int num_destinations; // The number of destination reactors this port writes to.
146 self_base_t* source_reactor; // Pointer to the self struct of the reactor that provides data to this port.
147 // If this is an input, that reactor will normally be the container of the
148 // output port that sends it data.
150
153
162
165
184lf_token_t* lf_new_token(void* port_or_action, void* val, size_t len);
185
201
204
220
234lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length);
235
246
257void _lf_initialize_template(token_template_t* tmplt, size_t element_size);
258
275lf_token_t* _lf_initialize_token_with_value(token_template_t* tmplt, void* value, size_t length);
276
294lf_token_t* _lf_initialize_token(token_template_t* tmplt, size_t length);
295
302
311
323
330void _lf_free_token_copies(void);
331
332#endif /* LF_TOKEN_H */
token_freed _lf_free_token(lf_token_t *token)
Free the specified token, if appropriate. If the reference count is greater than 0,...
Definition lf_token.c:165
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. This will attempt to get one from the ...
Definition lf_token.c:204
struct token_type_t token_type_t
Type information for tokens. Specifically, this struct contains the fields needed to support token ty...
void _lf_initialize_template(token_template_t *tmplt, size_t element_size)
Definition lf_token.c:256
lf_token_t * _lf_initialize_token(token_template_t *tmplt, size_t length)
Definition lf_token.c:298
token_freed _lf_done_using(lf_token_t *token)
Definition lf_token.c:353
lf_token_t * _lf_get_token(token_template_t *tmplt)
Definition lf_token.c:239
struct lf_port_base_t lf_port_base_t
Base type for ports. Port structs are customized types because their payloads are type specific....
struct lf_token_t lf_token_t
lf_token_t * lf_new_token(void *port_or_action, void *val, size_t len)
Return a new disassociated token with type matching the specified port or action and containing the s...
Definition lf_token.c:72
struct lf_sparse_io_record_t lf_sparse_io_record_t
lf_token_t * lf_writable_copy(lf_port_base_t *port)
Definition lf_token.c:76
void _lf_free_token_copies(void)
Free token copies made for mutable inputs. This function should be called at the beginning of each ti...
Definition lf_token.c:366
token_freed
Definition lf_token.h:52
@ TOKEN_AND_VALUE_FREED
Definition lf_token.h:56
@ TOKEN_FREED
Definition lf_token.h:55
@ NOT_FREED
Definition lf_token.h:53
@ VALUE_FREED
Definition lf_token.h:54
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. If the new token is the...
Definition lf_token.c:337
lf_token_t * _lf_initialize_token_with_value(token_template_t *tmplt, void *value, size_t length)
Definition lf_token.c:282
struct token_template_t token_template_t
Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens....
int _lf_count_token_allocations
Definition lf_token.c:15
void _lf_free_all_tokens()
Free all tokens. Free tokens on the _lf_token_recycling_bin hashset and all template tokens.
Definition lf_token.c:306
Execution environment. This struct contains information about the execution environment....
Definition environment.h:49
Base type for ports. Port structs are customized types because their payloads are type specific....
Definition lf_token.h:140
lf_sparse_io_record_t * sparse_record
Definition lf_token.h:143
self_base_t * source_reactor
Definition lf_token.h:146
bool is_present
Definition lf_token.h:142
int destination_channel
Definition lf_token.h:144
int num_destinations
Definition lf_token.h:145
token_template_t tmplt
Definition lf_token.h:141
Definition lf_token.h:110
size_t capacity
Definition lf_token.h:112
int size
Definition lf_token.h:111
size_t * present_channels
Definition lf_token.h:113
Definition lf_token.h:94
struct lf_token_t * next
Definition lf_token.h:104
size_t ref_count
Definition lf_token.h:102
size_t length
Definition lf_token.h:98
void * value
Definition lf_token.h:96
token_type_t * type
Definition lf_token.h:100
The base type for all reactor self structs.
Definition lf_types.h:276
Base type for ports (lf_port_base_t) and actions (trigger_t), which can carry tokens....
Definition lf_token.h:121
lf_token_t * token
Definition lf_token.h:124
size_t length
Definition lf_token.h:125
token_type_t type
Definition lf_token.h:123
Type information for tokens. Specifically, this struct contains the fields needed to support token ty...
Definition lf_token.h:67
void(* destructor)(void *value)
Definition lf_token.h:71
size_t element_size
Definition lf_token.h:69