From 83ca82204c215813dd0909cabb695b50232e0405 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sat, 20 Oct 2018 15:36:27 +0200 Subject: [PATCH] timing: added new function to compare timestamps --- include/villas/timing.h | 3 +++ lib/timing.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/include/villas/timing.h b/include/villas/timing.h index c005fee19..1dcbc0b51 100644 --- a/include/villas/timing.h +++ b/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/lib/timing.c b/lib/timing.c index 4ac408a25..915f94265 100644 --- a/lib/timing.c +++ b/lib/timing.c @@ -48,6 +48,14 @@ struct timespec time_add(const struct timespec *start, const struct timespec *en return sum; } +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; +} + struct timespec time_diff(const struct timespec *start, const struct timespec *end) { struct timespec diff = {