-
Notifications
You must be signed in to change notification settings - Fork 24
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
Priority queue refactoring #306
Conversation
Will this address this issue of RTI sending mistaken PTAGs: lf-lang/lingua-franca#2084 |
I don't think it does -- this is just a refactoring AFAIK. |
Thank you for refactoring this, @edwardalee! This is really helpful for the NDT optimization. In this commit (fb024fa), I made the function (Update)
According to @lhstrh's comment above, I just added the search function (pqueue_tag_find_same_tag) instead of checking the duplication inside the insert function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to look at this more closely later, but some quick feedback: You are right that we will need the capability to prevent accumulation in the queue of elements with the same tag. This will be particularly important if tags corresponding to the timeout time or FOREVER are posted, but we could get an unbounded accumulation of these without them ever getting cleared.
However, the solution looks expensive to me. Can we avoid mallocing and then freeing an element that is used just to conduct the search? I think the element can be put on the stack.
And perhaps the de-duplication should not be done by default. How about an alternate insert function (insert if not present)? Also, I suspect that instead of searching the queue, a low-level algorithm would be much more efficient. Probably it would just be a small variant of the bubble_up function in pqeueue_base that would perform the de-duplication while doing the insertion, instead of doing it in two separate steps.
(Actually, on reflection, probably this low-level idea won't be so easy... The bubble_up function in pqueue_base is destructive, in that it changes the data structure as it goes. If it finds a duplicate after making all these changes, then it likely will have to undo all those changes. Probably the two-phase approach is actually better.)
…ert_tag_if_not_present
Thank you for the feedback, @edwardalee! I modified the code based on your comment.
Now, the function
I made the function here ( |
I found a way to do this without replicating code from pqueue_base and without using malloc (the elements are on the stack). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Let's merge this.
This is a refactoring and cleanup of the pqueue infrastructure with the addition of a priority queue that uses tag ordering.
Currently, this priority queue (a
pqueue_tag_t
) is not used anywhere except in unit tests.The first place where it should be used is to replace the queue used by the
in_transit_message_tags
field of thefederate_info_t
struct maintained by the RTI for each federate. Also, @byeong-gil 's NDT optimization requires such a queue.Eventually, I believe this tag sorted queue could replace the event queue and significantly simply it without a performance penalty.