mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 21:28:21 +00:00
timekeeper: redo timekeeping
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user