Skip to content

Commit

Permalink
Merge pull request #491 from lf-lang/fix-concurrency
Browse files Browse the repository at this point in the history
Fix Unintended Action Override
  • Loading branch information
lhstrh authored Oct 19, 2024
2 parents c4764fb + ba805e1 commit 3d7715c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
26 changes: 12 additions & 14 deletions core/lf_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,20 @@ lf_token_t* _lf_new_token(token_type_t* type, void* value, size_t length) {
}

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
3 changes: 3 additions & 0 deletions include/api/reaction_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
/* 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)

Expand All @@ -97,6 +98,7 @@
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 @@ -105,6 +107,7 @@
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

0 comments on commit 3d7715c

Please sign in to comment.