Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
SDL 1.3 patch 00 for GSoC: Haiku - Implemented pthread spinlock in sr…
Browse files Browse the repository at this point in the history
…c/atomic/spinlock.c (in both trylock and

unlock).  Added appropriate checks in configure.in and include/SDL_configure.h.in.
  • Loading branch information
antifinidictor committed Jun 21, 2011
1 parent 2a77058 commit df726b9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
19 changes: 19 additions & 0 deletions configure.in
Expand Up @@ -280,6 +280,25 @@ if test x$enable_gcc_atomics = xyes; then
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
SOURCES="$SOURCES $srcdir/src/*.c"
SOURCES="$SOURCES $srcdir/src/atomic/*.c"
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.in
Expand Up @@ -45,6 +45,7 @@
#undef SIZEOF_VOIDP
#undef HAVE_GCC_ATOMICS
#undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET
#undef HAVE_PTHREAD_SPINLOCK

/* Comment this if you want to build without any C library requirements */
#undef HAVE_LIBC
Expand Down
11 changes: 9 additions & 2 deletions src/atomic/SDL_spinlock.c
Expand Up @@ -77,9 +77,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
return (result == 0);

#else
#elif HAVE_PTHREAD_SPINLOCK
/* pthread instructions */
return (pthread_spin_trylock(lock) == 0);
#else
/* Need CPU instructions for spinlock here! */
__need_spinlock_implementation__

#endif
}

Expand All @@ -101,7 +105,10 @@ SDL_AtomicUnlock(SDL_SpinLock *lock)

#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
__sync_lock_release(lock);


#elif HAVE_PTHREAD_SPINLOCK
pthread_spin_unlock(lock);

#else
*lock = 0;
#endif
Expand Down

0 comments on commit df726b9

Please sign in to comment.