43 #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
47 #include <mach/mach_time.h>
51 #if HAVE_CLOCK_GETTIME
52 static struct timespec start_ts;
53 #elif defined(__APPLE__)
55 mach_timebase_info_data_t mach_base_info;
58 static struct timeval start_tv;
70 #if HAVE_CLOCK_GETTIME
71 if (clock_gettime(CLOCK_MONOTONIC, &start_ts) == 0) {
74 #elif defined(__APPLE__)
75 kern_return_t
ret = mach_timebase_info(&mach_base_info);
78 start_mach = mach_absolute_time();
82 gettimeofday(&start_tv,
NULL);
94 if (has_monotonic_time) {
95 #if HAVE_CLOCK_GETTIME
97 clock_gettime(CLOCK_MONOTONIC, &now);
98 ticks = (now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec -
99 start_ts.tv_nsec) / 1000000;
100 #elif defined(__APPLE__)
101 uint64_t now = mach_absolute_time();
102 ticks = (((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000;
107 gettimeofday(&now,
NULL);
109 (now.tv_sec - start_tv.tv_sec) * 1000 + (now.tv_usec -
110 start_tv.tv_usec) / 1000;
123 if (has_monotonic_time) {
124 #if HAVE_CLOCK_GETTIME
127 clock_gettime(CLOCK_MONOTONIC, &now);
130 ticks += now.tv_nsec;
131 #elif defined(__APPLE__)
132 ticks = mach_absolute_time();
137 gettimeofday(&now,
NULL);
140 ticks += now.tv_usec;
152 if (has_monotonic_time) {
153 #if HAVE_CLOCK_GETTIME
155 #elif defined(__APPLE__)
156 Uint64 freq = mach_base_info.denom;
158 freq /= mach_base_info.numer;
172 struct timespec elapsed, tv;
175 Uint32 then, now, elapsed;
180 elapsed.tv_sec = ms / 1000;
181 elapsed.tv_nsec = (ms % 1000) * 1000000;
189 tv.tv_sec = elapsed.tv_sec;
190 tv.tv_nsec = elapsed.tv_nsec;
191 was_error = nanosleep(&tv, &elapsed);
195 elapsed = (now - then);
201 tv.tv_sec = ms / 1000;
202 tv.tv_usec = (ms % 1000) * 1000;
206 }
while (was_error && (errno == EINTR));
static SDL_bool ticks_started
unsigned long long uint64_t
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
uint64_t Uint64
An unsigned 64-bit integer type.
DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void)
Get the current value of the high resolution counter.
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void)
Get the count per second of the high resolution counter.