Skip to content

Commit

Permalink
Cleanup codes
Browse files Browse the repository at this point in the history
  • Loading branch information
byeonggiljun committed Mar 12, 2024
1 parent 1d4d05c commit 2ccd7cb
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 66 deletions.
5 changes: 0 additions & 5 deletions core/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions core/reactor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
37 changes: 1 addition & 36 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 1 addition & 8 deletions core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/utils/pqueue_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
3 changes: 1 addition & 2 deletions include/core/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions include/core/lf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};

/**
Expand Down
12 changes: 10 additions & 2 deletions include/core/utils/pqueue_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit 2ccd7cb

Please sign in to comment.