shared: Add timespec_is_zero helper

Add a helper function to check if a struct timespec is zero. This helper
will be used in the upcoming commits to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Alexandros Frantzis
2017-11-27 10:54:49 +02:00
committed by Pekka Paalanen
parent 0343c6ac69
commit e2a5f9e02d
2 changed files with 23 additions and 0 deletions
+12
View File
@@ -29,6 +29,7 @@
#include <stdint.h>
#include <assert.h>
#include <time.h>
#include <stdbool.h>
#define NSEC_PER_SEC 1000000000
@@ -133,6 +134,17 @@ timespec_sub_to_msec(const struct timespec *a, const struct timespec *b)
return timespec_sub_to_nsec(a, b) / 1000000;
}
/* Check if a timespec is zero
*
* \param a timespec
* \return whether the timespec is zero
*/
static inline bool
timespec_is_zero(const struct timespec *a)
{
return a->tv_sec == 0 && a->tv_nsec == 0;
}
/* Convert milli-Hertz to nanoseconds
*
* \param mhz frequency in mHz, not zero