Browse Source

mach_absolute_time is monotonic

which is convenient, since it is exactly what we need.
OPENBSD_5_7
Brent Cook 10 years ago
parent
commit
2e79e8cb07
1 changed files with 11 additions and 7 deletions
  1. +11
    -7
      compat/clock_gettime_osx.c

+ 11
- 7
compat/clock_gettime_osx.c View File

@ -24,19 +24,23 @@
int int
clock_gettime(clockid_t clk_id, struct timespec *ts) clock_gettime(clockid_t clk_id, struct timespec *ts)
{ {
static uint64_t timebase_factor = 0;
static uint64_t timebase_scale = 0;
mach_timebase_info_data_t timebase_info; mach_timebase_info_data_t timebase_info;
uint64_t nsec; uint64_t nsec;
if (clk_id != CLOCK_REALTIME)
return -1; /* not implemented */
/*
* Only CLOCK_MONOTONIC is needed by ntpd
*/
if (clk_id != CLOCK_MONOTONIC)
return -1;
if (timebase_factor == 0) {
mach_timebase_info(&timebase_info);
timebase_factor = timebase_info.numer / timebase_info.denom;
if (timebase_scale == 0) {
if (mach_timebase_info(&timebase_info))
return -1;
timebase_scale = timebase_info.numer / timebase_info.denom;
} }
nsec = mach_absolute_time() * timebase_factor;
nsec = mach_absolute_time() * timebase_scale;
ts->tv_sec = nsec / 1000000000UL; ts->tv_sec = nsec / 1000000000UL;
ts->tv_nsec = nsec % 1000000000UL; ts->tv_nsec = nsec % 1000000000UL;


Loading…
Cancel
Save