diff options
author | Daniel Stone <daniels@collabora.com> | 2017-03-01 11:34:03 +0000 |
---|---|---|
committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2017-03-13 14:20:06 +0200 |
commit | 839b63546d2e69e3bf863d0de701817524e5c1d1 (patch) | |
tree | 28c99402b393be6462829e1cea6dd248623853c3 /shared | |
parent | 37ad7e3bae090c8791dc638bfc3f952fb5c12acf (diff) |
timespec: Add timespec subtraction helpers
Add helpers to subtract two timespecs, then return the difference in
either milliseconds or nanoseconds. These will be used to compare
timestamps during the repaint cycle.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Suggested-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/timespec-util.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/shared/timespec-util.h b/shared/timespec-util.h index 958adb05..576b3e8f 100644 --- a/shared/timespec-util.h +++ b/shared/timespec-util.h @@ -93,6 +93,20 @@ timespec_to_nsec(const struct timespec *a) return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec; } +/* Subtract timespecs and return result in nanoseconds + * + * \param a[in] operand + * \param b[in] operand + * \return to_nanoseconds(a - b) + */ +static inline int64_t +timespec_sub_to_nsec(const struct timespec *a, const struct timespec *b) +{ + struct timespec r; + timespec_sub(&r, a, b); + return timespec_to_nsec(&r); +} + /* Convert timespec to milliseconds * * \param a timespec @@ -106,6 +120,18 @@ timespec_to_msec(const struct timespec *a) return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; } +/* Subtract timespecs and return result in milliseconds + * + * \param a[in] operand + * \param b[in] operand + * \return to_milliseconds(a - b) + */ +static inline int64_t +timespec_sub_to_msec(const struct timespec *a, const struct timespec *b) +{ + return timespec_sub_to_nsec(a, b) / 1000000; +} + /* Convert milli-Hertz to nanoseconds * * \param mhz frequency in mHz, not zero |