Skip to content
Merged
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
1 change: 1 addition & 0 deletions config/gthr.m4
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AC_DEFUN([GCC_AC_THREAD_HEADER],
[
case $1 in
aix) thread_header=config/rs6000/gthr-aix.h ;;
c11) thread_header=gthr-c11.h ;;
dce) thread_header=config/pa/gthr-dce.h ;;
gcn) thread_header=config/gcn/gthr-gcn.h ;;
lynx) thread_header=config/gthr-lynx.h ;;
Expand Down
2 changes: 1 addition & 1 deletion gcc/configure
Original file line number Diff line number Diff line change
Expand Up @@ -12885,7 +12885,7 @@ case ${enable_threads} in
# default
target_thread_file='single'
;;
aix | dce | lynx | mipssde | posix | rtems | \
aix | c11 | dce | lynx | mipssde | posix | rtems | \
single | tpf | vxworks | win32)
target_thread_file=${enable_threads}
;;
Expand Down
2 changes: 1 addition & 1 deletion gcc/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ case ${enable_threads} in
# default
target_thread_file='single'
;;
aix | dce | lynx | mipssde | posix | rtems | \
aix | c11 | dce | lynx | mipssde | posix | rtems | \
single | tpf | vxworks | win32)
target_thread_file=${enable_threads}
;;
Expand Down
1 change: 1 addition & 0 deletions libgcc/configure
Original file line number Diff line number Diff line change
Expand Up @@ -5689,6 +5689,7 @@ tm_file="${tm_file_}"

case $target_thread_file in
aix) thread_header=config/rs6000/gthr-aix.h ;;
c11) thread_header=gthr-c11.h ;;
dce) thread_header=config/pa/gthr-dce.h ;;
gcn) thread_header=config/gcn/gthr-gcn.h ;;
lynx) thread_header=config/gthr-lynx.h ;;
Expand Down
258 changes: 258 additions & 0 deletions libgcc/gthr-c11.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
/* Copyright (C) 1997-2023 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */

/* gthr.h API implementation in terms of ISO C11 threads.h */

#ifndef _GLIBCXX_GCC_GTHR_C11_H
#define _GLIBCXX_GCC_GTHR_C11_H

#define __GTHREADS 1
#define __GTHREADS_CXX0X 1
#define __GTHREAD_ONCE_INIT ONCE_FLAG_INIT

#define _GTHREAD_USE_MUTEX_TIMEDLOCK 1

#undef __GTHREAD_MUTEX_INIT
#define _GTHREAD_USE_MUTEX_INIT_FUNC 1
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function

#undef __GTHREAD_RECURSIVE_MUTEX_INIT
#define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC 1
#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function

#define __GTHREAD_HAS_COND 1
#undef __GTHREAD_COND_INIT
#define _GTHREAD_USE_COND_INIT_FUNC 1
#define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function

#define _GLIBCXX_THREAD_ABI_COMPAT 1
#define _GLIBCXX_HAS_GTHREADS 1
#define _GLIBCXX_USE_THRD_SLEEP 1

#include <threads.h>
#include <time.h>

typedef thrd_t __gthread_t;
typedef tss_t __gthread_key_t;
typedef once_flag __gthread_once_t;
typedef mtx_t __gthread_mutex_t;
typedef mtx_t __gthread_recursive_mutex_t;
typedef cnd_t __gthread_cond_t;
typedef struct timespec __gthread_time_t;

static inline int __gthread_active_p(void)
{
return 1;
}

static inline int
__gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
void *__args)
{
return thrd_create(__threadid, (thrd_start_t)__func, __args) != thrd_success;
}

static inline int
__gthread_join (__gthread_t __threadid, void **__value_ptr)
{
return thrd_join(__threadid, (int *)__value_ptr) != thrd_success;
}

static inline int
__gthread_detach (__gthread_t __threadid)
{
return thrd_detach(__threadid) != thrd_success;
}

static inline int
__gthread_equal (__gthread_t __t1, __gthread_t __t2)
{
return thrd_equal(__t1, __t2);
}

static inline __gthread_t
__gthread_self (void)
{
return thrd_current();
}

static inline int
__gthread_yield (void)
{
(void)thrd_yield();
return 0;
}

static inline int
__gthread_once (__gthread_once_t *__once, void (*__func) (void))
{
call_once(__once, __func);
return 0;
}

static inline int
__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
{
return tss_create(__key, __dtor) != thrd_success;
}

static inline int
__gthread_key_delete (__gthread_key_t __key)
{
tss_delete(__key);
return 0;
}

static inline void *
__gthread_getspecific (__gthread_key_t __key)
{
return tss_get(__key);
}

static inline int
__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
{
return tss_set(__key, (void *)__ptr) != thrd_success;
}

static inline void
__gthread_mutex_init_function (__gthread_mutex_t *__mutex)
{
(void)mtx_init(__mutex, mtx_plain);
}

static inline int
__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
{
mtx_destroy(__mutex);
return 0;
}

