pthread_sigmask: Work around Cygwin bug.
authorBruno Haible <bruno@clisp.org>
Fri, 8 Jul 2011 23:01:36 +0000 (01:01 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 8 Jul 2011 23:01:36 +0000 (01:01 +0200)
* m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Test for the Cygwin
bug.
* lib/pthread_sigmask.c (pthread_sigmask): Fix the return value from
the system's pthread_sigmask function.
* doc/posix-functions/pthread_sigmask.texi: Mention the Cygwin bug.

ChangeLog
doc/posix-functions/pthread_sigmask.texi
lib/pthread_sigmask.c
m4/pthread_sigmask.m4

index 80ae091..cebc6f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2011-07-08  Bruno Haible  <bruno@clisp.org>
 
+       pthread_sigmask: Work around Cygwin bug.
+       * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Test for the Cygwin
+       bug.
+       * lib/pthread_sigmask.c (pthread_sigmask): Fix the return value from
+       the system's pthread_sigmask function.
+       * doc/posix-functions/pthread_sigmask.texi: Mention the Cygwin bug.
+
+2011-07-08  Bruno Haible  <bruno@clisp.org>
+
        pthread_sigmask: Work around bug in single-threaded implementation.
        * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Test for the
        FreeBSD, HP-UX, Solaris bug.
index 62f0a76..58b6295 100644 (file)
@@ -19,6 +19,10 @@ MacOS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6.
 This function does nothing and always returns 0 in programs that are not
 linked with @code{-lpthread} on some platforms:
 FreeBSD 6.4, HP-UX 11.31, Solaris 9.
+@item
+When it fails, this functions returns -1 instead of the error number on
+some platforms:
+Cygwin 1.7.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index b53b15d..06ee7fc 100644 (file)
@@ -43,6 +43,10 @@ pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask)
         }
     }
 # endif
+# if PTHREAD_SIGMASK_FAILS_WITH_ERRNO
+  if (ret == -1)
+    return errno;
+# endif
   return ret;
 #else
   int ret = sigprocmask (how, new_mask, old_mask);
index f8b3e8a..c65a4ce 100644 (file)
@@ -119,6 +119,46 @@ changequote([,])dnl
           ;;
       esac
     fi
+
+    dnl On Cygwin 1.7.5, the pthread_sigmask() has a wrong return value
+    dnl convention: Upon failure, it returns -1 and sets errno.
+    AC_CACHE_CHECK([whether pthread_sigmask returns error numbers],
+      [gl_cv_func_pthread_sigmask_return_works],
+      [
+        gl_save_LIBS="$LIBS"
+        LIBS="$LIBS $LIB_PTHREAD_SIGMASK"
+        AC_RUN_IFELSE(
+          [AC_LANG_SOURCE([[
+#include <pthread.h>
+#include <signal.h>
+#include <stddef.h>
+int main ()
+{
+  sigset_t set;
+  sigemptyset (&set);
+  if (pthread_sigmask (1729, &set, NULL) == -1)
+    return 1;
+  return 0;
+}]])],
+          [gl_cv_func_pthread_sigmask_return_works=yes],
+          [gl_cv_func_pthread_sigmask_return_works=no],
+          [case "$host_os" in
+             cygwin*)
+               gl_cv_func_pthread_sigmask_return_works="guessing no";;
+             *)
+               gl_cv_func_pthread_sigmask_return_works="guessing yes";;
+           esac
+          ])
+        LIBS="$gl_save_LIBS"
+      ])
+    case "$gl_cv_func_pthread_sigmask_return_works" in
+      *no)
+        REPLACE_PTHREAD_SIGMASK=1
+        AC_DEFINE([PTHREAD_SIGMASK_FAILS_WITH_ERRNO], [1],
+          [Define to 1 if pthread_mask(), when it fails, returns -1 and sets errno.])
+        ;;
+    esac
+
   fi
 ])