diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c index e303367c29f..3723d21f885 100644 --- a/dlls/ntdll/unix/sync.c +++ b/dlls/ntdll/unix/sync.c @@ -2788,10 +2788,39 @@ NTSTATUS WINAPI NtDelayExecution( BOOLEAN alertable, const LARGE_INTEGER *timeou } else { + LONGLONG ticks = timeout->QuadPart; LARGE_INTEGER now; - timeout_t when, diff; + timeout_t when = ticks, diff; - if ((when = timeout->QuadPart) < 0) +#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_NANOSLEEP) + static BOOL disable_clock_nanosleep = FALSE; + if (!disable_clock_nanosleep && ticks != 0) + { + struct timespec when; + int err; + + if (ticks < 0) + { + clock_gettime( CLOCK_REALTIME, &when ); + when.tv_sec += (time_t)(-ticks / TICKSPERSEC); + when.tv_nsec += (long)((-ticks % TICKSPERSEC) * 100); + } + else + { + when.tv_sec = (time_t)((ticks / TICKSPERSEC) - SECS_1601_TO_1970); + when.tv_nsec = (long)((ticks % TICKSPERSEC) * 100); + } + + usleep(0); + while ((err = clock_nanosleep( CLOCK_REALTIME, TIMER_ABSTIME, &when, NULL )) == EINTR); + if (!err) + return STATUS_SUCCESS; + else + disable_clock_nanosleep = TRUE; + } +#endif + + if (when < 0) { NtQuerySystemTime( &now ); when = now.QuadPart - when;