mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
timing: added new function to compare timestamps
This commit is contained in:
parent
ed27d25823
commit
83ca82204c
2 changed files with 11 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Add table
Reference in a new issue