diff options
author | Lorenz Junglas <lolleko@users.noreply.github.com> | 2020-10-12 16:27:31 +0200 |
---|---|---|
committer | Lorenz Junglas <lolleko@users.noreply.github.com> | 2020-10-12 16:27:31 +0200 |
commit | 1107c7f327f6d14010b4bd45b25e3c47f89b9948 (patch) | |
tree | e98f9a38594140b424c4a0cecda73612de88be9a /drivers/unix | |
parent | ab0907c1bab2b1f4131aa63d24f9d337692d64a6 (diff) |
Fix nanosleep usage
nanosleep returns 0 or -1 not the error code.
The error code "EINTR" (if encountered) is placed in errno, in which case nanosleep can be safely recalled with the remaining time.
This is required, so that nanosleep continues if the calling thread is interrupted by a signal.
See manpage nanosleep(2) for additional details.
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/os_unix.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 96c338f86b..dac4d6ab01 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -235,8 +235,11 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { } void OS_Unix::delay_usec(uint32_t p_usec) const { - struct timespec rem = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 }; - while (nanosleep(&rem, &rem) == EINTR) { + struct timespec requested = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 }; + struct timespec remaining; + while (nanosleep(&requested, &remaining) == -1 && errno == EINTR) { + requested.tv_sec = remaining.tv_sec; + requested.tv_nsec = remaining.tv_nsec; } } |