Fixed bug 2618 - incomplete pthread-based lock support should be removed

binarycrusader

Since changeset 358696c354a8, SDL 2.0 has been broken on Solaris when compiling with the Solaris Studio compiler (which uses the pthread implementation of SDL_AtomicLock).

Notably, it gets stuck at the MemoryBarrierRelease in SDL_GetErrBuf:

6585 # 218
6586     if (!tls_errbuf && !tls_being_created) {
6587          SDL_AtomicLock_REAL ( & tls_lock );
6588         if (!tls_errbuf) {
6589             SDL_TLSID slot;
6590             tls_being_created = SDL_TRUE;
6591             slot =  SDL_TLSCreate_REAL ( );
6592             tls_being_created = SDL_FALSE;
6593              { SDL_SpinLock _tmp = 0 ; SDL_AtomicLock_REAL ( & _tmp ) ; SDL_AtomicUnlock_REAL ( & _tmp ) ; };
^^^ loops forever above
6594             tls_errbuf = slot;
6595         }
6596          SDL_AtomicUnlock_REAL ( & tls_lock );
6597     }


Running: testthread
(process id 28926)
^Cdbx: warning: Interrupt ignored but forwarded to child.
signal INT (Interrupt) in __nanosleep at 0xfe52a875
0xfe52a875: __nanosleep+0x0015: jae      __nanosleep+0x23   [ 0xfe52a883, .+0xe ]
Current function is SDL_Delay_REAL
  204           was_error = nanosleep(&tv, &elapsed);
(dbx) where
  [1] __nanosleep(0xfeffe848, 0xfeffe850, 0xfe75a5ac, 0xfe5169d8), at 0xfe52a875
  [2] nanosleep(0xfeffe848, 0xfeffe850), at 0xfe516a3b
=>[3] SDL_Delay_REAL(ms = 0), line 204 in "SDL_systimer.c"
  [4] SDL_AtomicLock_REAL(lock = 0xfeffe88c), line 104 in "SDL_spinlock.c"
  [5] SDL_GetErrBuf(), line 225 in "SDL_thread.c"
  [6] SDL_ClearError_REAL(), line 216 in "SDL_error.c"
  [7] SDL_InitSubSystem_REAL(flags = 0), line 116 in "SDL.c"
  [8] SDL_Init_REAL(flags = 0), line 244 in "SDL.c"
  [9] SDL_Init(a = 0), line 89 in "SDL_dynapi_procs.h"
  [10] main(argc = 1, argv = 0xfeffe948), line 65 in "testthread.c"

As far as I can tell, this is because pthread_spin_trylock() always returns EBUSY for this particular lock; since it works in other places, I'm suspicious.

Different Solaris Studio compiler versions seem to make no difference.

I've verified this is broken on Linux as well if SDL_spinlock.c is modified to use the pthread implementation.

This appears to be because pthread_spin_init() and pthread_spin_destroy() are not used with the locks as required.
This commit is contained in:
Sam Lantinga 2014-07-07 21:27:42 -07:00
parent 0c8e33764c
commit 8077bf3d10
8 changed files with 0 additions and 28 deletions

View File

