util/time: add os_time_nanosleep_until() function
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34242>
This commit is contained in:
committed by
Marge Bot
parent
00d905c4b2
commit
699ae0aad9
@@ -60,7 +60,21 @@ os_time_get_nano(void)
|
||||
return ts.tv_nsec + ts.tv_sec*INT64_C(1000000000);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
os_time_nanosleep_until(int64_t deadline)
|
||||
{
|
||||
#if DETECT_OS_LINUX || DETECT_OS_MANAGARM
|
||||
struct timespec time;
|
||||
time.tv_sec = deadline / INT64_C(1000000000);
|
||||
time.tv_nsec = deadline % INT64_C(1000000000);
|
||||
while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time, &time) == EINTR);
|
||||
#else
|
||||
int64_t duration = deadline - os_time_get_nano();
|
||||
if (duration > 0) {
|
||||
os_time_sleep(duration / 1000);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
os_time_sleep(int64_t usecs)
|
||||
|
||||
@@ -74,6 +74,8 @@ os_localtime(const time_t *timer, struct tm *buf)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
os_time_nanosleep_until(int64_t deadline);
|
||||
|
||||
/*
|
||||
* Sleep.
|
||||
|
||||
Reference in New Issue
Block a user