@@ -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.
*/
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(+)