#ifndef UC_TIME_H_ #define UC_TIME_H_ #include #include /** Add two struct timeval. * * @param dst where to store the result * @param a first timeval to add * @param b second timeval to add * @return dst */ struct timeval *uc_tvadd(struct timeval *dst, const struct timeval *a, const struct timeval *b); /** Subtract two struct timeval. * * @param dst where to store the result * @param a first timeval to subtract * @param b second timeval to subtract * @return dst */ struct timeval *uc_tvsub(struct timeval *dst, const struct timeval *a, const struct timeval *b); /** Add two struct timevals. * * @param dst where to store the result * @param a first timeval to add * @param b second timeval to add * @return dst */ int uc_tvcmp(const struct timeval *a, const struct timeval *b); /** Add two struct timespec. * * @param dst where to store the result * @param a first timespec to add * @param b second timespec to add * @return dst */ struct timespec *uc_tsadd(struct timespec *dst, const struct timespec *a, const struct timespec *b); /** Subtract two struct timespec. * * @param dst where to store the result * @param a first timespec to subtract * @param b second timespec to subtract * @return dst */ struct timespec *uc_tssub(struct timespec *dst, const struct timespec *a, const struct timespec *b); /** Add two struct timespec. * * @param a first timespec to add * @param b second timespec to add * @return < 0 if a is less than b, 0 if a and be are equal, > 0 if a is greater than b */ int uc_tscmp(const struct timespec *a, const struct timespec *b); static inline uint64_t uc_tv2milisec(const struct timeval *t) { return t->tv_sec * 1000 + t->tv_usec / 1000; } static inline uint64_t uc_ts2milisec(const struct timespec *t) { return t->tv_sec * 1000 + t->tv_nsec / 10000000; } static inline uint64_t uc_ts2nanosec(const struct timespec *t) { return t->tv_sec * 1000000000ULL + t->tv_nsec; } /** Convert number of miliseconds to a timeval. * * @param dst where to store the result * @param ms number of miliseconds * @return dst */ struct timeval *uc_ms2tv(struct timeval *dst, uint64_t ms); #endif