-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix an implicit conversion from int to unsigned in Events #14176
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
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.
all functions in this header file have it declared as
int ms
, this change would cause confusion?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.
This was the solution @kjbracey-arm suggested above...
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 guess Martin means that it's not consistent with other APIs here? Maybe they also need changing.
But if we're using a mixture of signed and unsigned internally and that got reflected in API might look a bit icky. Would be honest at least...
I noticed this issue the other day too: #14077.
So I suspect the code might not be 100% solid as you reach the extremes of the int range anyway. Just as weird stuff happens if you're less then
(int) 0
, as Anna noted, weird stuff might happen if you're greater than(unsigned) 0x7fffffff
, depending on how solid all the maths is.It's possible this isn't a net benefit. Maybe the working range is only 0-7fffffff, and
unsigned
doesn't match that any more thanint
.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.
To a large extent many the Chrono APIs avoid this by just saying "screw it - use a 64-bit type". Thats so big you never have to worry about range problems. Maybe we might want to go 64-bit inside and out to avoid #14077-type problems? We have 64-bit for RTOS APIs and all ticker_api-based stuff. This is a 32-bit outlier in the core system (although various subsystems like Netsocket are 32-bitty).
And, thinking of Chrono as it stands now, we have Chrono implemented already in
Event
. So we currently have aduration<int, milli>
there feeding into this. If changing stuff tounsigned
here, you should follow through so thatEvent::delay
(and others?) took aduration<unsigned, milli>
.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.
If we only change
equeue_event_delay
then we introduce inconsistency in the equeue library with a mixture of signed and unsigned APIs. Additionally I thought the original request was to changeEventQueue::call_in
to take an unsigned int, which also introduces inconsistency in that library.But I am worried that the code is not behaving as I expected. I can't repoduce #13105 as described: the event is dispatched right away and not after 49.7 days as we would have expected.
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.
Sounds to me like this needs much more thought! Don't forget for events we have
static constexpr std::chrono::duration<int, std::milli> non_periodic{-1};
Which allows a -ve duration to represent a non_periodic ie once off event. So we can't just move all durations to unsigned without re-writing the underlying functionality to allow for a non periodic event in another way...
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.
The other option I guess would be to make it all unsigned but to enforce a maximum value and then reserve a few values above that max to use for the different modes....
Uh oh!
There was an error while loading. Please reload this page.
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.
@evedon see my comment here for why it makes more sense to change
equeue_event_delay
#13105 (comment)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 like your suggestion above. We should fix the events library properly and use unsigned everywhere, including duration<unsigned, milli>.
As for
EventQueue::call_in(int ms, F f)
, given that the function is already deprecated, it's probably okay to leave it as such until it is removed.I suggest that we bring in all the events related PRs in the same release so it is less disruptive to our users.