| 45 | #endif |
| 46 | |
| 47 | static uint64 InitTicks() |
| 48 | { |
| 49 | if ( g_TickBase != 0 ) |
| 50 | return g_TickBase; |
| 51 | |
| 52 | #if defined(_WIN32) |
| 53 | LARGE_INTEGER Large; |
| 54 | QueryPerformanceFrequency(&Large); |
| 55 | g_TickFrequency = Large.QuadPart; |
| 56 | g_TickFrequencyDouble = (double)g_TickFrequency; |
| 57 | // Before Windows Vista, multicore system QPC can be non-monotonic |
| 58 | QueryPerformanceCounter( &Large ); |
| 59 | g_TickBase = g_TickLastReturned_XPWorkaround = Large.QuadPart; |
| 60 | #elif IsOSX() |
| 61 | mach_timebase_info_data_t TimebaseInfo; |
| 62 | mach_timebase_info(&TimebaseInfo); |
| 63 | g_TickFrequencyDouble = (double) TimebaseInfo.denom / (double) TimebaseInfo.numer * 1.0e9; |
| 64 | g_TickFrequency = (uint64)( g_TickFrequencyDouble + 0.5 ); |
| 65 | g_TickBase = mach_absolute_time(); |
| 66 | #elif IsNintendoSwitch() |
| 67 | g_TickBase = PlatformTime_GetRawTickCounter(); |
| 68 | g_TickFrequency = PlatformTime_GetRawTickFrequency(); |
| 69 | g_TickFrequencyDouble = g_TickFrequency; |
| 70 | #elif IsPosix() |
| 71 | // TickFrequency is constant since clock_gettime always returns nanoseconds |
| 72 | timespec TimeSpec; |
| 73 | clock_gettime( CLOCK_MONOTONIC, &TimeSpec ); |
| 74 | g_TickBase = (uint64)TimeSpec.tv_sec * 1000000000 + TimeSpec.tv_nsec; |
| 75 | #else |
| 76 | #error Unknown platform |
| 77 | #endif |
| 78 | |
| 79 | #if defined( _WIN32 ) || IsOSX() || IsNintendoSwitch() |
| 80 | g_TicksToUS = 1.0e6 / g_TickFrequencyDouble; |
| 81 | #endif |
| 82 | |
| 83 | return g_TickBase; |
| 84 | } |
| 85 | |
| 86 | uint64 Plat_RelativeTicks() |
| 87 | { |
no outgoing calls
no test coverage detected