Asoragna/cleanup#49
Merged
irobot-ros merged 4 commits intoirobot/add-events-executorfrom Feb 23, 2021
Merged
Conversation
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
Signed-off-by: Soragna, Alberto <alberto.soragna@gmail.com>
Signed-off-by: Soragna, Alberto <alberto.soragna@gmail.com>
Collaborator
|
IMOLGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does some cleanup and small fixes to events executor and timers manager.|
I suggest to first review by commit
191f47a
6a99496
c99d764
b72d124
run_timersit was computing the next timeout at the end of the while loop. This was done because in that location it was possible to directly access the locked heap structure.This works only if the next iteration of the while loop is immediately executed, but it will be incorrect if someone else acquires the mutex (e.g. for adding/removing timers).
The reason is that the next timeout may be 1 second, but maybe the mutex has been held by someone else for 0.8 seconds: the real timeout is now 0.2 seconds, but the previous implementation would have still waited for 1 second.
The solution is to compute the timeout at the beginning of the while loop, i.e. after the mutex has been acquired.
In order to do that efficiently I created a new implementation of
get_head_timeout_unsafethat if no timers have been removed can directly return the timeout without need to iterate over the all vector.