From a560a6211868d517908f44e1ea90336b18cdb97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Tue, 22 Aug 2017 18:02:12 +0200 Subject: Make OS::delay_usec() more reliable on UNIX Implemented with `nanosleep()`. `usleep()` is deprecated. Also loops to ensure that __at least__ the requested time is waited, accounting for spurious interruptions. May help in situations like reattempting to connect to the debugger. --- drivers/unix/os_unix.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/unix/os_unix.cpp') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 0f4e8f757c..7698bb2fa1 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -315,7 +315,9 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { void OS_Unix::delay_usec(uint32_t p_usec) const { - usleep(p_usec); + struct timespec rem = { p_usec / 1000000, (p_usec % 1000000) * 1000 }; + while (nanosleep(&rem, &rem) == EINTR) { + } } uint64_t OS_Unix::get_ticks_usec() const { -- cgit v1.2.3