Implemented pthread spinlocks.
authorNathan Heisey <nathanheisey@gmail.com>
Wed, 22 Jun 2011 10:33:48 +0000
changeset 5557c1ed57cbfd66
parent 5556 45a709ef443d
child 5558 dd0f52bf2bfa
Implemented pthread spinlocks.
configure.in
include/SDL_config.h.in
src/atomic/SDL_spinlock.c
     1.1 --- a/configure.in	Wed Jun 15 10:28:01 2011 +0100
     1.2 +++ b/configure.in	Wed Jun 22 10:33:48 2011 +0000
     1.3 @@ -280,6 +280,25 @@
     1.4      fi
     1.5  fi
     1.6  
     1.7 +# Check for pthread implementation
     1.8 +AC_MSG_CHECKING(for pthread spinlock)
     1.9 +have_pthread_spinlock=no
    1.10 +
    1.11 +AC_TRY_LINK([
    1.12 +#include <pthread.h>
    1.13 +],[
    1.14 +pthread_spinlock_t a;
    1.15 +pthread_spin_trylock(&a);
    1.16 +pthread_spin_unlock(&a);
    1.17 +],[
    1.18 +have_pthread_spinlock=yes
    1.19 +])
    1.20 +AC_MSG_RESULT($have_pthread_spinlock)
    1.21 +if test x$have_pthread_spinlock = xyes; then
    1.22 +    AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [ ])
    1.23 +fi
    1.24 +
    1.25 +
    1.26  # Standard C sources
    1.27  SOURCES="$SOURCES $srcdir/src/*.c"
    1.28  SOURCES="$SOURCES $srcdir/src/atomic/*.c"
     2.1 --- a/include/SDL_config.h.in	Wed Jun 15 10:28:01 2011 +0100
     2.2 +++ b/include/SDL_config.h.in	Wed Jun 22 10:33:48 2011 +0000
     2.3 @@ -45,6 +45,7 @@
     2.4  #undef SIZEOF_VOIDP
     2.5  #undef HAVE_GCC_ATOMICS
     2.6  #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET
     2.7 +#undef HAVE_PTHREAD_SPINLOCK
     2.8  
     2.9  /* Comment this if you want to build without any C library requirements */
    2.10  #undef HAVE_LIBC
     3.1 --- a/src/atomic/SDL_spinlock.c	Wed Jun 15 10:28:01 2011 +0100
     3.2 +++ b/src/atomic/SDL_spinlock.c	Wed Jun 22 10:33:48 2011 +0000
     3.3 @@ -77,9 +77,13 @@
     3.4          : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
     3.5      return (result == 0);
     3.6  
     3.7 -#else
     3.8 +#elif HAVE_PTHREAD_SPINLOCK
     3.9 +    /* pthread instructions */
    3.10 +    return (pthread_spin_trylock(lock) == 0);
    3.11 +#else	
    3.12      /* Need CPU instructions for spinlock here! */
    3.13      __need_spinlock_implementation__
    3.14 +	
    3.15  #endif
    3.16  }
    3.17  
    3.18 @@ -101,7 +105,10 @@
    3.19  
    3.20  #elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
    3.21      __sync_lock_release(lock);
    3.22 -
    3.23 +    
    3.24 +#elif HAVE_PTHREAD_SPINLOCK
    3.25 +    pthread_spin_unlock(lock);
    3.26 +	
    3.27  #else
    3.28      *lock = 0;
    3.29  #endif