Fixed bug 5467 - SDL sys timer Mac OS update proposal

David Carlier

Change of api from 2016 which reduce code complexity a bit.
This commit is contained in:
Sam Lantinga 2021-01-23 09:50:43 -08:00
parent 0f57864c9e
commit 96cfb81232
6 changed files with 28 additions and 7 deletions

View File

@ -873,6 +873,7 @@ if(LIBC)
else() else()
set(HAVE_ALLOCA_H 1) set(HAVE_ALLOCA_H 1)
set(HAVE_ALLOCA 1) set(HAVE_ALLOCA 1)
check_symbol_exists(clock_gettime_nsec_np HAVE_CLOCK_GETTIME_NSEC_NP)
endif() endif()
check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION) check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)

3
configure vendored
View File

@ -17068,7 +17068,7 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi fi
for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit for ac_func in malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info clock_gettime_nsec_np poll _Exit
do : do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -26008,6 +26008,7 @@ fi
cat >Makefile.rules <<__EOF__ cat >Makefile.rules <<__EOF__

View File

@ -345,7 +345,7 @@ if test x$enable_libc = xyes; then
AC_DEFINE(HAVE_MPROTECT, 1, [ ]) AC_DEFINE(HAVE_MPROTECT, 1, [ ])
]), ]),
) )
AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info poll _Exit) AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp strlen strlcpy strlcat _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp vsscanf vsnprintf fopen64 fseeko fseeko64 sigaction setjmp nanosleep sysconf sysctlbyname getauxval elf_aux_info clock_gettime_nsec_np poll _Exit)
AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt sqrtf tan tanf) AC_CHECK_FUNCS(acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf trunc truncf fmod fmodf log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt sqrtf tan tanf)

View File

@ -191,6 +191,7 @@
#cmakedefine HAVE_SYSCONF 1 #cmakedefine HAVE_SYSCONF 1
#cmakedefine HAVE_SYSCTLBYNAME 1 #cmakedefine HAVE_SYSCTLBYNAME 1
#cmakedefine HAVE_CLOCK_GETTIME 1 #cmakedefine HAVE_CLOCK_GETTIME 1
#cmakedefine HAVE_CLOCK_GETTIME_NSEC_NP 1
#cmakedefine HAVE_GETPAGESIZE 1 #cmakedefine HAVE_GETPAGESIZE 1
#cmakedefine HAVE_MPROTECT 1 #cmakedefine HAVE_MPROTECT 1
#cmakedefine HAVE_ICONV 1 #cmakedefine HAVE_ICONV 1

View File

@ -196,6 +196,7 @@
#undef HAVE_SYSCONF #undef HAVE_SYSCONF
#undef HAVE_SYSCTLBYNAME #undef HAVE_SYSCTLBYNAME
#undef HAVE_CLOCK_GETTIME #undef HAVE_CLOCK_GETTIME
#undef HAVE_CLOCK_GETTIME_NSEC_NP
#undef HAVE_GETPAGESIZE #undef HAVE_GETPAGESIZE
#undef HAVE_MPROTECT #undef HAVE_MPROTECT
#undef HAVE_ICONV #undef HAVE_ICONV

View File

