Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libstdc++-v3: enable std::thread for zephyr via posix #25

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,14 @@ else
is_cross_compiler=yes
fi

# required for gthr-posix.h support in Zephyr
case "${target}" in
*zephyr*)
CFLAGS="$CFLAGS -include `realpath $srcdir/libgcc/zephyr-bits.h`"
CXXFLAGS="$CXXFLAGS -include `realpath $srcdir/libgcc/zephyr-bits.h`"
;;
esac

# Find the build and target subdir names.

# post-stage1 host modules use a different CC_FOR_BUILD so, in order to
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ else
is_cross_compiler=yes
fi

# required for gthr-posix.h support in Zephyr
case "${target}" in
*zephyr*)
CFLAGS="$CFLAGS -include `realpath $srcdir/libgcc/zephyr-bits.h`"
CXXFLAGS="$CXXFLAGS -include `realpath $srcdir/libgcc/zephyr-bits.h`"
;;
esac

# Find the build and target subdir names.
GCC_TOPLEV_SUBDIRS
# Be sure to cover against remnants of an in-tree build.
Expand Down
13 changes: 13 additions & 0 deletions libgcc/zephyr-bits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef LIBGCC_ZEPHYR_BITS_H_
#define LIBGCC_ZEPHYR_BITS_H_

#define _POSIX_THREADS 200809L
#define _POSIX_TIMERS 200809L
#define _POSIX_MONOTONIC_CLOCK 200809L
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1

#define _PTHREAD_MUTEX_INITIALIZER (-1)
#define _PTHREAD_COND_INITIALIZER (-1)
#define _PTHREAD_ONCE_INIT {1,0}

#endif /* LIBGCC_ZEPHYR_BITS_H_ */
65 changes: 64 additions & 1 deletion libstdc++-v3/acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,8 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
ac_has_clock_realtime=no
ac_has_nanosleep=no
ac_has_sched_yield=no
ac_has_sleep=no
ac_has_usleep=no

if test x"$enable_libstdcxx_time" = x"auto"; then

Expand Down Expand Up @@ -1396,6 +1398,17 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
ac_has_sched_yield=yes
esac

case "${target}" in
*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

if test x"$enable_libstdcxx_time" = x"rt"; then
Expand Down Expand Up @@ -1589,21 +1602,38 @@ AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [

AC_MSG_CHECKING([for gettimeofday])

runtests=yes
ac_has_gettimeofday=no
ac_has_sys_time_h=no

case "${target}" in
*zephyr*)
runtests=no
ac_has_gettimeofday=yes
ac_has_sys_time_h=yes
;;
esac

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"

ac_has_gettimeofday=no;
if test x"$runtests" = x"yes"; then
AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
fi

if test x"$ac_has_sys_time_h" = x"yes"; then
AC_MSG_CHECKING([for gettimeofday])
if test x"$runtests" = x"yes"; then
GCC_TRY_COMPILE_OR_LINK([#include <sys/time.h>],
[timeval tv; gettimeofday(&tv, 0);],
[ac_has_gettimeofday=yes], [ac_has_gettimeofday=no])
fi

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 +3994,24 @@ dnl
AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
GLIBCXX_ENABLE(libstdcxx-threads,auto,,[enable C++11 threads support])

runtests=yes
ac_gthread_use_mutex_timedlock=no
ac_has_gthreads=no
ac_gthread_use_pthreads=no
ac_have_posix_semaphore=no
ac_gthread_use_pthreads_rwlock_t=no

case "${target}" in
*zephyr*)
runtests=no
ac_gthread_use_mutex_timedlock=yes
ac_has_gthreads=yes
ac_gthread_use_pthreads=yes
ac_have_posix_semaphore=yes
ac_gthread_use_pthreads_rwlock_t=yes
;;
esac

if test x$enable_libstdcxx_threads = xauto ||
test x$enable_libstdcxx_threads = xyes; then

