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
167
176
179
198lf_token_t* lf_new_token(void* port_or_action, void* val, size_t len);
199
215
218
234
248lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length);
249
260
271void _lf_initialize_template(token_template_t* tmplt, size_t element_size);
272
289lf_token_t* _lf_initialize_token_with_value(token_template_t* tmplt, void* value, size_t length);
290
308lf_token_t* _lf_initialize_token(token_template_t* tmplt, size_t length);
309
316
325
337
344void _lf_free_token_copies(void);
345
346#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:152
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:191
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:243
lf_token_t * _lf_initialize_token(token_template_t *tmplt, size_t length)
Definition lf_token.c:285
token_freed _lf_done_using(lf_token_t *token)
Definition lf_token.c:340
lf_token_t * _lf_get_token(token_template_t *tmplt)
Definition lf_token.c:224
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:59
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:63
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:353
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:324
lf_token_t * _lf_initialize_token_with_value(token_template_t *tmplt, void *value, size_t length)
Definition lf_token.c:269
lf_token_t * _lf_tokens_allocated_in_reactions
List of tokens created within reactions that must be freed. Tokens created by lf_writable_copy,...
Definition lf_token.c:29
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:293
Execution environment. This struct contains information about the execution environment....
Definition environment.h:69
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
size_t present_channels[]
Definition lf_token.h:113
int size
Definition lf_token.h:111
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:278
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