time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.

Make it easy to compare 'struct timeval's and get their difference.
pull/4785/head
Todd Mortimer 5 years ago committed by Victor Julien
parent e945dea244
commit 9fafc1031c

@ -33,6 +33,17 @@ void TimeGet(struct timeval *);
/** \brief intialize a 'struct timespec' from a 'struct timeval'. */
#define FROM_TIMEVAL(timev) { .tv_sec = (timev).tv_sec, .tv_nsec = (timev).tv_usec * 1000 }
/** \brief compare two 'struct timeval' and return the difference in seconds */
#define TIMEVAL_DIFF_SEC(tv_new, tv_old) \
(uint64_t)((((uint64_t)(tv_new).tv_sec * 1000000 + (tv_new).tv_usec) - \
((uint64_t)(tv_old).tv_sec * 1000000 + (tv_old).tv_usec)) / \
1000000)
/** \brief compare two 'struct timeval' and return if the first is earlier than the second */
#define TIMEVAL_EARLIER(tv_first, tv_second) \
(((tv_first).tv_sec < (tv_second).tv_sec) || \
((tv_first).tv_sec == (tv_second).tv_sec && (tv_first).tv_usec < (tv_second).tv_usec))
#ifdef UNITTESTS
void TimeSet(struct timeval *);
void TimeSetToCurrentTime(void);

Loading…
Cancel
Save