diff options
author | dana <dana@dana.is> | 2024-12-26 09:36:45 -0600 |
---|---|---|
committer | dana <dana@dana.is> | 2024-12-26 10:09:25 -0600 |
commit | 6bb792dba89016c250bc9f2581c9c267dd322254 (patch) | |
tree | 436bc0514ff4a7d63c12af2aadc060f8ed645788 /Src/compat.c | |
parent | 7798fd88ac42f55980fb9832f2f7e379392fe6aa (diff) | |
download | zsh-6bb792dba89016c250bc9f2581c9c267dd322254.tar.gz zsh-6bb792dba89016c250bc9f2581c9c267dd322254.zip |
53257: use monotonic clock where appropriate
update the following features to use the monotonic clock for calculating time
deltas and intervals:
* MAILCHECK parameter
* PERIOD parameter
* SECONDS parameter
* %(nS.t.f) prompt-expansion sequence
* time built-in's elapsed time and cpu % values
* zsh/zftp ZFTP_TMOUT parameter
* zsh/zprof timings
also use CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC on macOS
Diffstat (limited to 'Src/compat.c')
-rw-r--r-- | Src/compat.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Src/compat.c b/Src/compat.c index 8b31ad9f4..918d98e69 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -136,7 +136,19 @@ zgettime_monotonic_if_available(struct timespec *ts) #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) struct timespec dts; + +/* + * On at least some versions of macOS it appears that CLOCK_MONOTONIC is not + * actually monotonic -- there are reports that it can go backwards. + * CLOCK_MONOTONIC_RAW does not have this problem. On top of that, it is faster + * to read and it has nanosecond precision. We could use it on other systems + * too, but on Linux at least it seems that CLOCK_MONOTONIC is preferred + */ +#if defined(__APPLE__) && defined(CLOCK_MONOTONIC_RAW) + if (clock_gettime(CLOCK_MONOTONIC_RAW, &dts) < 0) { +#else if (clock_gettime(CLOCK_MONOTONIC, &dts) < 0) { +#endif zwarn("unable to retrieve CLOCK_MONOTONIC time: %e", errno); ret--; } else { |