Check for the non-portable pthread_tryjoin_np.
authorWerner Koch <wk@gnupg.org>
Thu, 26 Jan 2012 10:15:16 +0000 (11:15 +0100)
committerWerner Koch <wk@gnupg.org>
Thu, 26 Jan 2012 10:15:16 +0000 (11:15 +0100)
* configure.ac: Check for pthread_tryjoin_np.  Also rework the pthread
test to update LIBS
* src/npth.c (npth_join) [HAVE_PTHREAD_TRYJOIN_NP]: Use
pthread_tryjoin_np only if available.

configure.ac
src/npth.c

index 3081cd9..6e1e9a5 100644 (file)
@@ -152,10 +152,12 @@ AM_CONDITIONAL(HAVE_W64_SYSTEM, test "$have_w64_system" = yes)
 
 if test "$have_w32_system" = no; then
   have_pthread=no
-  AC_CHECK_LIB(pthread,pthread_create,have_pthread=yes)
-  if test "$have_pthread" = yes; then
+  AC_CHECK_LIB(pthread, pthread_create)
+  if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then
+    have_pthread=yes
     AC_DEFINE(HAVE_PTHREAD, ,[Define if we have pthread.])
   fi
+  AC_CHECK_FUNCS([pthread_tryjoin_np])
 fi
 
 NETLIBS=
@@ -191,6 +193,7 @@ AC_SUBST(BUILD_TIMESTAMP)
 AC_SUBST(BUILD_FILEVERSION)
 
 # Substitution used for npth-config
+# Fixme:  This should be based on the above tests.
 NPTH_CONFIG_LIBS="-lposix -lrt"
 NPTH_CONFIG_CFLAGS=""
 NPTH_CONFIG_HOST="$host"
index 7185974..43c17a1 100644 (file)
@@ -169,11 +169,13 @@ npth_join (npth_t thread, void **retval)
 {
   int err;
 
+#ifdef HAVE_PTHREAD_TRYJOIN_NP
   /* No need to allow competing threads to enter when we can get the
-     lock immediately.  */
+     lock immediately.  pthread_tryjoin_np is a GNU extension.  */
   err = pthread_tryjoin_np (thread, retval);
   if (err != EBUSY)
     return err;
+#endif /*HAVE_PTHREAD_TRYJOIN_NP*/
 
   ENTER();
   err = pthread_join (thread, retval);