1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

timing: add new function to compare timestamps

This commit is contained in:
Steffen Vogel 2018-10-21 20:24:32 +01:00
parent 592d07a32d
commit 4715706f85
2 changed files with 11 additions and 0 deletions

View file

@ -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);

View file

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