| 85 | static u64 mt_timestart = 0; |
| 86 | |
| 87 | static int clock_gettime(int clk_id, struct timespec *tp) { |
| 88 | kern_return_t retval = KERN_SUCCESS; |
| 89 | if (clk_id == TIMER_ABSTIME) { |
| 90 | if (!mt_timestart) { |
| 91 | // only one timer, initilized on the first call to the TIMER |
| 92 | mach_timebase_info_data_t tb = {0}; |
| 93 | mach_timebase_info(&tb); |
| 94 | mt_timebase = tb.numer; |
| 95 | mt_timebase /= tb.denom; |
| 96 | mt_timestart = mach_absolute_time(); |
| 97 | } |
| 98 | |
| 99 | double diff = (mach_absolute_time() - mt_timestart) * mt_timebase; |
| 100 | tp->tv_sec = diff * MT_NANO; |
| 101 | tp->tv_nsec = diff - (tp->tv_sec * MT_GIGA); |
| 102 | } else // other clk_ids are mapped to the coresponding mach clock_service |
| 103 | { |
| 104 | clock_serv_t cclock; |
| 105 | mach_timespec_t mts; |
| 106 | |
| 107 | host_get_clock_service(mach_host_self(), clk_id, &cclock); |
| 108 | retval = clock_get_time(cclock, &mts); |
| 109 | mach_port_deallocate(mach_task_self(), cclock); |
| 110 | |
| 111 | tp->tv_sec = mts.tv_sec; |
| 112 | tp->tv_nsec = mts.tv_nsec; |
| 113 | } |
| 114 | |
| 115 | return retval; |
| 116 | } |
| 117 | #endif |
| 118 | |
| 119 | #endif |
no outgoing calls
no test coverage detected