time: add timemono_since
authorEmilio G. Cota <cota@braap.org>
Tue, 27 Sep 2016 21:57:53 +0000 (17:57 -0400)
committerDavid Gibson <david@gibson.dropbear.id.au>
Wed, 28 Sep 2016 00:43:22 +0000 (10:43 +1000)
time_mono()'s documentation references time_since(), which is nowhere
to be found.

A possible fix would be to just remove that stale reference.

Instead, this patch adds timemono_since(), which hopefully
captures the meaning of the original time_since().

Signed-off-by: Emilio G. Cota <cota@braap.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/time/test/run-monotonic.c
ccan/time/time.h

index ed70f3dbb5bddc19e15ed460c250f43fac236456..787ca6820b4c5c1976cdcaae526475eb506fd48f 100644 (file)
@@ -7,7 +7,7 @@ int main(void)
        struct timemono t1, t2;
        struct timerel t3;
 
-       plan_tests(2);
+       plan_tests(3);
 
        /* Test time_mono */
        t1 = time_mono();
@@ -19,6 +19,7 @@ int main(void)
        t3.ts.tv_nsec = 0;
 
        ok1(time_less(timemono_between(t1, t2), t3));
+       ok1(time_less(timemono_since(t1), t3));
 
        return exit_status();
 }
index 5c916f4c4c2ef04b9648791d862bb3eea731a6cd..54d92c57b89090152a9c1a42e10c656ee0c2e82c 100644 (file)
@@ -127,7 +127,7 @@ struct timeabs time_now(void);
  * This value is only really useful for measuring time intervals.
  *
  * See also:
- *     time_since()
+ *     timemono_since()
  */
 struct timemono time_mono(void);
 
@@ -320,6 +320,17 @@ static inline struct timerel timemono_between(struct timemono recent,
        return t;
 }
 
+/**
+ * timemono_since - elapsed monotonic time since @old
+ * @old: a monotonic time from the past.
+ */
+static inline struct timerel timemono_since(struct timemono old)
+{
+       struct timemono now = time_mono();
+
+       return timemono_between(now, old);
+}
+
 /**
  * timeabs_sub - subtract a relative time from an absolute time
  * @abs: the absolute time.