18 #ifndef _BOILERPLATE_TIME_H
19 #define _BOILERPLATE_TIME_H
23 typedef unsigned long long ticks_t;
25 typedef long long sticks_t;
31 void timespec_sub(
struct timespec *__restrict r,
32 const struct timespec *__restrict t1,
33 const struct timespec *__restrict t2);
35 void timespec_subs(
struct timespec *__restrict r,
36 const struct timespec *__restrict t1,
39 void timespec_add(
struct timespec *__restrict r,
40 const struct timespec *__restrict t1,
41 const struct timespec *__restrict t2);
43 void timespec_adds(
struct timespec *__restrict r,
44 const struct timespec *__restrict t1,
51 static inline sticks_t timespec_scalar(
const struct timespec *__restrict t)
53 return t->tv_sec * 1000000000LL + t->tv_nsec;
56 static inline int __attribute__ ((always_inline))
57 timespec_before(const struct timespec *__restrict t1,
58 const struct timespec *__restrict t2)
60 if (t1->tv_sec < t2->tv_sec)
63 if (t1->tv_sec == t2->tv_sec &&
64 t1->tv_nsec < t2->tv_nsec)
70 static inline int __attribute__ ((always_inline))
71 timespec_before_or_same(const struct timespec *__restrict t1,
72 const struct timespec *__restrict t2)
74 if (t1->tv_sec < t2->tv_sec)
77 if (t1->tv_sec == t2->tv_sec &&
78 t1->tv_nsec <= t2->tv_nsec)
84 static inline int __attribute__ ((always_inline))
85 timespec_after(const struct timespec *__restrict t1,
86 const struct timespec *__restrict t2)
88 return !timespec_before_or_same(t1, t2);
91 static inline int __attribute__ ((always_inline))
92 timespec_after_or_same(const struct timespec *__restrict t1,
93 const struct timespec *__restrict t2)
95 return !timespec_before(t1, t2);