[PATCH weston v2 1/6] shared: Add timespec_eq helper function
Alexandros Frantzis
alexandros.frantzis at collabora.com
Fri Feb 16 16:44:14 UTC 2018
Add a helper function to check if two struct timespec values are equal.
This helper function will be used in upcoming commits that implement the
input_timestamps_unstable_v1 protocol.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
Changes in v2:
- No changes.
shared/timespec-util.h | 13 +++++++++++++
tests/timespec-test.c | 12 ++++++++++++
2 files changed, 25 insertions(+)
diff --git a/shared/timespec-util.h b/shared/timespec-util.h
index 5f4b2b9e..ca0156af 100644
--- a/shared/timespec-util.h
+++ b/shared/timespec-util.h
@@ -231,6 +231,19 @@ timespec_is_zero(const struct timespec *a)
return a->tv_sec == 0 && a->tv_nsec == 0;
}
+/* Check if two timespecs are equal
+ *
+ * \param a[in] timespec to check
+ * \param b[in] timespec to check
+ * \return whether timespecs a and b are equal
+ */
+static inline bool
+timespec_eq(const struct timespec *a, const struct timespec *b)
+{
+ return a->tv_sec == b->tv_sec &&
+ a->tv_nsec == b->tv_nsec;
+}
+
/* Convert milli-Hertz to nanoseconds
*
* \param mhz frequency in mHz, not zero
diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index 54230f89..24400187 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -294,3 +294,15 @@ ZUC_TEST(timespec_test, timespec_is_zero)
ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_nsec));
ZUC_ASSERT_FALSE(timespec_is_zero(&non_zero_sec));
}
+
+ZUC_TEST(timespec_test, timespec_eq)
+{
+ struct timespec a = { .tv_sec = 2, .tv_nsec = 1 };
+ struct timespec b = { .tv_sec = -1, .tv_nsec = 2 };
+
+ ZUC_ASSERT_TRUE(timespec_eq(&a, &a));
+ ZUC_ASSERT_TRUE(timespec_eq(&b, &b));
+
+ ZUC_ASSERT_FALSE(timespec_eq(&a, &b));
+ ZUC_ASSERT_FALSE(timespec_eq(&b, &a));
+}
--
2.14.1
More information about the wayland-devel
mailing list