22 #ifndef LELY_UTIL_TIME_H_
23 #define LELY_UTIL_TIME_H_
29 #ifndef LELY_UTIL_TIME_INLINE
30 #define LELY_UTIL_TIME_INLINE static inline
39 struct timespec *tp,
const struct timespec *inc);
43 struct timespec *tp, uint_least64_t sec);
47 struct timespec *tp, uint_least64_t msec);
51 struct timespec *tp, uint_least64_t usec);
55 struct timespec *tp, uint_least64_t nsec);
59 struct timespec *tp,
const struct timespec *dec);
63 struct timespec *tp, uint_least64_t sec);
67 struct timespec *tp, uint_least64_t msec);
71 struct timespec *tp, uint_least64_t usec);
75 struct timespec *tp, uint_least64_t nsec);
82 const struct timespec *t1,
const struct timespec *t2);
90 const struct timespec *t1,
const struct timespec *t2);
98 const struct timespec *t1,
const struct timespec *t2);
105 const struct timespec *t1,
const struct timespec *t2);
114 LELY_UTIL_TIME_INLINE
int timespec_cmp(
const void *p1,
const void *p2);
119 tp->tv_sec += inc->tv_sec;
120 tp->tv_nsec += inc->tv_nsec;
122 if (tp->tv_nsec >= 1000000000l) {
124 tp->tv_nsec -= 1000000000l;
137 struct timespec inc = { (time_t)(msec / 1000),
138 (long)((msec % 1000) * 1000000l) };
145 struct timespec inc = { (time_t)(usec / 1000000l),
146 (long)((usec % 1000000l) * 1000) };
153 struct timespec inc = { (time_t)(nsec / 1000000000l),
154 (long)(nsec % 1000000000l) };
161 tp->tv_sec -= dec->tv_sec;
162 tp->tv_nsec -= dec->tv_nsec;
164 if (tp->tv_nsec < 0) {
166 tp->tv_nsec += 1000000000l;
179 struct timespec dec = { (time_t)(msec / 1000),
180 (long)((msec % 1000) * 1000000l) };
187 struct timespec dec = { (time_t)(usec / 1000000l),
188 (long)((usec % 1000000l) * 1000) };
195 struct timespec dec = { (time_t)(nsec / 1000000000l),
196 (long)(nsec % 1000000000l) };
203 return t1->tv_sec - t2->tv_sec;
209 return (int_least64_t)(t1->tv_sec - t2->tv_sec) * 1000
210 + (t1->tv_nsec - t2->tv_nsec) / 1000000l;
216 return (int_least64_t)(t1->tv_sec - t2->tv_sec) * 1000000l
217 + (t1->tv_nsec - t2->tv_nsec) / 1000;
223 return (int_least64_t)(t1->tv_sec - t2->tv_sec) * 1000000000l
224 + t1->tv_nsec - t2->tv_nsec;
238 const struct timespec *t1 = (
const struct timespec *)p1;
239 const struct timespec *t2 = (
const struct timespec *)p2;
241 int cmp = (t2->tv_sec < t1->tv_sec) - (t1->tv_sec < t2->tv_sec);
243 cmp = (t2->tv_nsec < t1->tv_nsec) - (t1->tv_nsec < t2->tv_nsec);
251 #endif // !LELY_UTIL_TIME_H_