It's now possible to disable the fast atomic operations, at a huge performance penalty.
1.1 --- a/configure.in Mon Feb 07 20:06:26 2011 -0800
1.2 +++ b/configure.in Mon Feb 07 22:57:33 2011 -0800
1.3 @@ -422,6 +422,12 @@
1.4 if test x$enable_cpuinfo != xyes; then
1.5 AC_DEFINE(SDL_CPUINFO_DISABLED)
1.6 fi
1.7 +AC_ARG_ENABLE(atomic,
1.8 +AC_HELP_STRING([--enable-atomic], [Enable the atomic operations [[default=yes]]]),
1.9 + , enable_atomic=yes)
1.10 +if test x$enable_atomic != xyes; then
1.11 + AC_DEFINE(SDL_ATOMIC_DISABLED)
1.12 +fi
1.13 AC_ARG_ENABLE(assembly,
1.14 AC_HELP_STRING([--enable-assembly], [Enable assembly routines [[default=yes]]]),
1.15 , enable_assembly=yes)
2.1 --- a/include/SDL_atomic.h Mon Feb 07 20:06:26 2011 -0800
2.2 +++ b/include/SDL_atomic.h Mon Feb 07 22:57:33 2011 -0800
2.3 @@ -141,6 +141,9 @@
2.4 /* Platform specific optimized versions of the atomic functions,
2.5 * you can disable these by defining SDL_DISABLE_ATOMIC_INLINE
2.6 */
2.7 +#if SDL_ATOMIC_DISABLED
2.8 +#define SDL_DISABLE_ATOMIC_INLINE
2.9 +#endif
2.10 #ifndef SDL_DISABLE_ATOMIC_INLINE
2.11
2.12 #ifdef HAVE_MSC_ATOMICS
3.1 --- a/include/SDL_config.h.in Mon Feb 07 20:06:26 2011 -0800
3.2 +++ b/include/SDL_config.h.in Mon Feb 07 22:57:33 2011 -0800
3.3 @@ -171,6 +171,7 @@
3.4 #undef SDL_DEFAULT_ASSERT_LEVEL
3.5
3.6 /* Allow disabling of core subsystems */
3.7 +#undef SDL_ATOMIC_DISABLED
3.8 #undef SDL_AUDIO_DISABLED
3.9 #undef SDL_CPUINFO_DISABLED
3.10 #undef SDL_EVENTS_DISABLED
4.1 --- a/src/atomic/SDL_spinlock.c Mon Feb 07 20:06:26 2011 -0800
4.2 +++ b/src/atomic/SDL_spinlock.c Mon Feb 07 22:57:33 2011 -0800
4.3 @@ -22,6 +22,7 @@
4.4 #include "SDL_stdinc.h"
4.5
4.6 #include "SDL_atomic.h"
4.7 +#include "SDL_mutex.h"
4.8 #include "SDL_timer.h"
4.9
4.10 /* Don't do the check for Visual Studio 2005, it's safe here */
4.11 @@ -33,7 +34,25 @@
4.12 SDL_bool
4.13 SDL_AtomicTryLock(SDL_SpinLock *lock)
4.14 {
4.15 -#if defined(_MSC_VER)
4.16 +#if SDL_ATOMIC_DISABLED
4.17 + /* Terrible terrible damage */
4.18 + static SDL_mutex *_spinlock_mutex;
4.19 +
4.20 + if (!_spinlock_mutex) {
4.21 + /* Race condition on first lock... */
4.22 + _spinlock_mutex = SDL_CreateMutex();
4.23 + }
4.24 + SDL_mutexP(_spinlock_mutex);
4.25 + if (*lock == 0) {
4.26 + *lock = 1;
4.27 + SDL_mutexV(_spinlock_mutex);
4.28 + return SDL_TRUE;
4.29 + } else {
4.30 + SDL_mutexV(_spinlock_mutex);
4.31 + return SDL_FALSE;
4.32 + }
4.33 +
4.34 +#elif defined(_MSC_VER)
4.35 SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
4.36 return (InterlockedExchange((long*)lock, 1) == 0);
4.37