src/atomic/SDL_spinlock.c
changeset 5225 5d01d426f2ea
parent 5097 b938ad843e52
child 5262 b530ef003506
     1.1 --- a/src/atomic/SDL_spinlock.c	Mon Feb 07 20:06:26 2011 -0800
     1.2 +++ b/src/atomic/SDL_spinlock.c	Mon Feb 07 22:57:33 2011 -0800
     1.3 @@ -22,6 +22,7 @@
     1.4  #include "SDL_stdinc.h"
     1.5  
     1.6  #include "SDL_atomic.h"
     1.7 +#include "SDL_mutex.h"
     1.8  #include "SDL_timer.h"
     1.9  
    1.10  /* Don't do the check for Visual Studio 2005, it's safe here */
    1.11 @@ -33,7 +34,25 @@
    1.12  SDL_bool
    1.13  SDL_AtomicTryLock(SDL_SpinLock *lock)
    1.14  {
    1.15 -#if defined(_MSC_VER)
    1.16 +#if SDL_ATOMIC_DISABLED
    1.17 +    /* Terrible terrible damage */
    1.18 +    static SDL_mutex *_spinlock_mutex;
    1.19 +
    1.20 +    if (!_spinlock_mutex) {
    1.21 +        /* Race condition on first lock... */
    1.22 +        _spinlock_mutex = SDL_CreateMutex();
    1.23 +    }
    1.24 +    SDL_mutexP(_spinlock_mutex);
    1.25 +    if (*lock == 0) {
    1.26 +        *lock = 1;
    1.27 +        SDL_mutexV(_spinlock_mutex);
    1.28 +        return SDL_TRUE;
    1.29 +    } else {
    1.30 +        SDL_mutexV(_spinlock_mutex);
    1.31 +        return SDL_FALSE;
    1.32 +    }
    1.33 +
    1.34 +#elif defined(_MSC_VER)
    1.35      SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
    1.36      return (InterlockedExchange((long*)lock, 1) == 0);
    1.37