On 23/11/20 18:31 +0000, Jonathan Wakely wrote:
On 22/11/20 13:37 +0000, Jonathan Wakely via Libstdc++ wrote:
On Sun, 22 Nov 2020, 12:29 Iain Sandoe, <idsan...@googlemail.com> wrote:

thanks for looking at this over the weekend.

Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:

On Sat, 21 Nov 2020 at 23:55, David Edelsohn via Libstdc++
<libstd...@gcc.gnu.org> wrote:
I am seeing 93 new libstdc++ failures on AIX, even after Jonathan's
fixes.  And a few c++ failures with similar symptoms.  I'm not certain
that it is due to this patch, but it's the likely suspect.
Yes, it's that patch.

This should fix most of those errors, but I haven't finished testing
it, and can't commit it now anyway.
<patch.txt>

with r11-5235 + this patch there are still quite a few fails on Darwin -
but
all seem to be the same ( so maybe only problem ;) ):
 “sem_timedwait was not declared in this scope”.

It looks like the semaphore header is optional in SUSv3 (AFAIK that’s still
the claimed edition for Darwin) - and although Darwin has the semaphore
header, it doesn’t seem to have an impl. of sem_timedwait.

just:
int sem_trywait(sem_t *);
int sem_wait(sem_t *) ;



It probably depends on the _POSIX_TIMEOUTS option which MacOS doesn't
support (optional in POSIX 2001, but not 2008).

Hopefully this fixes it, but I haven't tested it on darwin, only
linux, aix and solaris.

Committed.

With the patch this time ...


commit 92b47a321e14f98c524f6e67e7ecabad5afa7886
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Mon Nov 23 17:17:09 2020

    libstdc++: Add configure checks for semaphores
    
    This moves the checks for POSIX semaphores to configure time. As well as
    requiring <semaphore.h> and SEM_VALUE_MAX, we also require the
    sem_timedwait function. That was only optional in POSIX 2001 (and is
    absent on Darwin).
    
    libstdc++-v3/ChangeLog:
    
            * acinclude.m4 (GLIBCXX_CHECK_GTHREADS): Check for
            * config.h.in: Regenerate.
            * configure: Regenerate.
            * include/bits/semaphore_base.h (_GLIBCXX_HAVE_POSIX_SEMAPHORE):
            Check autoconf macro instead of defining it here.

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 486347b34d94..a4a0bb840181 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -4089,6 +4089,43 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
     fi
   fi
 
+  AC_CHECK_HEADER(semaphore.h, [
+    AC_MSG_CHECKING([for POSIX Semaphores and sem_timedwait])
+    AC_TRY_COMPILE([
+	#include <unistd.h>
+	#include <semaphore.h>
+	#include <limits.h>
+      ],
+      [
+	#if !defined _POSIX_TIMEOUTS || _POSIX_TIMEOUTS <= 0
+	# error "POSIX Timeouts option not supported"
+	#elif !defined _POSIX_SEMAPHORES || _POSIX_SEMAPHORES <= 0
+	# error "POSIX Semaphores option not supported"
+	#else
+	#if defined SEM_VALUE_MAX
+	constexpr int sem_value_max = SEM_VALUE_MAX;
+	#elif defined _POSIX_SEM_VALUE_MAX
+	constexpr int sem_value_max = _POSIX_SEM_VALUE_MAX;
+	#else
+	# error "SEM_VALUE_MAX not available"
+	#endif
+	sem_t sem;
+	sem_init(&sem, 0, sem_value_max);
+	struct timespec ts = { 0 };
+	sem_timedwait(&sem, &ts);
+	#endif
+      ],
+      [ac_have_posix_semaphore=yes],
+      [ac_have_posix_semaphore=no])],
+      [ac_have_posix_semaphore=no])
+
+  if test $ac_have_posix_semaphore = yes ; then
+    AC_DEFINE(_GLIBCXX_HAVE_POSIX_SEMAPHORE,
+	      1,
+	      [Define to 1 if POSIX Semaphores with sem_timedwait are available in <semaphore.h>.])
+  fi
+  AC_MSG_RESULT([$ac_have_posix_semaphore])
+
   CXXFLAGS="$ac_save_CXXFLAGS"
   AC_LANG_RESTORE
 ])
diff --git a/libstdc++-v3/include/bits/semaphore_base.h b/libstdc++-v3/include/bits/semaphore_base.h
index 5e29d3783fe1..0692f95f24f2 100644
--- a/libstdc++-v3/include/bits/semaphore_base.h
+++ b/libstdc++-v3/include/bits/semaphore_base.h
@@ -39,11 +39,9 @@
 
 #include <ext/numeric_traits.h>
 
-#if __has_include(<semaphore.h>)
+#ifdef _GLIBCXX_HAVE_POSIX_SEMAPHORE
+# include <limits.h>
 # include <semaphore.h>
-# if defined SEM_VALUE_MAX || _POSIX_SEM_VALUE_MAX
-#  define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1
-# endif
 #endif
 
 #include <chrono>

Reply via email to