-
Notifications
You must be signed in to change notification settings - Fork 3k
Unification of wait functions #2274
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
This commit adds two implementations for the mbed wait functions (wait, wait_ms, wait_us): - with the RTOS present, the wait functions will use `Thread::wait` for millisecond delays and a busy wait loop for sub-millisecond delays. - with the RTOS not present, the wait functions will always use a busy wait loop.
Possible issues with this PR:
|
+1 This looks great to me! Now that I think about it, won't the previous |
You're right, any blocking function that relies on its blocking behaviour for timing will have a problem in a preemptive RTOS environment. |
I think this may actually handle interrupt context correctly based on the implementation of core_util_are_interrupts_enabled: |
} | ||
|
||
void wait_ms(int ms) { | ||
wait_us(ms * 1000); |
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 might consider having wait and wait_ms use Thread:wait exclusively, since the RTOS will get you very close to ms resoultion
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'd mean adding core_utils_are_interrupts_enabled
checks to each wait
function. Not sure this is needed.
LGTM 👍 |
Added a new commit that potentially improves the accuracy of |
This commit adds two implementations for the mbed wait functions (wait,
wait_ms, wait_us):
Thread::wait
formillisecond delays and a busy wait loop for sub-millisecond delays.
wait loop.