From 5cbac8c41547207c183716797bb86161df334158 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Apr 2025 16:22:41 +0200 Subject: [PATCH] Revert "temp revert nanosleep for nix" This reverts commit 78cf0d8f9dc46d6f731070ce1c5c3ba946a2ecb5. --- src/sdl/i_system.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 788c703cd..4356f1651 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1805,7 +1805,25 @@ void I_Sleep(UINT32 ms) void I_SleepDuration(precise_t duration) { -#if defined (MIN_SLEEP_DURATION_MS) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) + UINT64 precision = I_GetPrecisePrecision(); + precise_t dest = I_GetPreciseTime() + duration; + precise_t slack = (precision / 5000); // 0.2 ms slack + if (duration > slack) + { + duration -= slack; + struct timespec ts = { + .tv_sec = duration / precision, + .tv_nsec = duration * 1000000000 / precision % 1000000000, + }; + int status; + do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); + while (status == EINTR); + } + + // busy-wait the rest + while (((INT64)dest - (INT64)I_GetPreciseTime()) > 0); +#elif defined (MIN_SLEEP_DURATION_MS) UINT64 precision = I_GetPrecisePrecision(); INT32 sleepvalue = cv_sleep.value; UINT64 delaygranularity;