@@ -193,6 +193,23 @@ static inline bool time_greater(struct timerel a, struct timerel b)
193
193
return time_greater_ (a .ts , b .ts );
194
194
}
195
195
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
+
196
213
static inline bool time_less_ (struct timespec a , struct timespec b )
197
214
{
198
215
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)
220
237
return time_less_ (a .ts , b .ts );
221
238
}
222
239
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
+
223
257
/**
224
258
* time_less - is a before b?
225
259
* @a: one relative time.
@@ -404,6 +438,29 @@ static inline struct timeabs timeabs_sub(struct timeabs abs, struct timerel rel)
404
438
return t ;
405
439
}
406
440
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
+
407
464
static inline struct timespec time_add_ (struct timespec a , struct timespec b )
408
465
{
409
466
struct timespec sum ;
@@ -488,6 +545,8 @@ static inline struct timerel timerel_add(struct timerel a, struct timerel b)
488
545
* @div: number to divide it by.
489
546
*
490
547
* Example:
548
+ * #include <sys/wait.h>
549
+ *
491
550
* // How long does it take to do a fork?
492
551
* static struct timerel forking_time(void)
493
552
* {
0 commit comments