Skip to content

Commit

Permalink
Merge branch 'main' into static-schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk567 committed Oct 21, 2024
2 parents 998f555 + 3d7715c commit e8975a9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
26 changes: 12 additions & 14 deletions core/lf_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,20 @@ lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length) {
// I also don't get why the token isn't simply returned, and
// _lf_free_token_value or _lf_done_using has to be called.
lf_token_t* _lf_get_token(token_template_t* tmplt) {
if (tmplt->token != NULL) {
if (tmplt->token->ref_count == 1) {
LF_PRINT_DEBUG("_lf_get_token: Reusing template token: %p with ref_count %zu", (void*)tmplt->token,
tmplt->token->ref_count);
// Free any previous value in the token.
_lf_free_token_value(tmplt->token);
return tmplt->token;
} else {
// Liberate the token.
_lf_done_using(tmplt->token);
}
LF_CRITICAL_SECTION_ENTER(GLOBAL_ENVIRONMENT);
if (tmplt->token != NULL && tmplt->token->ref_count == 1) {
LF_PRINT_DEBUG("_lf_get_token: Reusing template token: %p with ref_count %zu", (void*)tmplt->token,
tmplt->token->ref_count);
// Free any previous value in the token.
_lf_free_token_value(tmplt->token);
LF_CRITICAL_SECTION_EXIT(GLOBAL_ENVIRONMENT);
return tmplt->token;
}
LF_CRITICAL_SECTION_EXIT(GLOBAL_ENVIRONMENT);
// If we get here, we need a new token.
tmplt->token = _lf_new_token((token_type_t*)tmplt, NULL, 0);
tmplt->token->ref_count = 1;
return tmplt->token;
lf_token_t* result = _lf_new_token((token_type_t*)tmplt, NULL, 0);
result->ref_count = 1;
return result;
}

void _lf_initialize_template(token_template_t* tmplt, size_t element_size) {
Expand Down
33 changes: 18 additions & 15 deletions include/api/reaction_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@
*/
#if SCHEDULER == SCHED_STATIC
#define lf_set(out, val) \
do { \
out->value = val; \
lf_set_present(out); \
out->token = (lf_token_t *)(uintptr_t)val; /* The long-term solution is to generate an event type for each connection buffer of primitive type. */ \
} while(0)
do { \
out->value = val; \
lf_set_present(out); \
out->token = (lf_token_t *)(uintptr_t)val; /* The long-term solution is to generate an event type for each connection buffer of primitive type. */ \
} while(0)
#else
#define lf_set(out, val) \
do { \
out->value = val; \
lf_set_present(out); \
if (((token_template_t*)out)->token != NULL) { \
/* The cast "*((void**) &out->value)" is a hack to make the code */ \
/* compile with non-token types where value is not a pointer. */ \
lf_token_t* token = _lf_initialize_token_with_value((token_template_t*)out, *((void**) &out->value), 1); \
} \
} while(0)
#define lf_set(out, val) \
do { \
out->value = val; \
lf_set_present(out); \
if (((token_template_t*)out)->token != NULL) { \
/* The cast "*((void**) &out->value)" is a hack to make the code */ \
/* compile with non-token types where value is not a pointer. */ \
lf_token_t* token = _lf_initialize_token_with_value((token_template_t*)out, *((void**)&out->value), 1); \
out->token = token; \
} \
} while (0)
#endif

/**
Expand All @@ -106,6 +107,7 @@ do { \
do { \
lf_set_present(out); \
lf_token_t* token = _lf_initialize_token_with_value((token_template_t*)out, val, len); \
out->token = token; \
out->value = token->value; \
out->length = len; \
} while (0)
Expand All @@ -114,6 +116,7 @@ do { \
do { \
lf_set_present(out); \
lf_token_t* token = _lf_initialize_token_with_value((token_template_t*)out, val, len); \
out->token = token; \
out->value = static_cast<decltype(out->value)>(token->value); \
out->length = len; \
} while (0)
Expand Down
2 changes: 1 addition & 1 deletion lingua-franca-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master
fix-concurrency
3 changes: 2 additions & 1 deletion python/lib/pythontarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ PyObject* convert_C_action_to_py(void* action) {
}

// Actions in Python always use token type
((generic_action_capsule_struct*)cap)->value = trigger->tmplt.token->value;
if (((generic_action_instance_struct*)action)->token != NULL)
((generic_action_capsule_struct*)cap)->value = ((generic_action_instance_struct*)action)->token->value;

return cap;
}
Expand Down

0 comments on commit e8975a9

Please sign in to comment.