diff options
Diffstat (limited to 'src/utils/time.c')
-rw-r--r-- | src/utils/time.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/time.c b/src/utils/time.c new file mode 100644 index 0000000..b6bc960 --- /dev/null +++ b/src/utils/time.c @@ -0,0 +1,23 @@ +#include "time.h" + +#include <time.h> + +int64_t nano_sleep(uint64_t nano_seconds) { + struct timespec remaining, + request = {nano_seconds / NANO_TO_SECOND, nano_seconds % NANO_TO_SECOND}; + nanosleep(&request, &remaining); + int64_t ret = remaining.tv_sec * NANO_TO_SECOND + remaining.tv_nsec; + if (ret < 0 || ret > NANO_TO_SECOND) { // TODO: fix later + return 0; + } else { + return ret; + } +} + +int64_t nano_time() { + struct timespec t = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &t); + return t.tv_sec * NANO_TO_SECOND + t.tv_nsec; +} + + |