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.
(cherry picked from commit 1107c7f327
)
This commit is contained in:
parent
952a089551
commit
c7f2f9fa1f
1 changed files with 5 additions and 3 deletions
|
@ -257,9 +257,11 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_Unix::delay_usec(uint32_t p_usec) const {
|
void OS_Unix::delay_usec(uint32_t p_usec) const {
|
||||||
|
struct timespec requested = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 };
|
||||||
struct timespec rem = { static_cast<time_t>(p_usec / 1000000), (static_cast<long>(p_usec) % 1000000) * 1000 };
|
struct timespec remaining;
|
||||||
while (nanosleep(&rem, &rem) == EINTR) {
|
while (nanosleep(&requested, &remaining) == -1 && errno == EINTR) {
|
||||||
|
requested.tv_sec = remaining.tv_sec;
|
||||||
|
requested.tv_nsec = remaining.tv_nsec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint64_t OS_Unix::get_ticks_usec() const {
|
uint64_t OS_Unix::get_ticks_usec() const {
|
||||||
|
|
Loading…
Reference in a new issue