@ -46,7 +46,7 @@
Also added OS X Monotonic clock support Also added OS X Monotonic clock support
Based on work in https://github.com/ThomasHabets/monotonic_clock Based on work in https://github.com/ThomasHabets/monotonic_clock
*/ */
#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME #if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME || HAVE_CLOCK_GETTIME_NSEC_NP
#include <time.h> #include <time.h>
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
@ -54,7 +54,7 @@
#endif #endif
/* Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP */ /* Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP */
#if HAVE_CLOCK_GETTIME #if HAVE_CLOCK_GETTIME || HAVE_CLOCK_GETTIME_NSEC_NP
#ifdef CLOCK_MONOTONIC_RAW #ifdef CLOCK_MONOTONIC_RAW
#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW #define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW
#else #else
@ -65,7 +65,7 @@
/* The first ticks value of the application */ /* The first ticks value of the application */
#if HAVE_CLOCK_GETTIME #if HAVE_CLOCK_GETTIME
static struct timespec start_ts; static struct timespec start_ts;
#elif defined(__APPLE__) #elif defined(__APPLE__) && !HAVE_CLOCK_GETTIME_NSEC_NP
static uint64_t start_mach; static uint64_t start_mach;
mach_timebase_info_data_t mach_base_info; mach_timebase_info_data_t mach_base_info;
#endif #endif
@ -87,11 +87,17 @@ SDL_TicksInit(void)
has_monotonic_time = SDL_TRUE; has_monotonic_time = SDL_TRUE;
} else } else
#elif defined(__APPLE__) #elif defined(__APPLE__)
#if !HAVE_CLOCK_GETTIME_NSEC_NP
kern_return_t ret = mach_timebase_info(&mach_base_info); kern_return_t ret = mach_timebase_info(&mach_base_info);
if (ret == 0) { if (ret == 0) {
has_monotonic_time = SDL_TRUE; has_monotonic_time = SDL_TRUE;
start_mach = mach_absolute_time(); start_mach = mach_absolute_time();
} else } else
#else
if (clock_gettime_nsec_np(SDL_MONOTONIC_CLOCK) > 0) {
has_monotonic_time = SDL_TRUE;
} else
#endif
#endif #endif
{ {
gettimeofday(&start_tv, NULL); gettimeofday(&start_tv, NULL);
@ -118,8 +124,12 @@ SDL_GetTicks(void)
clock_gettime(SDL_MONOTONIC_CLOCK, &now); clock_gettime(SDL_MONOTONIC_CLOCK, &now);
ticks = (Uint32)((now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec - start_ts.tv_nsec) / 1000000); ticks = (Uint32)((now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec - start_ts.tv_nsec) / 1000000);
#elif defined(__APPLE__) #elif defined(__APPLE__)
#if !HAVE_CLOCK_GETTIME_NSEC_NP
uint64_t now = mach_absolute_time(); uint64_t now = mach_absolute_time();
ticks = (Uint32)((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000); ticks = (Uint32)((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000);
#else
ticks = (Uint32)clock_gettime_nsec_np(SDL_MONOTONIC_CLOCK);
#endif
#else #else
SDL_assert(SDL_FALSE); SDL_assert(SDL_FALSE);
ticks = 0; ticks = 0;
@ -150,7 +160,11 @@ SDL_GetPerformanceCounter(void)
ticks *= 1000000000; ticks *= 1000000000;
ticks += now.tv_nsec; ticks += now.tv_nsec;
#elif defined(__APPLE__) #elif defined(__APPLE__)
#if !HAVE_CLOCK_GETTIME_NSEC_NP
ticks = mach_absolute_time(); ticks = mach_absolute_time();
#else
ticks = (Uint32)clock_gettime_nsec_np(SDL_MONOTONIC_CLOCK);
#endif
#else #else
SDL_assert(SDL_FALSE); SDL_assert(SDL_FALSE);
ticks = 0; ticks = 0;
@ -177,13 +191,16 @@ SDL_GetPerformanceFrequency(void)
#if HAVE_CLOCK_GETTIME #if HAVE_CLOCK_GETTIME
return 1000000000; return 1000000000;
#elif defined(__APPLE__) #elif defined(__APPLE__)
#if !HAVE_CLOCK_GETTIME_NSEC_NP
Uint64 freq = mach_base_info.denom; Uint64 freq = mach_base_info.denom;
freq *= 1000000000; freq *= 1000000000;
freq /= mach_base_info.numer; freq /= mach_base_info.numer;
return freq; return freq;
#else
return 1000000000;
#endif #endif
} #endif
}
return 1000000; return 1000000;
} }