diff --git a/core/utils/pqueue_base.c b/core/utils/pqueue_base.c index c0abb0619..5d602e1de 100644 --- a/core/utils/pqueue_base.c +++ b/core/utils/pqueue_base.c @@ -29,6 +29,15 @@ * - The provided pqueue_eq_elem_f implementation is used to test and * search for equal elements present in the queue; and * - Removed capability to reassign priorities. + * + * Modified by Byeonggil Jun (Apr, 2024). + * Changes: + * - Made the pqueue_cmp_pri_f function return do the three-way comparison + * rather than the two-way comparison. + * - The changed pqueue_cmp_pri_f function is used to check the equality of + * two elements in the pqueue_find_equal_same_priority function. + * - Remove the pqueue_find_equal function. + * */ #include @@ -44,38 +53,6 @@ #define LF_RIGHT(i) (((i) << 1) + 1) #define LF_PARENT(i) ((i) >> 1) -void* find_equal(pqueue_t* q, void* e, int pos, pqueue_pri_t max) { - if (pos < 0) { - lf_print_error_and_exit("find_equal() called with a negative pos index."); - } - - // Stop the recursion when we've reached the end of the - // queue. This has to be done before accessing the queue - // to avoid segmentation fault. - if (!q || (size_t)pos >= q->size) { - return NULL; - } - - void* rval; - void* curr = q->d[pos]; - - // Stop the recursion when we've surpassed the maximum priority. - if (!curr || q->cmppri(q->getpri(curr), max) == 1) { - return NULL; - } - - if (q->eqelem(curr, e)) { - return curr; - } else { - rval = find_equal(q, e, LF_LEFT(pos), max); - if (rval) - return rval; - else - return find_equal(q, e, LF_RIGHT(pos), max); - } - return NULL; -} - static void* find_same_priority(pqueue_t* q, void* e, int pos) { if (pos < 0) { lf_print_error_and_exit("find_same_priority() called with a negative pos index."); @@ -227,8 +204,6 @@ static void percolate_down(pqueue_t* q, size_t i) { q->setpos(moving_node, i); } -void* pqueue_find_equal(pqueue_t* q, void* e, pqueue_pri_t max) { return find_equal(q, e, 1, max); } - void* pqueue_find_same_priority(pqueue_t* q, void* e) { return find_same_priority(q, e, 1); } void* pqueue_find_equal_same_priority(pqueue_t* q, void* e) { return find_equal_same_priority(q, e, 1); } diff --git a/core/utils/pqueue_support.h b/core/utils/pqueue_support.h deleted file mode 100644 index 2c462262e..000000000 --- a/core/utils/pqueue_support.h +++ /dev/null @@ -1,115 +0,0 @@ -/************* -Copyright (c) 2022, The University of California at Berkeley. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -***************/ - -/** - * @file pqueue_support.h - * @author Edward A. Lee - * @author Marten Lohstroh - * @brief Header-only support functions for pqueue. - */ - -#ifndef PQUEUE_SUPPORT_H -#define PQUEUE_SUPPORT_H - -#include "../reactor.h" - -// ********** Priority Queue Support Start - -/** - * Return whether the first and second argument are given in reverse order. - */ -static int in_reverse_order(pqueue_pri_t thiz, pqueue_pri_t that) { return (thiz > that); } - -/** - * Return false (0) regardless of reaction order. - */ -static int in_no_particular_order(pqueue_pri_t thiz, pqueue_pri_t that) { return false; } - -/** - * Return whether or not the given events have matching triggers. - */ -static int event_matches(void* next, void* curr) { return (((event_t*)next)->trigger == ((event_t*)curr)->trigger); } - -/** - * Return whether or not the given reaction_t pointers - * point to the same struct. - */ -static int reaction_matches(void* next, void* curr) { return (next == curr); } - -/** - * Report a priority equal to the time of the given event. - * Used for sorting pointers to event_t structs in the event queue. - */ -static pqueue_pri_t get_event_time(void* a) { return (pqueue_pri_t)(((event_t*)a)->base.tag.time); } - -/** - * Report a priority equal to the index of the given reaction. - * Used for sorting pointers to reaction_t structs in the - * blocked and executing queues. - */ -static pqueue_pri_t get_reaction_index(void* a) { return ((reaction_t*)a)->index; } - -/** - * Return the given event's position in the queue. - */ -static size_t get_event_position(void* a) { return ((event_t*)a)->pos; } - -/** - * Return the given reaction's position in the queue. - */ -static size_t get_reaction_position(void* a) { return ((reaction_t*)a)->pos; } - -/** - * Set the given event's position in the queue. - */ -static void set_event_position(void* a, size_t pos) { ((event_t*)a)->pos = pos; } - -/** - * Return the given reaction's position in the queue. - */ -static void set_reaction_position(void* a, size_t pos) { ((reaction_t*)a)->pos = pos; } - -/** - * Print some information about the given reaction. - * - * DEBUG function only. - */ -static void print_reaction(void* reaction) { - reaction_t* r = (reaction_t*)reaction; - LF_PRINT_DEBUG("%s: chain_id:%llu, index: %llx, reaction: %p", r->name, r->chain_id, r->index, (void*)r); -} - -/** - * Print some information about the given event. - * - * DEBUG function only. - */ -static void print_event(void* event) { - event_t* e = (event_t*)event; - LF_PRINT_DEBUG("tag: " PRINTF_TAG ", trigger: %p, token: %p", e->base.tag.time, e->base.tag.microstep, - (void*)e->trigger, (void*)e->token); -} - -// ********** Priority Queue Support End -#endif diff --git a/include/core/utils/pqueue_base.h b/include/core/utils/pqueue_base.h index 5039fe282..b913ab64f 100644 --- a/include/core/utils/pqueue_base.h +++ b/include/core/utils/pqueue_base.h @@ -30,6 +30,14 @@ * search for equal elements present in the queue; and * - Removed capability to reassign priorities. * + * Modified by Byeonggil Jun (Apr, 2024). + * Changes: + * - Made the pqueue_cmp_pri_f function return do the three-way comparison + * rather than the two-way comparison. + * - The changed pqueue_cmp_pri_f function is used to check the equality of + * two elements in the pqueue_find_equal_same_priority function. + * - Remove the pqueue_find_equal function. + * * @brief Priority Queue function declarations used as a base for Lingua Franca priority queues. * * @{ @@ -139,16 +147,6 @@ void* pqueue_pop(pqueue_t* q); */ void pqueue_empty_into(pqueue_t** dest, pqueue_t** src); -/** - * Find the highest-ranking item with priority up to and including the given - * maximum priority that matches the supplied entry. - * @param q the queue - * @param e the entry to compare against - * @param max_priority the maximum priority to consider - * @return NULL if no matching event has been found, otherwise the entry - */ -void* pqueue_find_equal(pqueue_t* q, void* e, pqueue_pri_t max_priority); - /** * Return an entry with the same priority as the specified entry or NULL if there is no such entry. * @param q the queue