@@ -193,6 +193,23 @@ static inline bool time_greater(struct timerel a, struct timerel b)
193193 return time_greater_ (a .ts , b .ts );
194194}
195195
196+ /**
197+ * timemono_after - is a after b?
198+ * @a: one monotonic time.
199+ * @b: another monotonic time.
200+ *
201+ * Example:
202+ * static bool timed_out(const struct timemono *start)
203+ * {
204+ * #define TIMEOUT time_from_msec(1000)
205+ * return timemono_after(time_mono(), timemono_add(*start, TIMEOUT));
206+ * }
207+ */
208+ static inline bool timemono_after (struct timemono a , struct timemono b )
209+ {
210+ return time_greater_ (a .ts , b .ts );
211+ }
212+
196213static inline bool time_less_ (struct timespec a , struct timespec b )
197214{
198215 if (TIME_CHECK (a ).tv_sec < TIME_CHECK (b ).tv_sec )
@@ -220,6 +237,23 @@ static inline bool time_before(struct timeabs a, struct timeabs b)
220237 return time_less_ (a .ts , b .ts );
221238}
222239
240+ /**
241+ * timemono_before - is a before b?
242+ * @a: one monotonic time.
243+ * @b: another monotonic time.
244+ *
245+ * Example:
246+ * static bool still_valid(const struct timemono *start)
247+ * {
248+ * #define TIMEOUT time_from_msec(1000)
249+ * return timemono_before(time_mono(), timemono_add(*start, TIMEOUT));
250+ * }
251+ */
252+ static inline bool timemono_before (struct timemono a , struct timemono b )
253+ {
254+ return time_less_ (a .ts , b .ts );
255+ }
256+
223257/**
224258 * time_less - is a before b?
225259 * @a: one relative time.
@@ -404,6 +438,29 @@ static inline struct timeabs timeabs_sub(struct timeabs abs, struct timerel rel)
404438 return t ;
405439}
406440
441+ /**
442+ * timemono_sub - subtract a relative time from a monotonic time
443+ * @mono: the monotonic time.
444+ * @rel: the relative time.
445+ *
446+ * This returns a well formed struct timemono of @mono - @rel.
447+ *
448+ * Example:
449+ * // We do one every second.
450+ * static struct timemono previous_time(void)
451+ * {
452+ * return timemono_sub(time_mono(), time_from_msec(1000));
453+ * }
454+ */
455+ static inline struct timemono timemono_sub (struct timemono mono , struct timerel rel )
456+ {
457+ struct timemono t ;
458+
459+ t .ts = time_sub_ (mono .ts , rel .ts );
460+ return t ;
461+ }
462+
463+
407464static inline struct timespec time_add_ (struct timespec a , struct timespec b )
408465{
409466 struct timespec sum ;
@@ -488,6 +545,8 @@ static inline struct timerel timerel_add(struct timerel a, struct timerel b)
488545 * @div: number to divide it by.
489546 *
490547 * Example:
548+ * #include <sys/wait.h>
549+ *
491550 * // How long does it take to do a fork?
492551 * static struct timerel forking_time(void)
493552 * {
0 commit comments