diff --git a/core/environment.c b/core/environment.c index af192c09b..eb012589b 100644 --- a/core/environment.c +++ b/core/environment.c @@ -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]); + } +} \ No newline at end of file diff --git a/core/reactor_common.c b/core/reactor_common.c index 83a1592b9..455b3a065 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -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 @@ -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. @@ -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. @@ -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 } /** diff --git a/include/core/environment.h b/include/core/environment.h index 8099eed26..9f3960a6f 100644 --- a/include/core/environment.h +++ b/include/core/environment.h @@ -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. diff --git a/lingua-franca-ref.txt b/lingua-franca-ref.txt index 1f7391f92..5d6695559 100644 --- a/lingua-franca-ref.txt +++ b/lingua-franca-ref.txt @@ -1 +1 @@ -master +add-reaction