diff options
| author | Rafael David Tinoco <rafael.tinoco@linaro.org> | 2019-01-29 15:36:56 -0200 |
|---|---|---|
| committer | Cyril Hrubis <chrubis@suse.cz> | 2019-01-30 14:22:37 +0100 |
| commit | 8a7948b307c2c28cdcf5b8b83debf87cfe929ebd (patch) | |
| tree | 9c089630de235007ad7af86637b6ef6f1221b9ad /include/tst_timer.h | |
| parent | 14e435649d2cd228ed54daf497273740455addf7 (diff) | |
| download | platform_external_ltp-8a7948b307c2c28cdcf5b8b83debf87cfe929ebd.tar.gz platform_external_ltp-8a7948b307c2c28cdcf5b8b83debf87cfe929ebd.tar.bz2 platform_external_ltp-8a7948b307c2c28cdcf5b8b83debf87cfe929ebd.zip | |
tst_timer: Add tst_timespec_sub_us()
This commit adds a tst_timespec_sub_us() function that subtracts
microseconds from a given timespec struct.
Signed-off-by: Rafael David Tinoco <rafael.tinoco@linaro.org>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'include/tst_timer.h')
| -rw-r--r-- | include/tst_timer.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/tst_timer.h b/include/tst_timer.h index b57adf7aa..043b71460 100644 --- a/include/tst_timer.h +++ b/include/tst_timer.h @@ -171,6 +171,23 @@ static inline struct timespec tst_timespec_add(struct timespec t1, } /* + * Subtracts us microseconds from t. + */ +static inline struct timespec tst_timespec_sub_us(struct timespec t, + long long us) +{ + t.tv_sec -= us / 1000000; + t.tv_nsec -= (us % 1000000) * 1000; + + if (t.tv_nsec < 0) { + t.tv_sec--; + t.tv_nsec += 1000000000; + } + + return t; +} + +/* * Returns difference between two timespec structures. */ static inline struct timespec tst_timespec_diff(struct timespec t1, |
