Skip to contentSkip to conversation

build: Define __USE_UNIX98 for old glibc

PATCH New Takashi Iwai 1 participant 2 messages May 16, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 build: Define __USE_UNIX98 for old glibc

Otherwise PTHREAD_MUTEX_RECURSIVE isn't defined and we get an error with old glibc.

---
 src/pcm/pcm_local.h | 1 +
 1 file changed, 1 insertion(+)
src/pcm/pcm_local.h +1 -0
index 32e6dcdf6fcd..e4f652187c49 100644
@@ -35,6 +35,7 @@
 #include "local.h"
 
 #ifdef THREAD_SAFE_API
+#define __USE_UNIX98 1	/* for old glibc */
 #include <pthread.h>
 #endif
 
Signature · 1 line
2.13.0
#1 lore raw

PATCH 2/2 conf: Check the availability of PTHREAD_MUTEX_RECURSIVE

Check the availability of PTHREAD_MUTEX_RECURSIVE in configure script and use it only when possible. A fairly old version of glibc still seems working, but just to be sure.

---
 configure.ac  | 9 +++++++++
 src/conf.c    | 2 ++
 src/pcm/pcm.c | 2 ++
 3 files changed, 13 insertions(+)
configure.ac +9 -0
index ec254762bed6..a17f2c4aef5c 100644
@@ -266,6 +266,15 @@ else
   AC_MSG_RESULT(no)
 fi
 
+dnl Check for pthread
+if test "$HAVE_LIBPTHREAD" = "yes"; then
+  AC_CHECK_DECL(PTHREAD_MUTEX_RECURSIVE,
+    AC_DEFINE(HAVE_PTHREAD_MUTEX_RECURSIVE, [],
+      [Define if your pthreads implementation have PTHREAD_MUTEX_RECURSIVE]),
+    ,
+    [#include <pthread.h>])
+fi
+
 dnl Check for __thread
 AC_MSG_CHECKING([for __thread])
 AC_LINK_IFELSE([AC_LANG_PROGRAM([#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 1) || (__GNUC__ == 4 && __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ < 2))
src/conf.c +2 -0
index 2b52b44e9144..9a887433a4fe 100644
@@ -490,7 +490,9 @@ static void snd_config_init_mutex(void)
 	pthread_mutexattr_t attr;
 
 	pthread_mutexattr_init(&attr);
+#ifdef HAVE_PTHREAD_MUTEX_RECURSIVE
 	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+#endif
 	pthread_mutex_init(&snd_config_update_mutex, &attr);
 	pthread_mutexattr_destroy(&attr);
 }
src/pcm/pcm.c +2 -0
index 8a7a5950de3c..200b10c2c09c 100644
@@ -2600,7 +2600,9 @@ int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
 	INIT_LIST_HEAD(&pcm->async_handlers);
 #ifdef THREAD_SAFE_API
 	pthread_mutexattr_init(&attr);
+#ifdef HAVE_PTHREAD_MUTEX_RECURSIVE
 	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+#endif
 	pthread_mutex_init(&pcm->lock, &attr);
 	/* use locking as default;
 	 * each plugin may suppress this in its open call
Signature · 1 line
2.13.0