[Swan-dev] now() and other topics
Paul Wouters
paul at nohats.ca
Thu May 1 17:49:49 EEST 2014
On Thu, 1 May 2014, D. Hugh Redelmeier wrote:
> | Don't mix up monotonic time with wall clock time (AKA CLOCK_REALTIME).
> | Some uses need one and some need another.
>
> For this reason, I propose that different types be used for the
> different purposes. Then the C language type system could catch some
> mix-ups.
So how about:
/* monotonic version of time(3) */
time_t now_monotonic(void)
{
struct timespec res;
if (clock_getres(CLOCK_MONOTONIC, &res) == 0) {
/* can this ever happen? */
return time(NULL);
}
return res.tv_sec;
}
time_t now_real(void)
{
struct timespec res;
if (clock_getres(CLOCK_REALTIME, &res) == 0) {
/* can this ever happen? */
return time(NULL);
}
return res.tv_sec;
}
I have no idea when clock_getres() would return an error, so I didn't
want to passert() on it.
Then we use now_monotonic() only for items related the our event
scheduling?
Paul
More information about the Swan-dev
mailing list