diff options
Diffstat (limited to 'Spear/Sys/Timer')
| -rw-r--r-- | Spear/Sys/Timer/timer.c | 9 | ||||
| -rw-r--r-- | Spear/Sys/Timer/timer.h | 3 |
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 | ||
| 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; |
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. |
| 54 | uint64_t time_point_to_ns(time_point*); | 54 | uint64_t time_point_to_ns(time_point*); |
| 55 | 55 | ||
| 56 | /// Add a time delta to a timestamp. | ||
| 57 | void 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. |
| 57 | void time_sleep(time_delta dt); | 60 | void time_sleep(time_delta dt); |
| 58 | 61 | ||
