46
46
Also added OS X Monotonic clock support
47
47
Based on work in https://github.com/ThomasHabets/monotonic_clock
48
48
*/
49
- #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME || HAVE_CLOCK_GETTIME_NSEC_NP
49
+ #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
50
50
#include <time.h>
51
51
#endif
52
52
#ifdef __APPLE__
53
53
#include <mach/mach_time.h>
54
54
#endif
55
55
56
56
/* Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP */
57
- #if HAVE_CLOCK_GETTIME || HAVE_CLOCK_GETTIME_NSEC_NP
57
+ #if HAVE_CLOCK_GETTIME
58
58
#ifdef CLOCK_MONOTONIC_RAW
59
59
#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW
60
60
#else
65
65
/* The first ticks value of the application */
66
66
#if HAVE_CLOCK_GETTIME
67
67
static struct timespec start_ts ;
68
- #elif defined(__APPLE__ ) && ! HAVE_CLOCK_GETTIME_NSEC_NP
68
+ #elif defined(__APPLE__ )
69
69
static uint64_t start_mach ;
70
70
mach_timebase_info_data_t mach_base_info ;
71
71
#endif
@@ -87,17 +87,11 @@ SDL_TicksInit(void)
87
87
has_monotonic_time = SDL_TRUE ;
88
88
} else
89
89
#elif defined(__APPLE__ )
90
- #if !HAVE_CLOCK_GETTIME_NSEC_NP
91
90
kern_return_t ret = mach_timebase_info (& mach_base_info );
92
91
if (ret == 0 ) {
93
92
has_monotonic_time = SDL_TRUE ;
94
93
start_mach = mach_absolute_time ();
95
94
} else
96
- #else
97
- if (clock_gettime_nsec_np (SDL_MONOTONIC_CLOCK ) > 0 ) {
98
- has_monotonic_time = SDL_TRUE ;
99
- } else
100
- #endif
101
95
#endif
102
96
{
103
97
gettimeofday (& start_tv , NULL );
@@ -124,12 +118,8 @@ SDL_GetTicks(void)
124
118
clock_gettime (SDL_MONOTONIC_CLOCK , & now );
125
119
ticks = (Uint32 )((now .tv_sec - start_ts .tv_sec ) * 1000 + (now .tv_nsec - start_ts .tv_nsec ) / 1000000 );
126
120
#elif defined(__APPLE__ )
127
- #if !HAVE_CLOCK_GETTIME_NSEC_NP
128
121
uint64_t now = mach_absolute_time ();
129
122
ticks = (Uint32 )((((now - start_mach ) * mach_base_info .numer ) / mach_base_info .denom ) / 1000000 );
130
- #else
131
- ticks = (Uint32 )clock_gettime_nsec_np (SDL_MONOTONIC_CLOCK );
132
- #endif
133
123
#else
134
124
SDL_assert (SDL_FALSE );
135
125
ticks = 0 ;
@@ -160,11 +150,7 @@ SDL_GetPerformanceCounter(void)
160
150
ticks *= 1000000000 ;
161
151
ticks += now .tv_nsec ;
162
152
#elif defined(__APPLE__ )
163
- #if !HAVE_CLOCK_GETTIME_NSEC_NP
164
153
ticks = mach_absolute_time ();
165
- #else
166
- ticks = (Uint32 )clock_gettime_nsec_np (SDL_MONOTONIC_CLOCK );
167
- #endif
168
154
#else
169
155
SDL_assert (SDL_FALSE );
170
156
ticks = 0 ;
@@ -191,16 +177,13 @@ SDL_GetPerformanceFrequency(void)
191
177
#if HAVE_CLOCK_GETTIME
192
178
return 1000000000 ;
193
179
#elif defined(__APPLE__ )
194
- #if !HAVE_CLOCK_GETTIME_NSEC_NP
195
180
Uint64 freq = mach_base_info .denom ;
196
181
freq *= 1000000000 ;
197
182
freq /= mach_base_info .numer ;
198
183
return freq ;
199
- #else
200
- return 1000000000 ;
201
- #endif
202
184
#endif
203
- }
185
+ }
186
+
204
187
return 1000000 ;
205
188
}
206
189
0 commit comments