[PATCH v2] time: Add TIME_MONOTONIC, TIME_ACTIVE, and TIME_THREAD_ACTIVE
Paul Eggert
eggert@cs.ucla.edu
Tue Nov 25 08:27:23 GMT 2025
On 2025-11-24 10:29, Adhemerval Zanella wrote:
> +* The ISO C23 optimal time base TIME_MONOTONIC, TIME_ACTIVE, and
> + TIME_THREAD_ACTIVE have been added.
I assume you meant "optional" not "optimal"?
Also, shouldn't this new feature be documented in the manual?
> + clockid_t clockid = clock_from_timebase (base);
> + if (clockid < 0)
> + return 0;
> + return __clock_gettime64 (clockid, ts) == 0 ? base : 0;
Wouldn't it be a bit faster, and even a bit future-proofier, to do this?
return __clock_gettime64 (clockid - 1, ts) == 0 ? base : 0;
Speed can matter in clock routines....
> int
> __timespec_getres (struct timespec *ts, int base)
> {
> - int ret;
> struct __timespec64 tp64;
>
> - ret = __timespec_getres64 (&tp64, base);
> + if (__timespec_getres64 (&tp64, base) != 0 && ts != NULL)
> + {
> + *ts = valid_timespec64_to_timespec (tp64);
> + return base;
> + }
>
> - if (ret == TIME_UTC && ts != NULL)
> - *ts = valid_timespec64_to_timespec (tp64);
> -
> - return ret;
> + return 0;
Why change from the old way of doing "return ret;"? In other words, why
not do something like this?
struct __timespec64 tp64;
int ret = __timespec_getres64 (&tp64, base);
if (ret != 0 && ts != NULL)
*ts = valid_timespec64_to_timespec (tp64);
return ret;
This way, the compiler doesn't need to save and restore BASE so the code
can be a tiny bit smaller and faster.
More information about the Libc-alpha
mailing list