diff options
author | Rafael David Tinoco <rafael.tinoco@linaro.org> | 2019-01-29 15:36:54 -0200 |
---|---|---|
committer | Cyril Hrubis <chrubis@suse.cz> | 2019-01-30 12:05:30 +0100 |
commit | e744bc9e6396f2c04e4d886bd7076eea9feab4ae (patch) | |
tree | 558a8be29ac5d22e09fc82a90358b96b3c979290 /include | |
parent | 0a84e767100926456e70545ea1642875caec5ef7 (diff) |
tst_timer: Add tst_timespec_add()
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>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'include')
-rw-r--r-- | include/tst_timer.h | 19 |
1 files changed, 19 insertions, 0 deletions
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 @@ -152,6 +152,25 @@ static inline struct timespec tst_timespec_add_us(struct timespec 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. */ static inline struct timespec tst_timespec_diff(struct timespec t1, |