-
Notifications
You must be signed in to change notification settings - Fork 3k
Update EventQueue API to use chrono times #13975
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
Conversation
@adbridge, thank you for your changes. |
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.
Thanks @adbridge . I wonder if we shouldn't provide a graceful period where dispatch(int ms=-1)
is exposed as a deprecated function.
events/include/events/EventQueue.h
Outdated
* @see EventQueue::dispatch | ||
* | ||
* Executes events indefinitely unless the dispatch loop is forcibly broken. | ||
* See break_dispatch() |
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.
You can use @see
to reference another function. Doxygen should generate a link to it and depending on it's configuration it can list references in break_dispatch
doc.
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.
Typo error removing the '@' by the looks of it!
events/include/events/EventQueue.h
Outdated
* @param ms Time to wait for events in milliseconds, a negative | ||
* value will dispatch events indefinitely | ||
* (default to -1) | ||
* @param wait Time to wait for events in milliseconds, expressed as a |
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 always found that description confusing; the parameter expresses the duration of the dispatch process. It has nothing to do with the time to wait for events. For example, if I request a dispatch for 10ms and an event is ready at 2ms into the process. The function won't exit after processing the event, it will continue the dispatch process for the remaining 8ms.
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 see what you mean, but it also isn't a time limit on the dispatch. If there are multiple events scheduled for the time as it stood on entry, it will run them all. It won't run the first few and then decide "oh, those first few events took longer than 10ms, let's stop dispatching.
So it is specifically determining how long it will wait, not dispatch, but yes, it's relative to the entry time, not a "gap" timeout after last event.
These sort of multi-op things with timeouts are always confusing. Compare condition variables, where there is a timeout on the wait, but no timeout on the mutex acquire. Time could be well past the deadline before you regain control, whether or not the wait timed out...
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.
That's part of the original comment by the author, are we saying we disagree with what was originally written ?
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 think the original comment is acceptable, and "wait" is right. @pan- didn't like it, interpreting it as a one-off wait for first event. I view it as correctly describing when we'll give up at any point we find ourselves waiting.
* In this case, the dispatch function does not wait and is IRQ safe. | ||
* | ||
*/ | ||
void dispatch_once(); |
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 lost my comment for that item.
@kjbracey-arm The implementation doesn't do exactly this. It may not break immediately out of the loop if the next tick hasn't been reached. Do you think we should patch the implementation ?
The change is trivial, we just have to return if ms
is equal to 0.
mbed-os/events/source/equeue.c
Lines 525 to 530 in 68612cb
int deadline = -1; | |
tick = equeue_tick(); | |
// check if we should stop dispatching soon | |
if (ms >= 0) { |
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'm not seeing what you're seeing here. If ms == 0
, then it computes tickdiff(timeout, tick)
, ie entry_tick + 0 - tick
, and that's got to be <= 0
, so it exits immediately. Right?
BTW the name here feels perilously close to dispatch_one()
, but I guess it's okay...
We must mark the function has deprecated and remove it in a future major release. |
events/include/events/EventQueue.h
Outdated
* @param ms Time to wait for events in milliseconds, a negative | ||
* value will dispatch events indefinitely | ||
* (default to -1) | ||
* @param wait Time to wait for events in milliseconds, expressed as a |
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 see what you mean, but it also isn't a time limit on the dispatch. If there are multiple events scheduled for the time as it stood on entry, it will run them all. It won't run the first few and then decide "oh, those first few events took longer than 10ms, let's stop dispatching.
So it is specifically determining how long it will wait, not dispatch, but yes, it's relative to the entry time, not a "gap" timeout after last event.
These sort of multi-op things with timeouts are always confusing. Compare condition variables, where there is a timeout on the wait, but no timeout on the mutex acquire. Time could be well past the deadline before you regain control, whether or not the wait timed out...
* In this case, the dispatch function does not wait and is IRQ safe. | ||
* | ||
*/ | ||
void dispatch_once(); |
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'm not seeing what you're seeing here. If ms == 0
, then it computes tickdiff(timeout, tick)
, ie entry_tick + 0 - tick
, and that's got to be <= 0
, so it exits immediately. Right?
BTW the name here feels perilously close to dispatch_one()
, but I guess it's okay...
events/include/events/EventQueue.h
Outdated
|
||
/** Dispatch currently queued events only and then terminate | ||
* | ||
* In this case, the dispatch function does not wait and is IRQ safe. |
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 think we can't quite say it's IRQ safe. It wouldn't be in an RTOS build, as it still uses mutexes for its state locks. It's close to it, and in certain specialised non-RTOS runtime environments this might be important, but for mainline Mbed OS API I think I'd like to not try to specify that.
events/include/events/EventQueue.h
Outdated
*/ | ||
void dispatch(int ms = -1); | ||
void dispatch(duration wait); |
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.
You need to leave the existing API with a deprecation warning. This PR then becomes a Feature update rather than Breaking change.
This pull request has automatically been marked as stale because it has had no recent activity. @adbridge, please carry out any necessary work to get the changes merged. Thank you for your contributions. |
Going to consider the changes here along side the fix needed for type inconsistencies across the event/eventqueue/equeue APIs (triggered by #14176) |
Updated Greentea test results:
|
@evedon please re-review |
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 good.
In the PR description you wrote "Note without this fix EventQueue dispatch function is actually broken." : Can you give more details on what is broken?
Difficult to be precise as I saw a variety of effects depending on what values were provided. These ranged from just hanging without actually dispatching the event to core dumping the chip. I can certainly add that. |
This pull request has automatically been marked as stale because it has had no recent activity. @ARMmbed/mbed-os-maintainers, please start CI to get the PR merged. |
CI started |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Summary of changes
Main dispatch function is updated to take a Chrono duration instead of an integer milliseconds parameter.
To allow for the instances of blocking and non wait versions, which previously were actioned by passing either -1 or 0 as the millisecond delay respectively, two other functions are now available.
dispatch_once() - new
dispatch_forever() - internally modified from the original version but no change in functionality
Note without this fix EventQueue dispatch function is actually broken. Events may not be dispatched at all or in the worst case the chip will crash.
Impact of changes
This is an API change, affecting the following areas:
E.g. '100ms'
Migration actions required
The following migrations actions are required:
as simple as adding 'ms' to any passed literal value. E.g. '100' becomes '100ms'. Variables passed in will need to be explicitly
converted.
Documentation
EventQueue docs may need to be updated . Code snippet examples will certainly need to be.
NB. This also has an impact on the Events snippet example as that uses the EventQueue.dispatch() function.
Pull request type
Test results
Reviewers
@kjbracey-arm @donatieng @pan-