diff --git a/src/driver/Makefile.am b/src/driver/Makefile.am index 8cb1f244a..a7fabb57d 100644 --- a/src/driver/Makefile.am +++ b/src/driver/Makefile.am @@ -16,6 +16,7 @@ INCLUDES = \ noinst_LIBRARIES = libneutrino_driver.a libneutrino_driver_netfile.a libneutrino_driver_a_SOURCES = \ + abstime.c \ encoding.cpp \ fontrenderer.cpp \ framebuffer.cpp \ diff --git a/src/driver/abstime.c b/src/driver/abstime.c new file mode 100644 index 000000000..5b3023da1 --- /dev/null +++ b/src/driver/abstime.c @@ -0,0 +1,27 @@ +#include /* for perror */ +#include + +time_t time_monotonic_ms(void) +{ + struct timespec t; + time_t ret; + if (clock_gettime(CLOCK_MONOTONIC, &t)) + { + perror("time_monotonic_ms clock_gettime"); + return -1; + } + ret = (t.tv_sec & 0x01FFFFF) * 1000; /* avoid overflow */ + ret += t.tv_nsec / 1000000; + return ret; +} + +time_t time_monotonic(void) +{ + struct timespec t; + if (clock_gettime(CLOCK_MONOTONIC, &t)) + { + perror("time_monotonic clock_gettime"); + return -1; + } + return t.tv_sec; +} diff --git a/src/driver/abstime.h b/src/driver/abstime.h new file mode 100644 index 000000000..bbd000993 --- /dev/null +++ b/src/driver/abstime.h @@ -0,0 +1,12 @@ +#ifndef _ABS_TIME_H_ +#define _ABS_TIME_H_ +#ifdef __cplusplus +extern "C" +{ +#endif +extern time_t time_monotonic_ms(void); +extern time_t time_monotonic(void); +#ifdef __cplusplus +} +#endif +#endif