From 4715706f85a6c4d7f7af564c10cb379e1d880c03 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 21 Oct 2018 20:24:32 +0100 Subject: [PATCH] timing: add new function to compare timestamps --- common/include/villas/timing.h | 3 +++ common/lib/timing.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/common/include/villas/timing.h b/common/include/villas/timing.h index 8a887ec5f..17e0d9d9a 100644 --- a/common/include/villas/timing.h +++ b/common/include/villas/timing.h @@ -32,6 +32,9 @@ extern "C" { #endif +/** Compare two timestamps. Return zero if they are equal */ +ssize_t time_cmp(const struct timespec *a, const struct timespec *b); + /** Get delta between two timespec structs */ struct timespec time_diff(const struct timespec *start, const struct timespec *end); diff --git a/common/lib/timing.c b/common/lib/timing.c index 9324c895a..980b6e203 100644 --- a/common/lib/timing.c +++ b/common/lib/timing.c @@ -84,3 +84,11 @@ double time_delta(const struct timespec *start, const struct timespec *end) return time_to_double(&diff); } + +ssize_t time_cmp(const struct timespec *a, const struct timespec *b) +{ + ssize_t sd = a->tv_sec - b->tv_sec; + ssize_t nsd = a->tv_nsec - b->tv_nsec; + + return sd != 0 ? sd : nsd; +}