瀏覽代碼

evtimer_gettime was broken on MacOs.

master
Richard Nyberg 16 年之前
父節點
當前提交
9f4d2b0662
共有 1 個檔案被更改,包括 7 行新增4 行删除
  1. +7
    -4
      evloop/timer.c

+ 7
- 4
evloop/timer.c 查看文件

@@ -25,12 +25,15 @@ int
evtimer_gettime(struct timespec *ts) evtimer_gettime(struct timespec *ts)
{ {
uint64_t nsecs; uint64_t nsecs;
static double nsmul;
static mach_timebase_info_data_t nsratio = { 0, 0 }; static mach_timebase_info_data_t nsratio = { 0, 0 };
if (nsratio.denom == 0) if (nsratio.denom == 0) {
mach_timebase_info(&nsratio); mach_timebase_info(&nsratio);
nsecs = mach_absolute_time() * nsratio.numer / nsratio.denom; nsmul = (double)nsratio.numer / nsratio.denom;
ts->tv_sec = nsecs / 1000000000; }
ts->tv_nsec = nsecs - ts->tv_sec * 1000000000; nsecs = mach_absolute_time() * nsmul;
ts->tv_sec = nsecs / 1000000000ULL;
ts->tv_nsec = nsecs - ts->tv_sec * 1000000000ULL;
return 0; return 0;
} }




||||||
x
 
000:0
Loading…
取消
儲存