| 42 | |
| 43 | namespace { |
| 44 | TimeSpec orwl_gettime() { |
| 45 | static double orwl_timebase = 0.0; |
| 46 | static uint64_t orwl_timestart = 0; |
| 47 | |
| 48 | // be more careful in a multithreaded environement |
| 49 | if (!orwl_timestart) { |
| 50 | #pragma clang diagnostic push |
| 51 | #pragma clang diagnostic ignored "-Wmissing-field-initializers" |
| 52 | mach_timebase_info_data_t tb = {0}; |
| 53 | #pragma clang diagnostic pop |
| 54 | mach_timebase_info(&tb); |
| 55 | orwl_timebase = tb.numer; |
| 56 | orwl_timebase /= tb.denom; |
| 57 | orwl_timestart = mach_absolute_time(); |
| 58 | } |
| 59 | TimeSpec t; |
| 60 | double diff = (mach_absolute_time() - orwl_timestart) * orwl_timebase; |
| 61 | t.sec = diff * 1e-9; |
| 62 | t.nsec = diff - (t.sec * 1e9); |
| 63 | return t; |
| 64 | } |
| 65 | |
| 66 | } // anonymous namespace |
| 67 | |