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 = {