diff options
Diffstat (limited to 'timer/src')
-rw-r--r-- | timer/src/timer.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/timer/src/timer.c b/timer/src/timer.c index 340cd98..d886f59 100644 --- a/timer/src/timer.c +++ b/timer/src/timer.c | |||
@@ -78,7 +78,7 @@ time_delta sec_to_time_delta(double seconds) { | |||
78 | #ifdef _WIN32 | 78 | #ifdef _WIN32 |
79 | return (time_delta)(seconds / seconds_per_count); | 79 | return (time_delta)(seconds / seconds_per_count); |
80 | #else | 80 | #else |
81 | return (time_delta)(seconds * nanoseconds); | 81 | return (time_delta)(seconds * 1.0e9); |
82 | #endif | 82 | #endif |
83 | } | 83 | } |
84 | 84 | ||
@@ -90,9 +90,20 @@ uint64_t time_point_to_ns(time_point t) { | |||
90 | #endif | 90 | #endif |
91 | } | 91 | } |
92 | 92 | ||
93 | time_point time_add(time_point t, time_delta dt) { | ||
94 | time_point out; | ||
95 | #ifdef _WIN32 | ||
96 | out = t + dt; | ||
97 | #else | ||
98 | out.tv_sec = t.tv_sec + (__time_t)(dt / nanoseconds); | ||
99 | out.tv_nsec = t.tv_nsec + (__time_t)(dt % nanoseconds); | ||
100 | #endif | ||
101 | return out; | ||
102 | } | ||
103 | |||
93 | void time_sleep(time_delta dt) { | 104 | void time_sleep(time_delta dt) { |
94 | #ifdef _WIN32 | 105 | #ifdef _WIN32 |
95 | const int64_t ms = dt / microseconds; | 106 | const uint64_t ms = dt / microseconds; |
96 | Sleep((DWORD)(ms)); | 107 | Sleep((DWORD)(ms)); |
97 | #else | 108 | #else |
98 | const uint64_t sec = dt / nanoseconds; | 109 | const uint64_t sec = dt / nanoseconds; |