* [PATCH] time: add timemono_since
@ 2016-09-27 21:57 Emilio G. Cota
2016-09-28 1:26 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Emilio G. Cota @ 2016-09-27 21:57 UTC (permalink / raw)
To: ccan
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>
---
ccan/time/test/run-monotonic.c | 3 ++-
ccan/time/time.h | 13 ++++++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/ccan/time/test/run-monotonic.c b/ccan/time/test/run-monotonic.c
index ed70f3d..787ca68 100644
--- a/ccan/time/test/run-monotonic.c
+++ b/ccan/time/test/run-monotonic.c
@@ -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();
}
diff --git a/ccan/time/time.h b/ccan/time/time.h
index 5c916f4..54d92c5 100644
--- a/ccan/time/time.h
+++ b/ccan/time/time.h
@@ -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);
@@ -321,6 +321,17 @@ static inline struct timerel timemono_between(struct timemono recent,
}
/**
+ * 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.
* @rel: the relative time.
--
2.5.0
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] time: add timemono_since
2016-09-27 21:57 [PATCH] time: add timemono_since Emilio G. Cota
@ 2016-09-28 1:26 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2016-09-28 1:26 UTC (permalink / raw)
To: Emilio G. Cota; +Cc: ccan
[-- Attachment #1.1: Type: text/plain, Size: 2321 bytes --]
On Tue, Sep 27, 2016 at 05:57:53PM -0400, Emilio G. Cota wrote:
> 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().
Indeed it does. Thanks for filling in that gap.
> Signed-off-by: Emilio G. Cota <cota@braap.org>
Applied to master.
> ---
> ccan/time/test/run-monotonic.c | 3 ++-
> ccan/time/time.h | 13 ++++++++++++-
> 2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/ccan/time/test/run-monotonic.c b/ccan/time/test/run-monotonic.c
> index ed70f3d..787ca68 100644
> --- a/ccan/time/test/run-monotonic.c
> +++ b/ccan/time/test/run-monotonic.c
> @@ -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();
> }
> diff --git a/ccan/time/time.h b/ccan/time/time.h
> index 5c916f4..54d92c5 100644
> --- a/ccan/time/time.h
> +++ b/ccan/time/time.h
> @@ -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);
>
> @@ -321,6 +321,17 @@ static inline struct timerel timemono_between(struct timemono recent,
> }
>
> /**
> + * 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.
> * @rel: the relative time.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
[-- Attachment #2: Type: text/plain, Size: 127 bytes --]
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-28 2:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-27 21:57 [PATCH] time: add timemono_since Emilio G. Cota
2016-09-28 1:26 ` David Gibson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.