diff options
Diffstat (limited to 'src/Platform/Posix/Timespec.h')
| -rw-r--r-- | src/Platform/Posix/Timespec.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Platform/Posix/Timespec.h b/src/Platform/Posix/Timespec.h new file mode 100644 index 0000000..1582f86 --- /dev/null +++ b/src/Platform/Posix/Timespec.h @@ -0,0 +1,23 @@ +#ifndef BH_PLATFORM_POSIX_TIMESPEC_H +#define BH_PLATFORM_POSIX_TIMESPEC_H + + +#include <BH/Thread.h> +#include <time.h> + + +static void convertToTimespec(struct timespec *ts, + uint32_t timeout) +{ + /* 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; + } +} + + +#endif /* BH_PLATFORM_POSIX_TIMESPEC_H */ |
