diff options
author | John Stultz <johnstul@us.ibm.com> | 2010-07-13 20:56:19 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2010-07-27 06:40:53 -0400 |
commit | ce3bf7ab22527183634a76512d9854a38615e4d5 (patch) | |
tree | 79e48c7c84618d968664bd660c75e03fc98e7d11 /include/linux/time.h | |
parent | 8c73626ab28527b7eb7f3061c027fbfe530c488c (diff) |
time: Implement timespec_add
After accidentally misusing timespec_add_safe, I wanted to make sure
we don't accidently trip over that issue again, so I created a simple
timespec_add() function which we can use to replace the instances
of timespec_add_safe() that don't want the overflow detection.
Signed-off-by: John Stultz <johnstul@us.ibm.com>
LKML-Reference: <1279068988-21864-3-git-send-email-johnstul@us.ibm.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/linux/time.h')
-rw-r--r-- | include/linux/time.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/linux/time.h b/include/linux/time.h index ea3559f0b3f2..9072df83de1f 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
@@ -76,9 +76,25 @@ extern unsigned long mktime(const unsigned int year, const unsigned int mon, | |||
76 | const unsigned int min, const unsigned int sec); | 76 | const unsigned int min, const unsigned int sec); |
77 | 77 | ||
78 | extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); | 78 | extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); |
79 | |||
80 | /* | ||
81 | * timespec_add_safe assumes both values are positive and checks | ||
82 | * for overflow. It will return TIME_T_MAX if the reutrn would be | ||
83 | * smaller then either of the arguments. | ||
84 | */ | ||
79 | extern struct timespec timespec_add_safe(const struct timespec lhs, | 85 | extern struct timespec timespec_add_safe(const struct timespec lhs, |
80 | const struct timespec rhs); | 86 | const struct timespec rhs); |
81 | 87 | ||
88 | |||
89 | static inline struct timespec timespec_add(struct timespec lhs, | ||
90 | struct timespec rhs) | ||
91 | { | ||
92 | struct timespec ts_delta; | ||
93 | set_normalized_timespec(&ts_delta, lhs.tv_sec + rhs.tv_sec, | ||
94 | lhs.tv_nsec + rhs.tv_nsec); | ||
95 | return ts_delta; | ||
96 | } | ||
97 | |||
82 | /* | 98 | /* |
83 | * sub = lhs - rhs, in normalized form | 99 | * sub = lhs - rhs, in normalized form |
84 | */ | 100 | */ |