--- CHANGES.md.orig 2024-09-10 00:00:00.000000000 +0000 +++ CHANGES.md 2026-03-03 10:00:05.000000000 +0100 @@ -1,3 +1,10 @@ + + +- `Mtime_clock`. Restore compatiblity with MacOS < 10.12. Before 10.12 + we use `mach_absolute_time` instead of `mach_continuous_time` which + means that sleep time is not taken into account. Thanks to + Sergey Fedorov for the report and help (#51). + v2.1.0 2024-09-10 Zagreb ------------------------ --- src/clock/mtime_clock.mli.orig 2024-09-10 00:00:00.000000000 +0000 +++ src/clock/mtime_clock.mli 2026-03-03 10:00:05.000000000 +0100 @@ -89,9 +89,10 @@ {- Platforms with a POSIX clock use {{:http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html}[clock_gettime]} with CLOCK_MONOTONIC.} - {- Darwin uses - {{:https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time}[mach_continous_time]}. - This means that sleep time is taken into account.} + {- MacOS >= 10.12 uses + {{:https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time}[mach_continous_time]}, sleep time is taken into + account. For MacOS < 10.12, {{:https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time}[mach_absolute_time]} is used, sleep time + is not taken into account.} {- Windows uses {{:https://msdn.microsoft.com/en-us/library/windows/desktop/aa373083%28v=vs.85%29.aspx}Performance counters}. } {- JavaScript uses --- src/clock/mtime_clock_stubs.c.orig 2024-09-10 00:00:00.000000000 +0000 +++ src/clock/mtime_clock_stubs.c 2026-03-03 10:00:05.000000000 +0100 @@ -19,7 +19,6 @@ #if defined(__APPLE__) && defined(__MACH__) #define OCAML_MTIME_DARWIN - #elif defined(__unix__) || defined(__unix) #include #if defined(__linux__) @@ -38,6 +37,14 @@ #include +#include + +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 + #define ocaml_darwin_mach_time mach_continuous_time +#else + #define ocaml_darwin_mach_time mach_absolute_time +#endif + static mach_timebase_info_data_t scale = {0}; void ocaml_mtime_clock_init_scale (void) @@ -52,9 +58,9 @@ CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit) { static uint64_t start = 0L; - if (start == 0L) { start = mach_continuous_time (); } + if (start == 0L) { start = ocaml_darwin_mach_time (); } if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); } - uint64_t now = mach_continuous_time (); + uint64_t now = ocaml_darwin_mach_time (); return caml_copy_int64 (((now - start) * scale.numer) / scale.denom); } @@ -62,7 +68,7 @@ CAMLprim value ocaml_mtime_clock_now_ns (value unit) { if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); } - uint64_t now = mach_continuous_time (); + uint64_t now = ocaml_darwin_mach_time (); return caml_copy_int64 ((now * scale.numer) / scale.denom); }