Files
CgeThread/posix/Timespec.h
Mikhail Romanko 04e02490b7
Some checks failed
CI / build-and-analyze (push) Failing after 1m18s
Initial commit
2026-08-09 12:55:16 +03:00

33 lines
680 B
C

#ifndef CGE_THREAD_TIMESPEC_H
#define CGE_THREAD_TIMESPEC_H
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
static int convertToTimespec(struct timespec *ts, uint32_t timeout) {
#if (_POSIX_TIMERS > 0)
if (clock_gettime(CLOCK_REALTIME, ts))
#endif
{
struct timeval tv;
if (gettimeofday(&tv, NULL))
return 0;
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;
}
ts->tv_sec += timeout / 1000;
ts->tv_nsec += (timeout % 1000) * 1000000;
while (ts->tv_nsec >= 1000000000) {
ts->tv_nsec -= 1000000000;
ts->tv_sec += 1;
}
return 1;
}
#endif /* CGE_THREAD_TIMESPEC_H */