lkml.org 
[lkml]   [2018]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 19/45] C++: Turn ktime_add/sub_ns() into inline template functions
From
Date
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)
\
 
 \ /
  Last update: 2018-04-01 22:48    [W:2.155 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site