Module: Monotonic

Defined in:
lib/monotonic.rb,
lib/monotonic/version.rb,
ext/monotonic/monotonic.c

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.nowObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/monotonic/monotonic.c', line 13

VALUE gettime_monotonic(VALUE self) {
  struct timespec ts;

#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
  clock_serv_t cclock;
  mach_timespec_t mts;
  host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
  clock_get_time(cclock, &mts);
  mach_port_deallocate(mach_task_self(), cclock);
  ts.tv_sec = mts.tv_sec;
  ts.tv_nsec = mts.tv_nsec;
#else
  clock_gettime(CLOCK_REALTIME, &ts);
#endif
  return rb_float_new((double)ts.tv_sec + (double)ts.tv_nsec * 1e-9);
}