ntdll: Fix tick count calculation on Mac.
commit289d456dd617c164047b6562b993a7c1a7955232
authorChip Davis <cdavis@codeweavers.com>
Wed, 27 Nov 2019 15:54:09 +0000 (27 09:54 -0600)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 28 Nov 2019 19:45:46 +0000 (28 20:45 +0100)
treea1d0e98728709be376f34a2fb5d820fb9632abf2
parentc6bafaa6d92b78c82be5b955cae455f581750a00
ntdll: Fix tick count calculation on Mac.

Inspired by a patch by Andrew Eikum.

macOS's mach_absolute_time() stops counting when the computer goes to
sleep/suspend/hibernate/etc. However, Windows's GetTickCount() does not
stop counting. mach_continuous_time() matches Windows's behavior.

BSD's CLOCK_MONOTONIC already counts asleep time.

Unfortunately, there is no clock source on Linux which does exactly what
we want. CLOCK_MONOTONIC_RAW is unaffected by NTP adjustment, but like
mach_absolute_time() doesn't keep ticking when the computer is asleep.
CLOCK_BOOTTIME does keep ticking, but it is affected by NTP adjustments.
CLOCK_MONOTONIC has both problems. What's needed is a
CLOCK_BOOTTIME_RAW, which would not be slewed by adjtimex(2) and would
count time spent asleep.

To avoid issues with skew and performance, this patch falls back to
mach_absolute_time() on macOS if mach_continuous_time() is unavailable.
Note that mach_continuous_time() was introduced in macOS 10.12, meaning
that if the minimum version required is less than that, it will be
linked weakly. Therefore we must check that it is nonnull before
attempting to call it.

Signed-off-by: Chip Davis <cdavis@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
configure
configure.ac
dlls/kernel32/time.c
dlls/ntdll/time.c
include/config.h.in
server/request.c