diff --git a/core/environment.c b/core/environment.c index 10c989880..1ec79f773 100644 --- a/core/environment.c +++ b/core/environment.c @@ -167,7 +167,6 @@ void environment_free(environment_t* env) { free(env->is_present_fields_abbreviated); pqueue_tag_free(env->event_q); pqueue_free(env->recycle_q); - // pqueue_free(env->next_q); environment_free_threaded(env); environment_free_single_threaded(env); @@ -241,13 +240,9 @@ int environment_init(environment_t* env, const char* name, int id, int num_worke env->_lf_handle = 1; // Initialize our priority queues. - // env->event_q = pqueue_init(INITIAL_EVENT_QUEUE_SIZE, in_reverse_order, get_event_time, get_event_position, - // set_event_position, event_matches, print_event); env->event_q = pqueue_tag_init_customize(INITIAL_EVENT_QUEUE_SIZE, event_matches); env->recycle_q = pqueue_init(INITIAL_EVENT_QUEUE_SIZE, in_no_particular_order, get_event_time, get_event_position, set_event_position, event_matches, print_event); - // env->next_q = pqueue_init(INITIAL_EVENT_QUEUE_SIZE, in_no_particular_order, get_event_time, get_event_position, - // set_event_position, event_matches, print_event); // Initialize functionality depending on target properties. environment_init_threaded(env, num_workers); diff --git a/core/reactor.c b/core/reactor.c index 5c431a651..ce6269753 100644 --- a/core/reactor.c +++ b/core/reactor.c @@ -221,12 +221,6 @@ int next(environment_t* env) { } } else { next_tag = event->base.tag; - // // Deduce the microstep - // if (next_tag.time == env->current_tag.time) { - // next_tag.microstep = env->current_tag.microstep + 1; - // } else { - // next_tag.microstep = 0; - // } } if (lf_is_tag_after_stop_tag(env, next_tag)) { diff --git a/core/reactor_common.c b/core/reactor_common.c index 8c24c33da..ad7bfc1c0 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -236,10 +236,6 @@ void _lf_pop_events(environment_t* env) { if (event->is_dummy) { LF_PRINT_DEBUG("Popped dummy event from the event queue."); - // if (event->next != NULL) { - // LF_PRINT_DEBUG("Putting event from the event queue for the next microstep."); - // pqueue_insert(env->next_q, event->next); - // } lf_recycle_event(env, event); // Peek at the next event in the event queue. event = (event_t*)pqueue_tag_peek(env->event_q); @@ -328,25 +324,11 @@ void _lf_pop_events(environment_t* env) { // Mark the trigger present. event->trigger->status = present; - // // If this event points to a next event, insert it into the next queue. - // if (event->next != NULL) { - // // Insert the next event into the next queue. - // pqueue_insert(env->next_q, event->next); - // } - lf_recycle_event(env, event); // Peek at the next event in the event queue. event = (event_t*)pqueue_tag_peek(env->event_q); }; - - // LF_PRINT_DEBUG("There are %zu events deferred to the next microstep.", pqueue_size(env->next_q)); - - // // After populating the reaction queue, see if there are things on the - // // next queue to put back into the event queue. - // while (pqueue_peek(env->next_q) != NULL) { - // pqueue_insert(env->event_q, pqueue_pop(env->next_q)); - // } } event_t* lf_get_new_event(environment_t* env) { @@ -376,7 +358,6 @@ void _lf_initialize_timer(environment_t* env, trigger_t* timer) { // && (timer->offset != 0 || timer->period != 0)) { event_t* e = lf_get_new_event(env); e->trigger = timer; - // e->time = lf_time_logical(env) + timer->offset; e->base.tag = (tag_t){.time = lf_time_logical(env) + timer->offset, .microstep = 0}; _lf_add_suspended_event(e); return; @@ -464,15 +445,12 @@ void _lf_trigger_shutdown_reactions(environment_t* env) { void lf_recycle_event(environment_t* env, event_t* e) { assert(env != GLOBAL_ENVIRONMENT); e->base.tag = (tag_t){.time = 0LL, .microstep = 0}; - // e->time = 0LL; e->trigger = NULL; - // e->pos = 0; e->token = NULL; e->is_dummy = false; #ifdef FEDERATED_DECENTRALIZED e->intended_tag = (tag_t){.time = NEVER, .microstep = 0u}; #endif - // e->next = NULL; pqueue_insert(env->recycle_q, e); } @@ -482,18 +460,6 @@ event_t* _lf_create_dummy_events(environment_t* env, trigger_t* trigger, tag_t t dummy->is_dummy = true; dummy->trigger = trigger; - // while (offset > 0) { - // if (offset == 1) { - // dummy->next = next; - // break; - // } - // dummy->next = lf_get_new_event(env); - // dummy = dummy->next; - // dummy->time = time; - // dummy->is_dummy = true; - // dummy->trigger = trigger; - // offset--; - // } return dummy; } @@ -508,7 +474,6 @@ void lf_replace_token(event_t* event, lf_token_t* token) { trigger_handle_t _lf_schedule_at_tag(environment_t* env, trigger_t* trigger, tag_t tag, lf_token_t* token) { assert(env != GLOBAL_ENVIRONMENT); - printf("In _lf_schedule_at_tag\n"); tag_t current_logical_tag = env->current_tag; LF_PRINT_DEBUG("_lf_schedule_at_tag() called with tag " PRINTF_TAG " at tag " PRINTF_TAG ".", tag.time - start_time, @@ -549,7 +514,7 @@ trigger_handle_t _lf_schedule_at_tag(environment_t* env, trigger_t* trigger, tag e->intended_tag = trigger->intended_tag; #endif - event_t* found = (event_t*)pqueue_tag_find_with_tag(env->event_q, tag); + event_t* found = (event_t*)pqueue_tag_find_equal_same_tag(env->event_q, (pqueue_tag_element_t*)e); if (found != NULL) { switch (trigger->policy) { case drop: diff --git a/core/threaded/reactor_threaded.c b/core/threaded/reactor_threaded.c index 80da46e7d..fa8861515 100644 --- a/core/threaded/reactor_threaded.c +++ b/core/threaded/reactor_threaded.c @@ -288,13 +288,6 @@ tag_t get_next_event_tag(environment_t* env) { } next_tag = event->base.tag; - // if (next_tag.time == env->current_tag.time) { - // LF_PRINT_DEBUG("Earliest event matches current time. Incrementing microstep. Event is dummy: %d.", - // event->is_dummy); - // next_tag.microstep = env->current_tag.microstep + 1; - // } else { - // next_tag.microstep = 0; - // } } // If a timeout tag was given, adjust the next_tag from the @@ -974,7 +967,7 @@ void lf_print_snapshot(environment_t* env) { // accessible here LF_PRINT_DEBUG("Event queue size: %zu. Contents:", pqueue_tag_size(env->event_q)); // FIXME: There is no pqueue_tag_dump now - // pqueue_dump(env->event_q, print_reaction); + pqueue_tag_dump(env->event_q); LF_PRINT_DEBUG(">>> END Snapshot"); } } diff --git a/core/utils/pqueue_tag.c b/core/utils/pqueue_tag.c index 53d2375fd..68e921e72 100644 --- a/core/utils/pqueue_tag.c +++ b/core/utils/pqueue_tag.c @@ -158,3 +158,5 @@ void pqueue_tag_remove_up_to(pqueue_tag_t* q, tag_t t) { head = pqueue_tag_peek_tag(q); } } + +void pqueue_tag_dump(pqueue_tag_t* q) { pqueue_dump((pqueue_t*)q, pqueue_tag_print_element); } \ No newline at end of file diff --git a/include/core/environment.h b/include/core/environment.h index 01b388d40..00084b8a6 100644 --- a/include/core/environment.h +++ b/include/core/environment.h @@ -73,9 +73,8 @@ typedef struct environment_t { int id; tag_t current_tag; tag_t stop_tag; - pqueue_t* event_q; + pqueue_tag_t* event_q; pqueue_t* recycle_q; - // pqueue_t* next_q; bool** is_present_fields; int is_present_fields_size; bool** is_present_fields_abbreviated; diff --git a/include/core/lf_types.h b/include/core/lf_types.h index 856c8b695..d70447159 100644 --- a/include/core/lf_types.h +++ b/include/core/lf_types.h @@ -196,16 +196,13 @@ typedef struct event_t event_t; /** Event activation record to push onto the event queue. */ struct event_t { - pqueue_tag_element_t base; // Elements of pqueue_tag - // instant_t time; // Time of release. - trigger_t* trigger; // Associated trigger, NULL if this is a dummy event. - // size_t pos; // Position in the priority queue. - lf_token_t* token; // Pointer to the token wrapping the value. - bool is_dummy; // Flag to indicate whether this event is merely a placeholder or an actual event. + pqueue_tag_element_t base; // Elements of pqueue_tag. It contains tag of release and position in the priority queue. + trigger_t* trigger; // Associated trigger, NULL if this is a dummy event. + lf_token_t* token; // Pointer to the token wrapping the value. + bool is_dummy; // Flag to indicate whether this event is merely a placeholder or an actual event. #ifdef FEDERATED tag_t intended_tag; // The intended tag. #endif - // event_t* next; // Pointer to the next event lined up in superdense time. }; /** diff --git a/include/core/utils/pqueue_tag.h b/include/core/utils/pqueue_tag.h index 51bff8d46..1a525c676 100644 --- a/include/core/utils/pqueue_tag.h +++ b/include/core/utils/pqueue_tag.h @@ -70,9 +70,9 @@ typedef pqueue_t pqueue_tag_t; pqueue_tag_t* pqueue_tag_init(size_t initial_size); /** - * @brief Create a priority queue sorted by tags and has a customized payload. + * @brief Create a priority queue sorted by tags and has a payload that requires a particular comparison function. * - * @param eqelem the callback function to check equivalence of entries + * @param eqelem the callback function to check equivalence of payloads. * * The elements of the priority queue will be of type pqueue_tag_element_t. * The caller should call pqueue_tag_free() when finished with the queue. @@ -194,4 +194,12 @@ void pqueue_tag_remove(pqueue_tag_t* q, pqueue_tag_element_t* e); */ void pqueue_tag_remove_up_to(pqueue_tag_t* q, tag_t t); +/** + * Dump the queue and it's internal structure. + * @internal + * debug function only + * @param q the queue + */ +void pqueue_tag_dump(pqueue_tag_t* q); + #endif // PQUEUE_TAG_H