From cad9b367a51f3efaefa666d68379fb21e1352678 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 15 May 2008 21:35:51 -0700 Subject: [PATCH] Use pthread_mutexattr_setkind_np as a fallback to set a recursive mutex type Some systems (FreeBSD) don't like setting it through pthread_mutexattr_settype --- CMakeLists.txt | 3 +++ OpenAL32/Include/alMain.h | 7 +++++++ config.h.in | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2af7e7f..f1c38727 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,6 +167,9 @@ IF(NOT HAVE_WINDOWS_H) MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!") ENDIF() + # Some systems need pthread_np.h to get recursive mutexes + CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H) + # _GNU_SOURCE is needed on some systems for extra attributes, and # _REENTRANT is needed for libc thread-safety ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 98d84a18..6bc5fd48 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -17,6 +17,9 @@ #include #include +#ifdef HAVE_PTHREAD_NP_H +#include +#endif #include #include #include @@ -45,6 +48,10 @@ static inline void InitializeCriticalSection(CRITICAL_SECTION *cs) assert(ret == 0); ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE); +#ifdef HAVE_PTHREAD_NP_H + if(ret != 0) + ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE); +#endif assert(ret == 0); ret = pthread_mutex_init(cs, &attrib); assert(ret == 0); diff --git a/config.h.in b/config.h.in index 5890b6fd..f40ca8a9 100644 --- a/config.h.in +++ b/config.h.in @@ -46,4 +46,7 @@ /* Define if we have GCC's destructor attribute */ #cmakedefine HAVE_GCC_DESTRUCTOR +/* Define if we have pthread_np.h */ +#cmakedefine HAVE_PTHREAD_NP_H + #endif -- 2.11.4.GIT