Skip to content

Commit

Permalink
libstdc++-v3: enable std::thread for zephyr via posix
Browse files Browse the repository at this point in the history
Add zephyr-specific hints for GLIBCXX_ENABLE_LIBSTDCXX_TIME().

Signed-off-by: Chris Friedt <[email protected]>
  • Loading branch information
cfriedt committed Dec 4, 2023
1 parent db5fcf3 commit 1e35c83
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion libstdc++-v3/acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,14 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
uclinux*)
ac_has_nanosleep=yes
ac_has_sched_yield=yes
zephyr*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
ac_has_sched_yield=yes
ac_has_sleep=yes
ac_has_usleep=yes
;;
esac
elif test x"$enable_libstdcxx_time" != x"no"; then
Expand Down Expand Up @@ -1589,12 +1597,21 @@ AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
AC_MSG_CHECKING([for gettimeofday])
case "${target_os}" in
zephyr*)
ac_has_gettimeofday=yes
;;
*)
ac_has_gettimeofday=no
;;
esac
if test x"$ac_has_gettimeofday" != x"yes"; then
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"
ac_has_gettimeofday=no;
AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
if test x"$ac_has_sys_time_h" = x"yes"; then
AC_MSG_CHECKING([for gettimeofday])
Expand All @@ -1604,6 +1621,7 @@ AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
AC_MSG_RESULT($ac_has_gettimeofday)
fi
fi
if test x"$ac_has_gettimeofday" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_GETTIMEOFDAY, 1,
Expand Down Expand Up @@ -3964,6 +3982,17 @@ dnl
AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
GLIBCXX_ENABLE(libstdcxx-threads,auto,,[enable C++11 threads support])
case "${target_os}" in
zephyr*)
# do not attempt to run compile or link tests
notest=yes
ac_gthread_use_mutex_timedlock=yes
ac_has_gthreads=yes
ac_gthread_use_pthreads=yes
ac_have_posix_semaphore=yes
;;
esac
if test x$enable_libstdcxx_threads = xauto ||
test x$enable_libstdcxx_threads = xyes; then
Expand All @@ -3982,6 +4011,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
AC_MSG_CHECKING([whether it can be safely assumed that mutex_timedlock is available])
if test x"$notest" != x"yes"; then
AC_TRY_COMPILE([#include <unistd.h>],
[
// In case of POSIX threads check _POSIX_TIMEOUTS.
Expand All @@ -3990,6 +4020,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
#error
#endif
], [ac_gthread_use_mutex_timedlock=1], [ac_gthread_use_mutex_timedlock=0])
fi
AC_DEFINE_UNQUOTED(_GTHREAD_USE_MUTEX_TIMEDLOCK, $ac_gthread_use_mutex_timedlock,
[Define to 1 if mutex_timedlock is available.])
Expand All @@ -4000,6 +4031,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
AC_MSG_CHECKING([for gthreads library])
if test x"$notest" != x"yes"; then
AC_TRY_COMPILE([#include "gthr.h"],
[
#ifndef __GTHREADS_CXX0X
Expand All @@ -4009,6 +4041,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
else
ac_has_gthreads=no
fi
fi
AC_MSG_RESULT([$ac_has_gthreads])
Expand All @@ -4021,6 +4054,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
# On VxWorks for example, pthread_rwlock_t is defined in sys/types.h
# but the pthread library is not there by default and the gthread library
# does not use it.
if test x"$notest" != x"yes"; then
AC_TRY_COMPILE([#include "gthr.h"],
[
#if (!defined(_PTHREADS))
Expand All @@ -4034,8 +4068,14 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
[],
[#include "gthr.h"])
fi
else
if test x"$ac_gthread_use_pthreads" = x"yes"; then
AC_DEFINE([_GLIBCXX_USE_PTHREAD_RWLOCK_T], 1,
[Define if POSIX read/write locks are available in <gthr.h>.])
fi
fi
if test x"$notest" != x"yes"; then
AC_CHECK_HEADER(semaphore.h, [
AC_MSG_CHECKING([for POSIX Semaphores and sem_timedwait])
AC_TRY_COMPILE([
Expand Down Expand Up @@ -4065,6 +4105,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
[ac_have_posix_semaphore=yes],
[ac_have_posix_semaphore=no])],
[ac_have_posix_semaphore=no])
fi
if test $ac_have_posix_semaphore = yes ; then
AC_DEFINE(HAVE_POSIX_SEMAPHORE,
Expand Down

0 comments on commit 1e35c83

Please sign in to comment.