Implemented pthread spinlocks.
This commit is contained in:
parent
d39b9dd978
commit
dfe639930e
3 changed files with 29 additions and 2 deletions
19
configure.in
19
configure.in
|
@ -280,6 +280,25 @@ if test x$enable_gcc_atomics = xyes; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check for pthread implementation
|
||||||
|
AC_MSG_CHECKING(for pthread spinlock)
|
||||||
|
have_pthread_spinlock=no
|
||||||
|
|
||||||
|
AC_TRY_LINK([
|
||||||
|
#include <pthread.h>
|
||||||
|
],[
|
||||||
|
pthread_spinlock_t a;
|
||||||
|
pthread_spin_trylock(&a);
|
||||||
|
pthread_spin_unlock(&a);
|
||||||
|
],[
|
||||||
|
have_pthread_spinlock=yes
|
||||||
|
])
|
||||||
|
AC_MSG_RESULT($have_pthread_spinlock)
|
||||||
|
if test x$have_pthread_spinlock = xyes; then
|
||||||
|
AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [ ])
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Standard C sources
|
# Standard C sources
|
||||||
SOURCES="$SOURCES $srcdir/src/*.c"
|
SOURCES="$SOURCES $srcdir/src/*.c"
|
||||||
SOURCES="$SOURCES $srcdir/src/atomic/*.c"
|
SOURCES="$SOURCES $srcdir/src/atomic/*.c"
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#undef SIZEOF_VOIDP
|
#undef SIZEOF_VOIDP
|
||||||
#undef HAVE_GCC_ATOMICS
|
#undef HAVE_GCC_ATOMICS
|
||||||
#undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
#undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||||
|
#undef HAVE_PTHREAD_SPINLOCK
|
||||||
|
|
||||||
/* Comment this if you want to build without any C library requirements */
|
/* Comment this if you want to build without any C library requirements */
|
||||||
#undef HAVE_LIBC
|
#undef HAVE_LIBC
|
||||||
|
|
|
@ -77,9 +77,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||||
return (result == 0);
|
return (result == 0);
|
||||||
|
|
||||||
|
#elif HAVE_PTHREAD_SPINLOCK
|
||||||
|
/* pthread instructions */
|
||||||
|
return (pthread_spin_trylock(lock) == 0);
|
||||||
#else
|
#else
|
||||||
/* Need CPU instructions for spinlock here! */
|
/* Need CPU instructions for spinlock here! */
|
||||||
__need_spinlock_implementation__
|
__need_spinlock_implementation__
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +106,9 @@ SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||||
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||||
__sync_lock_release(lock);
|
__sync_lock_release(lock);
|
||||||
|
|
||||||
|
#elif HAVE_PTHREAD_SPINLOCK
|
||||||
|
pthread_spin_unlock(lock);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
*lock = 0;
|
*lock = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue