Skip to content

Commit

Permalink
use CLOCK_BOOTTIME and mach_continuous_time
Browse files Browse the repository at this point in the history
  • Loading branch information
bikallem committed Aug 1, 2022
1 parent 55c9350 commit 4b6336a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src-clock/mtime_clock_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#elif defined(__unix__) || defined(__unix)
#include <unistd.h>
#if defined(__linux__)
#define OCAML_MTIME_LINUX
#endif
#if defined(_POSIX_VERSION)
#define OCAML_MTIME_POSIX
#endif
Expand Down Expand Up @@ -51,14 +54,14 @@ CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit)
static uint64_t start = 0L;
if (start == 0L) { start = mach_absolute_time (); }
if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); }
uint64_t now = mach_absolute_time ();
uint64_t now = mach_continuous_time ();
return caml_copy_int64 (((now - start) * scale.numer) / scale.denom);
}

CAMLprim value ocaml_mtime_clock_now_ns (value unit)
{
if (scale.denom == 0) { ocaml_mtime_clock_init_scale (); }
uint64_t now = mach_absolute_time ();
uint64_t now = mach_continuous_time ();
return caml_copy_int64 ((now * scale.numer) / scale.denom);
}

Expand All @@ -75,6 +78,13 @@ CAMLprim value ocaml_mtime_clock_elapsed_ns (value unit)
{
static struct timespec start = {0};
struct timespec now;
clockid_t clockid;

#if defined(OCAML_MTIME_LINUX)
clockid = CLOCK_BOOTTIME;
#else
clockid = CLOCK_MONOTONIC;
#endif

if (start.tv_sec == 0)
{
Expand Down

0 comments on commit 4b6336a

Please sign in to comment.