Commit a7df9020 authored by Sam Lantinga's avatar Sam Lantinga

Favor using pthread_mutexattr_settype() on Linux.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401327
parent 17858398
...@@ -1201,6 +1201,10 @@ CheckPTHREAD() ...@@ -1201,6 +1201,10 @@ CheckPTHREAD()
[ --enable-pthread-sem use pthread semaphores [default=yes]], [ --enable-pthread-sem use pthread semaphores [default=yes]],
, enable_pthread_sem=yes) , enable_pthread_sem=yes)
case "$target" in case "$target" in
*-*-linux*)
pthread_cflags="-D_REENTRANT -D_GNU_SOURCE"
pthread_lib="-lpthread"
;;
*-*-bsdi*) *-*-bsdi*)
pthread_cflags="-D_REENTRANT -D_THREAD_SAFE" pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
pthread_lib="" pthread_lib=""
...@@ -1288,29 +1292,30 @@ CheckPTHREAD() ...@@ -1288,29 +1292,30 @@ CheckPTHREAD()
# Check to see if recursive mutexes are available # Check to see if recursive mutexes are available
AC_MSG_CHECKING(for recursive mutexes) AC_MSG_CHECKING(for recursive mutexes)
has_recursive_mutexes=no has_recursive_mutexes=no
AC_TRY_LINK([ if test x$has_recursive_mutexes = xno; then
#include <pthread.h> AC_TRY_COMPILE([
],[ #include <pthread.h>
pthread_mutexattr_t attr; ],[
#if defined(linux) && !(defined(__arm__) && defined(QWS)) pthread_mutexattr_t attr;
pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#else ],[
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); has_recursive_mutexes=yes
#endif CFLAGS="$CFLAGS -DPTHREAD_RECURSIVE_MUTEX"
],[ ])
has_recursive_mutexes=yes fi
]) if test x$has_recursive_mutexes = xno; then
# Some systems have broken recursive mutex implementations AC_TRY_COMPILE([
case "$target" in #include <pthread.h>
*-*-darwin*) ],[
has_recursive_mutexes=no pthread_mutexattr_t attr;
;; pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
*-*-solaris*) ],[
has_recursive_mutexes=no has_recursive_mutexes=yes
;; CFLAGS="$CFLAGS -DPTHREAD_RECURSIVE_MUTEX_NP"
esac ])
fi
AC_MSG_RESULT($has_recursive_mutexes) AC_MSG_RESULT($has_recursive_mutexes)
if test x$has_recursive_mutexes != xyes; then if test x$has_recursive_mutexes = xno; then
CFLAGS="$CFLAGS -DPTHREAD_NO_RECURSIVE_MUTEX" CFLAGS="$CFLAGS -DPTHREAD_NO_RECURSIVE_MUTEX"
fi fi
......
...@@ -62,15 +62,13 @@ SDL_mutex *SDL_CreateMutex (void) ...@@ -62,15 +62,13 @@ SDL_mutex *SDL_CreateMutex (void)
mutex = (SDL_mutex *)calloc(1, sizeof(*mutex)); mutex = (SDL_mutex *)calloc(1, sizeof(*mutex));
if ( mutex ) { if ( mutex ) {
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
#ifdef PTHREAD_NO_RECURSIVE_MUTEX #if defined(PTHREAD_RECURSIVE_MUTEX)
/* No extra attributes necessary */ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#else #elif defined(PTHREAD_RECURSIVE_MUTEX_NP)
#ifdef linux
pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP); pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
#else #else
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); /* No extra attributes necessary */
#endif #endif /* PTHREAD_RECURSIVE_MUTEX */
#endif /* PTHREAD_NO_RECURSIVE_MUTEX */
if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) { if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) {
SDL_SetError("pthread_mutex_init() failed"); SDL_SetError("pthread_mutex_init() failed");
free(mutex); free(mutex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment