diff options
Diffstat (limited to 'src/Platform/Posix/Timespec.h')
| -rw-r--r-- | src/Platform/Posix/Timespec.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/Platform/Posix/Timespec.h b/src/Platform/Posix/Timespec.h index 1582f86..4bd673f 100644 --- a/src/Platform/Posix/Timespec.h +++ b/src/Platform/Posix/Timespec.h @@ -3,21 +3,35 @@ #include <BH/Thread.h> +#include <sys/time.h> #include <time.h> -static void convertToTimespec(struct timespec *ts, +static int convertToTimespec(struct timespec *ts, uint32_t timeout) { +#ifdef USE_CLOCK_GETTIME + if (clock_gettime(CLOCK_REALTIME, ts)) + return BH_ERROR; +#else + struct timeval tv; + + if (gettimeofday(&tv, NULL)) + return BH_ERROR; + + ts->tv_sec = tv.tv_sec; + ts->tv_nsec = tv.tv_usec * 1000; +#endif + /* Calculate absoulute time for timed wait */ - clock_gettime(CLOCK_REALTIME, ts); 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 BH_OK; } - #endif /* BH_PLATFORM_POSIX_TIMESPEC_H */ |
