Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix action is_present field not being reset #482

Merged
merged 11 commits into from
Sep 29, 2024
6 changes: 6 additions & 0 deletions core/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,9 @@ int environment_init(environment_t* env, const char* name, int id, int num_worke
env->initialized = true;
return 0;
}

void environment_verify(environment_t* env) {
for (int i = 0; i < env->is_present_fields_size; i++) {
LF_ASSERT_NON_NULL(env->is_present_fields[i]);
}
}
edwardalee marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 19 additions & 5 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,19 @@ void _lf_pop_events(environment_t* env) {
}
}

// Mark the trigger present.
// Mark the trigger present
event->trigger->status = present;

// If the trigger is a periodic timer, create a new event for its next execution.
if (event->trigger->is_timer && event->trigger->period > 0LL) {
// Reschedule the trigger.
lf_schedule_trigger(env, event->trigger, event->trigger->period, NULL);
} else {
// For actions, store a pointer to status field so it is reset later.
int ipfas = lf_atomic_fetch_add(&env->is_present_fields_abbreviated_size, 1);
if (ipfas < env->is_present_fields_size) {
env->is_present_fields_abbreviated[ipfas] = (bool*)&event->trigger->status;
}
}

// Copy the token pointer into the trigger struct so that the
Expand All @@ -323,9 +329,6 @@ void _lf_pop_events(environment_t* env) {
// freed prematurely.
_lf_done_using(token);

// Mark the trigger present.
event->trigger->status = present;

lf_recycle_event(env, event);

// Peek at the next event in the event queue.
Expand Down Expand Up @@ -603,8 +606,12 @@ trigger_handle_t _lf_insert_reactions_for_trigger(environment_t* env, trigger_t*
// for which we decrement the reference count.
_lf_replace_template_token((token_template_t*)trigger, token);

// Mark the trigger present.
// Mark the trigger present and store a pointer to it for marking it as absent later.
trigger->status = present;
int ipfas = lf_atomic_fetch_add(&env->is_present_fields_abbreviated_size, 1);
if (ipfas < env->is_present_fields_size) {
env->is_present_fields_abbreviated[ipfas] = (bool*)&trigger->status;
}

// Push the corresponding reactions for this trigger
// onto the reaction queue.
Expand Down Expand Up @@ -1096,6 +1103,13 @@ void initialize_global(void) {
// Call the code-generated function to initialize all actions, timers, and ports
// This is done for all environments/enclaves at the same time.
_lf_initialize_trigger_objects();

#if !defined(LF_SINGLE_THREADED) && !defined(NDEBUG)
// If we are testing, verify that environment with pointers is correctly set up.
for (int i = 0; i < num_envs; i++) {
environment_verify(&envs[i]);
}
#endif
}

/**
Expand Down
7 changes: 7 additions & 0 deletions include/core/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ int environment_init(environment_t* env, const char* name, int id, int num_worke
int num_is_present_fields, int num_modes, int num_state_resets, int num_watchdogs,
const char* trace_file_name);

/**
* @brief Verify that the environment is correctly set up.
*
* @param env
*/
void environment_verify(environment_t* env);

/**
* @brief Free the dynamically allocated memory on the environment struct.
* @param env The environment in which we are executing.
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
add-reaction
Loading