aboutsummaryrefslogtreecommitdiff
path: root/Spear/Sys/Timer
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Sys/Timer')
-rw-r--r--Spear/Sys/Timer/timer.c9
-rw-r--r--Spear/Sys/Timer/timer.h3
2 files changed, 12 insertions, 0 deletions
diff --git a/Spear/Sys/Timer/timer.c b/Spear/Sys/Timer/timer.c
index 707cd63..4a2fb2b 100644
--- a/Spear/Sys/Timer/timer.c
+++ b/Spear/Sys/Timer/timer.c
@@ -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