static inline int
__gthread_mutex_lock (__gthread_mutex_t *__mutex)
{
return mtx_lock(__mutex) != thrd_success;
}

static inline int
__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
{
return mtx_trylock(__mutex) != thrd_success;
}

static inline int
__gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
const __gthread_time_t *__abs_timeout)
{
return mtx_timedlock(__mutex, __abs_timeout) != thrd_success;
}

static inline int
__gthread_mutex_unlock (__gthread_mutex_t *__mutex)
{
return mtx_unlock(__mutex) != thrd_success;
}

static inline int
__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
{
return mtx_init(__mutex, mtx_recursive) != thrd_success;
}

static inline int
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
{
return mtx_lock(__mutex) != thrd_success;
}

static inline int
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
{
return mtx_trylock(__mutex) != thrd_success;
}

static inline int
__gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
const __gthread_time_t *__abs_timeout)
{
return __gthread_mutex_timedlock (__mutex, __abs_timeout);
}

static inline int
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_unlock (__mutex);
}

static inline int
__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
{
return __gthread_mutex_destroy (__mutex);
}

static inline void
__gthread_cond_init_function (__gthread_cond_t *__cond)
{
(void)cnd_init(__cond);
}

static inline int
__gthread_cond_broadcast (__gthread_cond_t *__cond)
{
return cnd_broadcast(__cond) != thrd_success;
}

static inline int
__gthread_cond_signal (__gthread_cond_t *__cond)
{
return cnd_signal(__cond) != thrd_success;
}

static inline int
__gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
{
return cnd_wait(__cond, __mutex) != thrd_success;
}

static inline int
__gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
const __gthread_time_t *__abs_timeout)
{
return cnd_timedwait(__cond, __mutex, __abs_timeout) != thrd_success;
}

static inline int
__gthread_cond_wait_recursive (__gthread_cond_t *__cond,
__gthread_recursive_mutex_t *__mutex)
{
return __gthread_cond_wait (__cond, __mutex);
}

static inline int
__gthread_cond_destroy (__gthread_cond_t* __cond)
{
cnd_destroy(__cond);
return 0;
}

#endif /* ! _GLIBCXX_GCC_GTHR_C11_H */
21 changes: 19 additions & 2 deletions libstdc++-v3/acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,8 @@ dnl not always desirable because, in glibc 2.16 and earlier, for
dnl example, in turn it triggers the linking of libpthread too,
dnl which activates locking,
dnl a large overhead for single-thread programs.
dnl --enable-libstdcxx-time=c11
dnl checks for the availability of <threads.h> and thrd_sleep in libc.
dnl --enable-libstdcxx-time=no
dnl --disable-libstdcxx-time
dnl disables the checks completely
Expand All @@ -1333,7 +1335,7 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [

GLIBCXX_ENABLE(libstdcxx-time,auto,[[[=KIND]]],
[use KIND for check type],
[permit yes|no|rt])
[permit yes|no|rt|c11])

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
Expand All @@ -1345,6 +1347,9 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
ac_has_clock_realtime=no
ac_has_nanosleep=no
ac_has_sched_yield=no
ac_has_thrd_sleep=no

AC_CHECK_HEADERS(threads.h, ac_has_threads_h=yes, ac_has_threads_h=no)

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

Expand Down Expand Up @@ -1396,11 +1401,20 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
ac_has_sched_yield=yes
esac

elif test x"$enable_libstdcxx_time" = x"c11"; then

# workaround for the error below until ac_cv_func_thrd_sleep is available when cross-compiling
# checking for library containing thrd_sleep...
# configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
ac_has_thrd_sleep=yes

elif test x"$enable_libstdcxx_time" != x"no"; then

if test x"$enable_libstdcxx_time" = x"rt"; then
AC_SEARCH_LIBS(clock_gettime, [rt])
AC_SEARCH_LIBS(nanosleep, [rt])
elif test x"$enable_libstdcxx_time" = x"c11"; then
AC_CHECK_FUNC(thrd_sleep)
else
AC_CHECK_FUNC(clock_gettime)
AC_CHECK_FUNC(nanosleep)
Expand Down Expand Up @@ -1537,6 +1551,9 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
if test x"$ac_has_nanosleep" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1,
[ Defined if nanosleep is available. ])
elif test x"$ac_has_thrd_sleep" = x"yes"; then
AC_DEFINE(_GLIBCXX_USE_THRD_SLEEP, 1,
[ Defined if thrd_sleep is available. ])
else
AC_MSG_CHECKING([for sleep])
AC_TRY_COMPILE([#include <unistd.h>],
Expand All @@ -1557,7 +1574,7 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
AC_MSG_RESULT($ac_has_usleep)
fi

if test x"$ac_has_nanosleep$ac_has_sleep" = x"nono"; then
if test x"$ac_has_nanosleep$ac_has_sleep$ac_has_thrd_sleep" = x"nonono"; then
ac_no_sleep=yes
AC_MSG_CHECKING([for Sleep])
AC_TRY_COMPILE([#include <windows.h>],
Expand Down
Loading