diff options
Diffstat (limited to 'Spear/Sys/Timer/timer.c')
-rw-r--r-- | Spear/Sys/Timer/timer.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Spear/Sys/Timer/timer.c b/Spear/Sys/Timer/timer.c index 8487f48..4a2fb2b 100644 --- a/Spear/Sys/Timer/timer.c +++ b/Spear/Sys/Timer/timer.c | |||
@@ -48,7 +48,7 @@ void time_now(time_point* t) { | |||
48 | #ifdef _WIN32 | 48 | #ifdef _WIN32 |
49 | QueryPerformanceCounter((LARGE_INTEGER*)t); | 49 | QueryPerformanceCounter((LARGE_INTEGER*)t); |
50 | #else | 50 | #else |
51 | clock_gettime(CLOCK_REALTIME, t); | 51 | clock_gettime(CLOCK_MONOTONIC_RAW, t); |
52 | #endif | 52 | #endif |
53 | } | 53 | } |
54 | 54 | ||
@@ -87,6 +87,15 @@ uint64_t time_point_to_ns(time_point* t) { | |||
87 | #endif | 87 | #endif |
88 | } | 88 | } |
89 | 89 | ||
90 | void time_add(const time_point* t, time_delta dt, time_point* out) { | ||
91 | #ifdef _WIN32 | ||
92 | *out = *t + dt; | ||
93 | #else | ||
94 | out->tv_sec = t->tv_sec + (dt / nanoseconds); | ||
95 | out->tv_nsec = t->tv_nsec + (dt % nanoseconds); | ||
96 | #endif | ||
97 | } | ||
98 | |||
90 | void time_sleep(time_delta dt) { | 99 | void time_sleep(time_delta dt) { |
91 | #ifdef _WIN32 | 100 | #ifdef _WIN32 |
92 | const int64_t ms = dt / microseconds; | 101 | const int64_t ms = dt / microseconds; |