diff mbox series

[v4,3/8] tst_timer: Add tst_timespec_add()

Message ID 20190129173659.27901-3-rafael.tinoco@linaro.org
State Accepted
Commit e744bc9e6396f2c04e4d886bd7076eea9feab4ae
Headers show
Series [v4,1/8] lib: add tst_clock_settime() to tst_clocks.h | expand

Commit Message

Rafael David Tinoco Jan. 29, 2019, 5:36 p.m. UTC
This commit adds a tst_timespec_add() function that adds two given
timespec structs. It is needed in order to avoid unneeded ns <-> us
conversions because, so far, there is only tst_timespec_add_us()
available.

Signed-off-by: Rafael David Tinoco <rafael.tinoco@linaro.org>
---
 include/tst_timer.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/include/tst_timer.h b/include/tst_timer.h
index 577bc88ef..b57adf7aa 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -151,6 +151,25 @@  static inline struct timespec tst_timespec_add_us(struct timespec t,
 	return t;
 }
 
+/*
+ * Adds two timespec structures.
+ */
+static inline struct timespec tst_timespec_add(struct timespec t1,
+                                               struct timespec t2)
+{
+	struct timespec res;
+
+	res.tv_sec = t1.tv_sec + t2.tv_sec;
+	res.tv_nsec = t1.tv_nsec + t2.tv_nsec;
+
+	if (res.tv_nsec >= 1000000000) {
+		res.tv_sec++;
+		res.tv_nsec -= 1000000000;
+	}
+
+	return res;
+}
+
 /*
  * Returns difference between two timespec structures.
  */