Expand All @@ -3982,6 +4030,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [

AC_MSG_CHECKING([whether it can be safely assumed that mutex_timedlock is available])

if x"$runtests" = x"yes"; then
AC_TRY_COMPILE([#include <unistd.h>],
[
// In case of POSIX threads check _POSIX_TIMEOUTS.
Expand All @@ -3990,6 +4039,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 +4050,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [

AC_MSG_CHECKING([for gthreads library])

if x"$runtests" = x"yes"; then
AC_TRY_COMPILE([#include "gthr.h"],
[
#ifndef __GTHREADS_CXX0X
Expand All @@ -4009,6 +4060,7 @@ AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
else
ac_has_gthreads=no
fi
fi

AC_MSG_RESULT([$ac_has_gthreads])

Expand All @@ -4021,21 +4073,31 @@ 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 x"$runtests" = x"yes"; then
AC_TRY_COMPILE([#include "gthr.h"],
[
#if (!defined(_PTHREADS))
#error
#endif
], [ac_gthread_use_pthreads=yes], [ac_gthread_use_pthreads=no])
fi
if test x"$ac_gthread_use_pthreads" = x"yes"; then
if x"$runtests" = x"yes"; then
AC_CHECK_TYPE([pthread_rwlock_t],
[AC_DEFINE([_GLIBCXX_USE_PTHREAD_RWLOCK_T], 1,
[Define if POSIX read/write locks are available in <gthr.h>.])],
[],
[#include "gthr.h"])
else
if x"$ac_gthread_use_pthreads_rwlock_t" = x"yes"; then
AC_DEFINE([_GLIBCXX_USE_PTHREAD_RWLOCK_T], 1,
[Define if POSIX read/write locks are available in <gthr.h>.])
fi
fi
fi
fi

if x"$runtests" = 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 +4127,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
63 changes: 61 additions & 2 deletions libstdc++-v3/configure
Original file line number Diff line number Diff line change
Expand Up @@ -20396,6 +20396,17 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gettimeofday" >&5
$as_echo_n "checking for gettimeofday... " >&6; }

runtests=yes
ac_has_gettimeofday=no
ac_has_sys_time_h=no

case "${target}" in
*zephyr*)
runtests=no
ac_has_gettimeofday=yes
ac_has_sys_time_h=yes
;;
esac

ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
Expand All @@ -20406,7 +20417,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -fno-exceptions"

ac_has_gettimeofday=no;
if test x"$runtests" = x"yes"; then
for ac_header in sys/time.h
do :
ac_fn_cxx_check_header_mongrel "$LINENO" "sys/time.h" "ac_cv_header_sys_time_h" "$ac_includes_default"
Expand All @@ -20420,10 +20431,12 @@ else
fi

done
fi

if test x"$ac_has_sys_time_h" = x"yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gettimeofday" >&5
$as_echo_n "checking for gettimeofday... " >&6; }
if test x"$runtests" = x"yes"; then
if test x$gcc_no_link = xyes; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
Expand Down Expand Up @@ -20464,11 +20477,12 @@ else
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
fi
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_has_gettimeofday" >&5
$as_echo "$ac_has_gettimeofday" >&6; }
fi

if test x"$ac_has_gettimeofday" = x"yes"; then

Expand Down Expand Up @@ -20517,6 +20531,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
ac_has_clock_realtime=no
ac_has_nanosleep=no
ac_has_sched_yield=no
ac_has_sleep=no
ac_has_usleep=no

if test x"$enable_libstdcxx_time" = x"auto"; then

Expand Down Expand Up @@ -20626,6 +20642,17 @@ fi
ac_has_sched_yield=yes
esac

case "${target}" in
*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

if test x"$enable_libstdcxx_time" = x"rt"; then
Expand Down Expand Up @@ -76041,6 +76068,23 @@ else
fi


runtests=yes
ac_gthread_use_mutex_timedlock=no
ac_has_gthreads=no
ac_gthread_use_pthreads=no
ac_have_posix_semaphore=no
ac_gthread_use_pthreads_rwlock_t=no

case "${target}" in
*zephyr*)
runtests=no
ac_gthread_use_mutex_timedlock=yes
ac_has_gthreads=yes
ac_gthread_use_pthreads=yes
ac_have_posix_semaphore=yes
ac_gthread_use_pthreads_rwlock_t=yes
;;
esac

if test x$enable_libstdcxx_threads = xauto ||
test x$enable_libstdcxx_threads = xyes; then
Expand All @@ -76066,6 +76110,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether it can be safely assumed that mutex_timedlock is available" >&5
$as_echo_n "checking whether it can be safely assumed that mutex_timedlock is available... " >&6; }

if x"$runtests" = x"yes"; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <unistd.h>
Expand All @@ -76089,6 +76134,7 @@ else
ac_gthread_use_mutex_timedlock=0
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi


cat >>confdefs.h <<_ACEOF
Expand All @@ -76104,6 +76150,7 @@ $as_echo "$res_mutex_timedlock" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gthreads library" >&5
$as_echo_n "checking for gthreads library... " >&6; }

if x"$runtests" = x"yes"; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include "gthr.h"
Expand All @@ -76128,6 +76175,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
ac_has_gthreads=no
fi
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_has_gthreads" >&5
$as_echo "$ac_has_gthreads" >&6; }
Expand All @@ -76142,6 +76190,7 @@ $as_echo "#define _GLIBCXX_HAS_GTHREADS 1" >>confdefs.h
# 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 x"$runtests" = x"yes"; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include "gthr.h"
Expand All @@ -76163,18 +76212,27 @@ else
ac_gthread_use_pthreads=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
if test x"$ac_gthread_use_pthreads" = x"yes"; then
if x"$runtests" = x"yes"; then
ac_fn_cxx_check_type "$LINENO" "pthread_rwlock_t" "ac_cv_type_pthread_rwlock_t" "#include \"gthr.h\"
"
if test "x$ac_cv_type_pthread_rwlock_t" = xyes; then :

$as_echo "#define _GLIBCXX_USE_PTHREAD_RWLOCK_T 1" >>confdefs.h

fi
else
if test "x$ac_cv_type_pthread_rwlock_t" = xyes; then :

$as_echo "#define _GLIBCXX_USE_PTHREAD_RWLOCK_T 1" >>confdefs.h

fi
fi
fi
fi

if x"$runtests" = x"yes"; then
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 :

Expand Down Expand Up @@ -76222,6 +76280,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
ac_have_posix_semaphore=no
fi
fi



Expand Down