mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-09-02 10:21:10 +02:00
driver/abstime.c: add time_monotonic_us
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h> /* for perror */
|
||||
#include <time.h>
|
||||
|
||||
@@ -27,3 +28,14 @@ time_t time_monotonic(void)
|
||||
time comparisons if the uptime is low, so add 7 days */
|
||||
return t.tv_sec + 604800;
|
||||
}
|
||||
|
||||
uint64_t time_monotonic_us(void)
|
||||
{
|
||||
struct timespec t;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &t))
|
||||
{
|
||||
perror("time_monotonic_us clock_gettime");
|
||||
return -1;
|
||||
}
|
||||
return ((int64_t)t.tv_sec + (uint64_t)604800) * (uint64_t) 1000000 + (uint64_t) t.tv_nsec / (uint64_t)1000;
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _ABS_TIME_H_
|
||||
#define _ABS_TIME_H_
|
||||
#ifdef __cplusplus
|
||||
@@ -6,6 +8,7 @@ extern "C"
|
||||
#endif
|
||||
extern time_t time_monotonic_ms(void);
|
||||
extern time_t time_monotonic(void);
|
||||
uint64_t time_monotonic_us(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user