mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-07 08:52:01 +00:00
Further improve sleep accuracy on UNIX systems
This commit is contained in:
parent
3e6862b1c2
commit
c00d139e55
1 changed files with 15 additions and 7 deletions
|
@ -2309,13 +2309,21 @@ 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();
|
||||||
struct timespec ts = {
|
precise_t dest = I_GetPreciseTime() + duration;
|
||||||
.tv_sec = duration / precision,
|
if (duration > 100000)
|
||||||
.tv_nsec = duration * 1000000000 / precision % 1000000000,
|
{
|
||||||
};
|
duration -= 100000; // 0.1 ms slack
|
||||||
int status;
|
struct timespec ts = {
|
||||||
do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts);
|
.tv_sec = duration / precision,
|
||||||
while (status == EINTR);
|
.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)
|
#elif defined (MIN_SLEEP_DURATION_MS)
|
||||||
UINT64 precision = I_GetPrecisePrecision();
|
UINT64 precision = I_GetPrecisePrecision();
|
||||||
INT32 sleepvalue = cv_sleep.value;
|
INT32 sleepvalue = cv_sleep.value;
|
||||||
|
|
Loading…
Reference in a new issue