@ -753,13 +753,6 @@ macro(CheckPTHREAD)
endif(HAVE_PTHREADS_SEM) endif(HAVE_PTHREADS_SEM)
endif(PTHREADS_SEM) endif(PTHREADS_SEM)
check_c_source_compiles("
#include <pthread.h>
int main(int argc, char** argv) {
pthread_spin_trylock(NULL);
return 0;
}" HAVE_PTHREAD_SPINLOCK)
check_c_source_compiles(" check_c_source_compiles("
#include <pthread.h> #include <pthread.h>
#include <pthread_np.h> #include <pthread_np.h>

View File

@ -2384,15 +2384,6 @@ AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]])
AC_MSG_RESULT($have_sem_timedwait) AC_MSG_RESULT($have_sem_timedwait)
fi fi
AC_MSG_CHECKING(for pthread_spin_trylock)
AC_TRY_LINK_FUNC(pthread_spin_trylock, [
has_pthread_spin_trylock=yes
AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [ ])
],[
has_pthread_spin_trylock=no
])
AC_MSG_RESULT($has_pthread_spin_trylock)
AC_CHECK_HEADER(pthread_np.h, have_pthread_np_h=yes, have_pthread_np_h=no, [ #include <pthread.h> ]) AC_CHECK_HEADER(pthread_np.h, have_pthread_np_h=yes, have_pthread_np_h=no, [ #include <pthread.h> ])
if test x$have_pthread_np_h = xyes; then if test x$have_pthread_np_h = xyes; then
AC_DEFINE(HAVE_PTHREAD_NP_H, 1, [ ]) AC_DEFINE(HAVE_PTHREAD_NP_H, 1, [ ])

View File

@ -46,7 +46,6 @@
#cmakedefine HAVE_GCC_ATOMICS @HAVE_GCC_ATOMICS@ #cmakedefine HAVE_GCC_ATOMICS @HAVE_GCC_ATOMICS@
#cmakedefine HAVE_GCC_SYNC_LOCK_TEST_AND_SET @HAVE_GCC_SYNC_LOCK_TEST_AND_SET@ #cmakedefine HAVE_GCC_SYNC_LOCK_TEST_AND_SET @HAVE_GCC_SYNC_LOCK_TEST_AND_SET@
#cmakedefine HAVE_PTHREAD_SPINLOCK @HAVE_PTHREAD_SPINLOCK@
#cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@ #cmakedefine HAVE_DXGI_H @HAVE_DXGI_H@

View File

@ -49,7 +49,6 @@
#endif #endif
#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
#undef HAVE_DDRAW_H #undef HAVE_DDRAW_H
#undef HAVE_DINPUT_H #undef HAVE_DINPUT_H

View File

@ -50,7 +50,6 @@
#endif #endif
#define HAVE_GCC_ATOMICS 1 #define HAVE_GCC_ATOMICS 1
/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */ /* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */
#define HAVE_PTHREAD_SPINLOCK 1
/* Comment this if you want to build without any C library requirements */ /* Comment this if you want to build without any C library requirements */
#define HAVE_LIBC 1 #define HAVE_LIBC 1

View File

@ -46,7 +46,6 @@
#define SIZEOF_VOIDP 4 #define SIZEOF_VOIDP 4
#define HAVE_GCC_ATOMICS 1 #define HAVE_GCC_ATOMICS 1
/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */ /* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */
#define HAVE_PTHREAD_SPINLOCK 1
/* Comment this if you want to build without any C library requirements */ /* Comment this if you want to build without any C library requirements */
#define HAVE_LIBC 0 #define HAVE_LIBC 0

View File

@ -50,7 +50,6 @@
#endif #endif
#define HAVE_GCC_ATOMICS 1 #define HAVE_GCC_ATOMICS 1
/* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */ /* #undef HAVE_GCC_SYNC_LOCK_TEST_AND_SET */
#define HAVE_PTHREAD_SPINLOCK 1
/* Comment this if you want to build without any C library requirements */ /* Comment this if you want to build without any C library requirements */
#define HAVE_LIBC 1 #define HAVE_LIBC 1

View File

@ -89,10 +89,6 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
/* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */ /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
return OSAtomicCompareAndSwap32Barrier(0, 1, lock); return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
#elif HAVE_PTHREAD_SPINLOCK
/* pthread instructions */
return (pthread_spin_trylock(lock) == 0);
#elif defined(__SOLARIS__) && defined(_LP64) #elif defined(__SOLARIS__) && defined(_LP64)
/* Used for Solaris with non-gcc compilers. */ /* Used for Solaris with non-gcc compilers. */
return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0); return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0);
@ -126,9 +122,6 @@ 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);
#elif defined(__SOLARIS__) #elif defined(__SOLARIS__)
/* Used for Solaris when not using gcc. */ /* Used for Solaris when not using gcc. */
*lock = 0; *lock = 0;