commit 92b47a321e14f98c524f6e67e7ecabad5afa7886 Author: Jonathan Wakely 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 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 + #include + #include + ], + [ + #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 .]) + 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 -#if __has_include() +#ifdef _GLIBCXX_HAVE_POSIX_SEMAPHORE +# include # include -# if defined SEM_VALUE_MAX || _POSIX_SEM_VALUE_MAX -# define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1 -# endif #endif #include