Skip to content
Snippets Groups Projects
Commit 92b47a32 authored by Jonathan Wakely's avatar Jonathan Wakely
Browse files

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.
parent 183ae52b
No related branches found
No related tags found
No related merge requests found
......@@ -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
])
......
......@@ -872,6 +872,10 @@
/* Define if gthreads library is available. */
#undef _GLIBCXX_HAS_GTHREADS
/* Define to 1 if POSIX Semaphores with sem_timedwait are available in
<semaphore.h>. */
#undef _GLIBCXX_HAVE_POSIX_SEMAPHORE
/* Define to 1 if a full hosted library is built, or 0 if freestanding. */
#undef _GLIBCXX_HOSTED
......
......@@ -76363,6 +76363,64 @@ fi
fi
fi
 
ac_fn_cxx_check_header_mongrel "$LINENO" "semaphore.h" "ac_cv_header_semaphore_h" "$ac_includes_default"
if test "x$ac_cv_header_semaphore_h" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for POSIX Semaphores and sem_timedwait" >&5
$as_echo_n "checking for POSIX Semaphores and sem_timedwait... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <unistd.h>
#include <semaphore.h>
#include <limits.h>
int
main ()
{
#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
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
ac_have_posix_semaphore=yes
else
ac_have_posix_semaphore=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
ac_have_posix_semaphore=no
fi
if test $ac_have_posix_semaphore = yes ; then
$as_echo "#define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_have_posix_semaphore" >&5
$as_echo "$ac_have_posix_semaphore" >&6; }
CXXFLAGS="$ac_save_CXXFLAGS"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment