-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[Backport v3.2-branch] lib: posix: make sleep() and usleep() standards-compliant #52545
Conversation
Using `usleep()` for >= 10000000 microseconds results in an error, so this test was kind of defective, having explicitly called `usleep()` for seconds. Also, check the return values of `clock_gettime()`. Signed-off-by: Chris Friedt <cfriedt@meta.com> (cherry picked from commit 23a1f0a)
In the case that `sleep()` is interrupted, the POSIX spec requires it to return the number of "unslept" seconds (i.e. the number of seconds requested minus the number of seconds actually slept). Since `k_sleep()` already returns the amount of "unslept" time in ms, we can simply use that. Signed-off-by: Chris Friedt <cfriedt@meta.com> (cherry picked from commit dcfcc64)
The original implementation of `usleep()` was not compliant to the POSIX spec in 3 ways. - calling thread may not be suspended (because `k_busy_wait()` was previously used for short durations) - if `usecs` > 1000000, previously we did not return -1 or set `errno` to `EINVAL` - if interrupted, previously we did not return -1 or set `errno` to `EINTR` This change addresses those issues to make `usleep()` more POSIX-compliant. Signed-off-by: Chris Friedt <cfriedt@meta.com> (cherry picked from commit 7b95428)
Previously, there was no test coverage for `sleep()` and `usleep()`. This change adds full test coverage. Signed-off-by: Chris Friedt <cfriedt@meta.com> (cherry picked from commit 027b79e)
Codecov Report
@@ Coverage Diff @@
## v3.2-branch #52545 +/- ##
==============================================
Coverage ? 50.53%
==============================================
Files ? 711
Lines ? 89949
Branches ? 21250
==============================================
Hits ? 45455
Misses ? 36793
Partials ? 7701 Continue to review full report at Codecov.
|
Backport 027b79e~4..027b79e from #52519
Fixes #51776
Fixes #52517
Fixes #52518