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; +}