timekeeper: redo timekeeping

This commit is contained in:
Matheus
2024-09-29 11:20:40 -03:00
parent bb910d9e20
commit b8acbc5bcd
12 changed files with 280 additions and 96 deletions
+18
View File
@@ -2,6 +2,7 @@
#define _TIME_H
#include <util.h>
#include <stdbool.h>
typedef long time_t;
typedef long suseconds_t;
@@ -39,4 +40,21 @@ static inline time_t timespec_ns(timespec_t a) {
return a.ns + a.s * 1000000000;
}
static inline time_t timespec_us(timespec_t a) {
return a.ns / 1000 + a.s * 1000000;
}
static inline timespec_t timespec_from_us(time_t us) {
timespec_t ts = {
.s = us / 1000000,
.ns = (us % 1000000) * 100
};
return ts;
}
static inline bool timespec_bigger(timespec_t t1, timespec_t t2) {
return t1.s > t2.s || (t1.s == t2.s && t1.ns > t2.ns);
}
#endif