Skip to content
Snippets Groups Projects
Commit fb80091a authored by Hanicef's avatar Hanicef
Browse files

Double slack time for busy-wait

parent 1da55066
No related branches found
No related tags found
No related merge requests found
...@@ -376,6 +376,11 @@ void I_SleepDuration(precise_t duration) ...@@ -376,6 +376,11 @@ void I_SleepDuration(precise_t duration)
{ {
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
UINT64 precision = I_GetPrecisePrecision(); 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 = { struct timespec ts = {
.tv_sec = duration / precision, .tv_sec = duration / precision,
.tv_nsec = duration * 1000000000 / precision % 1000000000, .tv_nsec = duration * 1000000000 / precision % 1000000000,
...@@ -383,6 +388,10 @@ void I_SleepDuration(precise_t duration) ...@@ -383,6 +388,10 @@ void I_SleepDuration(precise_t duration)
int status; int status;
do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts);
while (status == EINTR); while (status == EINTR);
}
// busy-wait the rest
while (((INT64)dest - (INT64)I_GetPreciseTime()) > 0);
#else #else
UINT64 precision = I_GetPrecisePrecision(); UINT64 precision = I_GetPrecisePrecision();
INT32 sleepvalue = cv_sleep.value; INT32 sleepvalue = cv_sleep.value;
......
...@@ -2310,7 +2310,7 @@ void I_SleepDuration(precise_t duration) ...@@ -2310,7 +2310,7 @@ void I_SleepDuration(precise_t duration)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) #if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__)
UINT64 precision = I_GetPrecisePrecision(); UINT64 precision = I_GetPrecisePrecision();
precise_t dest = I_GetPreciseTime() + duration; precise_t dest = I_GetPreciseTime() + duration;
precise_t slack = (precision / 10000); // 0.1 ms slack precise_t slack = (precision / 5000); // 0.2 ms slack
if (duration > slack) if (duration > slack)
{ {
duration -= slack; duration -= slack;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment