21 #include "../../SDL_internal.h" 44 #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME 48 #include <mach/mach_time.h> 52 #if HAVE_CLOCK_GETTIME 53 #ifdef CLOCK_MONOTONIC_RAW 54 #define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW 56 #define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC 61 #if HAVE_CLOCK_GETTIME 62 static struct timespec start_ts;
63 #elif defined(__APPLE__) 65 mach_timebase_info_data_t mach_base_info;
68 static struct timeval start_tv;
80 #if HAVE_CLOCK_GETTIME 81 if (clock_gettime(SDL_MONOTONIC_CLOCK, &start_ts) == 0) {
84 #elif defined(__APPLE__) 85 kern_return_t ret = mach_timebase_info(&mach_base_info);
88 start_mach = mach_absolute_time();
92 gettimeofday(&start_tv,
NULL);
106 if (!ticks_started) {
110 if (has_monotonic_time) {
111 #if HAVE_CLOCK_GETTIME 113 clock_gettime(SDL_MONOTONIC_CLOCK, &now);
114 ticks = (now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec -
115 start_ts.tv_nsec) / 1000000;
116 #elif defined(__APPLE__) 117 uint64_t now = mach_absolute_time();
118 ticks = (
Uint32)((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000);
126 gettimeofday(&now,
NULL);
127 ticks = (
Uint32)((now.tv_sec - start_tv.tv_sec) * 1000 + (now.tv_usec - start_tv.tv_usec) / 1000);
136 if (!ticks_started) {
140 if (has_monotonic_time) {
141 #if HAVE_CLOCK_GETTIME 144 clock_gettime(SDL_MONOTONIC_CLOCK, &now);
147 ticks += now.tv_nsec;
148 #elif defined(__APPLE__) 149 ticks = mach_absolute_time();
157 gettimeofday(&now,
NULL);
160 ticks += now.tv_usec;
168 if (!ticks_started) {
172 if (has_monotonic_time) {
173 #if HAVE_CLOCK_GETTIME 175 #elif defined(__APPLE__) 176 Uint64 freq = mach_base_info.denom;
178 freq /= mach_base_info.numer;
192 struct timespec elapsed, tv;
195 Uint32 then, now, elapsed;
200 elapsed.tv_sec = ms / 1000;
201 elapsed.tv_nsec = (ms % 1000) * 1000000;
209 tv.tv_sec = elapsed.tv_sec;
210 tv.tv_nsec = elapsed.tv_nsec;
211 was_error = nanosleep(&tv, &elapsed);
215 elapsed = (now - then);
221 tv.tv_sec = ms / 1000;
222 tv.tv_usec = (ms % 1000) * 1000;
226 }
while (was_error && (errno == EINTR));
uint32_t Uint32
An unsigned 32-bit integer type.
unsigned long long uint64_t
Uint64 SDL_GetPerformanceFrequency(void)
Get the count per second of the high resolution counter.
uint64_t Uint64
An unsigned 64-bit integer type.
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
#define SDL_GetPerformanceCounter
#define SDL_assert(condition)