From d7e6145acd3d2dba597f69c2679538fe8751cdf0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 21 Jan 2011 21:42:04 -0800 Subject: [PATCH] Separated out the minimum functionality that we need from gcc for our spinlock fallback. --- configure.in | 12 ++++++++++++ include/SDL_config.h.in | 1 + src/atomic/SDL_spinlock.c | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index c4ae06170..3f1c81f53 100644 --- a/configure.in +++ b/configure.in @@ -312,6 +312,18 @@ if test x$enable_gcc_atomics = xyes; then if test x$have_gcc_atomics = xyes; then AC_DEFINE(HAVE_GCC_ATOMICS) fi + + # See if we have the minimum operation needed for GCC atomics + AC_TRY_LINK([ + ],[ + int a; + __sync_lock_test_and_set(&a, 1); + ],[ + have_gcc_sync_lock_test_and_set=yes + ]) + if test x$have_gcc_sync_lock_test_and_set = xyes; then + AC_DEFINE(HAVE_GCC_SYNC_LOCK_TEST_AND_SET) + fi fi # Standard C sources diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 491fa1a4b..c0500f0ee 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -59,6 +59,7 @@ #undef SIZEOF_VOIDP #undef SDL_HAS_64BIT_TYPE #undef HAVE_GCC_ATOMICS +#undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET /* Comment this if you want to build without any C library requirements */ #undef HAVE_LIBC diff --git a/src/atomic/SDL_spinlock.c b/src/atomic/SDL_spinlock.c index eebe5631e..2cbd927d7 100644 --- a/src/atomic/SDL_spinlock.c +++ b/src/atomic/SDL_spinlock.c @@ -36,7 +36,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock) #elif defined(__MACOSX__) return OSAtomicCompareAndSwap32Barrier(0, 1, lock); -#elif defined(HAVE_GCC_ATOMICS) +#elif defined(HAVE_GCC_SYNC_LOCK_TEST_AND_SET) return (__sync_lock_test_and_set(lock, 1) == 0); #elif defined(__GNUC__) && defined(__arm__) && defined(__ARM_ARCH_5__)