MCPcopy Create free account
hub / github.com/RPCSX/rpcsx / clock_gettime

Function clock_gettime

kernel/cellos/src/sys_time.cpp:87–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85static u64 mt_timestart = 0;
86
87static 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

Callers 9

waitMethod · 0.85
Thread.cppFile · 0.85
sysinfo.cppFile · 0.85
getTscFreqMethod · 0.85
sys_clock_gettimeMethod · 0.85
sys_time.cppFile · 0.85
get_timebased_timeFunction · 0.85
get_system_timeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected