-
Notifications
You must be signed in to change notification settings - Fork 469
Base approximate time on a monotonic clock, like absolute time #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/shims/time.h
Outdated
@@ -152,9 +152,9 @@ _dispatch_approximate_time(void) | |||
struct timespec ts; | |||
dispatch_assume_zero(clock_gettime(CLOCK_UPTIME_FAST, &ts)); | |||
return _dispatch_timespec_to_nano(ts); | |||
#elif defined(__linux__) | |||
#elif HAVE_DECL_CLOCK_MONOTONIC_COARSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the if defined(__linux__)
because CLOCK_MONOTONIC is supposed to tick during machine sleeps if you look at POSIX, and it happens to not be the case on linux which eventually became ABI on this platform.
However if a platform has (1) MONOTONIC_COARSE and not UPTIME_FAST, and (2) is POSIX compliant, then this would cause a bug for the said platform.
However you're right that MONOTONIC_COARSE is what we want here.
c418375
to
700d08a
Compare
Amended; do we want to do the same in _dispatch_absolute_time() with a comment on top? |
we probably should now that you point this out. |
And document the reason behind this to avoid future bugs.
700d08a
to
58b23b8
Compare
How does that look? Ship it? |
Base approximate time on a monotonic clock, like absolute time Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
Caught this today; _dispatch_approximate_time() uses CLOCK_REALTIME on Linux for some reason, while _dispatch_absolute_time() uses CLOCK_MONOTONIC. This seems wrong and I can't think of a reason why this would be desirable in the first place.
Darwin code uses the same clock family for both, so use CLOCK_MONOTONIC_COARSE on Linux as the approximate time source, and test for it during configure.