| Subject | [PATCH 19/45] C++: Turn ktime_add/sub_ns() into inline template functions | From | David Howells <> | Date | Sun, 01 Apr 2018 21:42:09 +0100 |
| |
Turn ktime ns arithmetic functions into template functions to handle the nanosecond value type conversion correctly.
Signed-off-by: David Howells <dhowells@redhat.com> ---
include/linux/ktime.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/include/linux/ktime.h b/include/linux/ktime.h index 5b9fddbaac41..d46a16f23ffc 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h @@ -58,13 +58,21 @@ static inline ktime_t ktime_set(const s64 secs, const unsigned long nsecs) * Add a ktime_t variable and a scalar nanosecond value. * res = kt + nsval: */ -#define ktime_add_ns(kt, nsval) ((kt) + (nsval)) +template <typename NSVAL> +static inline ktime_t ktime_add_ns(ktime_t kt, NSVAL nsval) +{ + return kt + nsval; +} /* * Subtract a scalar nanosecod from a ktime_t variable * res = kt - nsval: */ -#define ktime_sub_ns(kt, nsval) ((kt) - (nsval)) +template <typename NSVAL> +static inline ktime_t ktime_sub_ns(ktime_t kt, NSVAL nsval) +{ + return kt - nsval; +} /* convert a timespec to ktime_t format: */ static inline ktime_t timespec_to_ktime(struct timespec ts)
|