+static inline void timespec_add (struct timespec *tsa, const struct timespec *tsb)
+{
+ tsa->tv_sec += tsb->tv_sec;
+ tsa->tv_nsec += tsb->tv_nsec;
+ while (tsa->tv_nsec >= 1000000000) {
+ tsa->tv_nsec -= 1000000000;
+ tsa->tv_sec++;
+ }
+}
+
+
+static inline int timespec_diff_ms (const struct timespec *tsa, const struct timespec *tsb)
+{
+ int diff = (tsb->tv_sec - tsa->tv_sec) * 1000;
+
+ if (tsb->tv_sec > tsa->tv_sec)
+ diff += (tsb->tv_nsec - tsa->tv_nsec) / 1000000;
+ else
+ diff -= (tsb->tv_nsec - tsa->tv_nsec) / 1000000;
+
+ return diff;
+}
+
+
+static inline void timeval_to_timespec (struct timespec *ts, const struct timeval *tv)
+{
+ ts->tv_sec = tv->tv_sec;
+ ts->tv_nsec = tv->tv_usec * 1000;
+}
+
+