aboutsummaryrefslogtreecommitdiff
path: root/Spear/Sys/Timer
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Sys/Timer')
-rw-r--r--Spear/Sys/Timer/timer.c11
-rw-r--r--Spear/Sys/Timer/timer.h3
2 files changed, 13 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
90void 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
90void time_sleep(time_delta dt) { 99void 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;
diff --git a/Spear/Sys/Timer/timer.h b/Spear/Sys/Timer/timer.h
index e426135..da4e7c7 100644
--- a/Spear/Sys/Timer/timer.h
+++ b/Spear/Sys/Timer/timer.h
@@ -53,6 +53,9 @@ time_delta sec_to_time_delta(double seconds);
53/// Convert the time point to nanoseconds. 53/// Convert the time point to nanoseconds.
54uint64_t time_point_to_ns(time_point*); 54uint64_t time_point_to_ns(time_point*);
55 55
56/// Add a time delta to a timestamp.
57void time_add(const time_point*, time_delta, time_point* out);
58
56/// Put the caller thread to sleep for the given amount of time. 59/// Put the caller thread to sleep for the given amount of time.
57void time_sleep(time_delta dt); 60void time_sleep(time_delta dt);
58 61