Skip to content

Commit 52dc7f4

Browse files
cfriedt-friedtcostephanosio
authored andcommitted
libgcc: gthr: support for --enable-threads=c11
Provide the gthr.h API implementation in terms of the ISO C11 threads API. Signed-off-by: Christopher Friedt <chris@friedt.co>
1 parent 685f451 commit 52dc7f4

File tree

8 files changed

+279
-2
lines changed

8 files changed

+279
-2
lines changed

config/gthr.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ AC_DEFUN([GCC_AC_THREAD_HEADER],
1212
[
1313
case $1 in
1414
aix) thread_header=config/rs6000/gthr-aix.h ;;
15+
c11) thread_header=gthr-c11.h ;;
1516
dce) thread_header=config/pa/gthr-dce.h ;;
1617
gcn) thread_header=config/gcn/gthr-gcn.h ;;
1718
lynx) thread_header=config/gthr-lynx.h ;;

gcc/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12885,7 +12885,7 @@ case ${enable_threads} in
1288512885
# default
1288612886
target_thread_file='single'
1288712887
;;
12888-
aix | dce | lynx | mipssde | posix | rtems | \
12888+
aix | c11 | dce | lynx | mipssde | posix | rtems | \
1288912889
single | tpf | vxworks | win32)
1289012890
target_thread_file=${enable_threads}
1289112891
;;

gcc/configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ case ${enable_threads} in
19941994
# default
19951995
target_thread_file='single'
19961996
;;
1997-
aix | dce | lynx | mipssde | posix | rtems | \
1997+
aix | c11 | dce | lynx | mipssde | posix | rtems | \
19981998
single | tpf | vxworks | win32)
19991999
target_thread_file=${enable_threads}
20002000
;;

libgcc/configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5689,6 +5689,7 @@ tm_file="${tm_file_}"
56895689
56905690
case $target_thread_file in
56915691
aix) thread_header=config/rs6000/gthr-aix.h ;;
5692+
c11) thread_header=gthr-c11.h ;;
56925693
dce) thread_header=config/pa/gthr-dce.h ;;
56935694
gcn) thread_header=config/gcn/gthr-gcn.h ;;
56945695
lynx) thread_header=config/gthr-lynx.h ;;

libgcc/gthr-c11.h

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
/* Copyright (C) 1997-2023 Free Software Foundation, Inc.
2+
3+
This file is part of GCC.
4+
5+
GCC is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License as published by the Free
7+
Software Foundation; either version 3, or (at your option) any later
8+
version.
9+
10+
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
Under Section 7 of GPL version 3, you are granted additional
16+
permissions described in the GCC Runtime Library Exception, version
17+
3.1, as published by the Free Software Foundation.
18+
19+
You should have received a copy of the GNU General Public License and
20+
a copy of the GCC Runtime Library Exception along with this program;
21+
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22+
<http://www.gnu.org/licenses/>. */
23+
24+
/* gthr.h API implementation in terms of ISO C11 threads.h */
25+
26+
#ifndef _GLIBCXX_GCC_GTHR_C11_H
27+
#define _GLIBCXX_GCC_GTHR_C11_H
28+
29+
#define __GTHREADS 1
30+
#define __GTHREADS_CXX0X 1
31+
#define __GTHREAD_ONCE_INIT ONCE_FLAG_INIT
32+
33+
#define _GTHREAD_USE_MUTEX_TIMEDLOCK 1
34+
35+
#undef __GTHREAD_MUTEX_INIT
36+
#define _GTHREAD_USE_MUTEX_INIT_FUNC 1
37+
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
38+
39+
#undef __GTHREAD_RECURSIVE_MUTEX_INIT
40+
#define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC 1
41+
#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
42+
43+
#define __GTHREAD_HAS_COND 1
44+
#undef __GTHREAD_COND_INIT
45+
#define _GTHREAD_USE_COND_INIT_FUNC 1
46+
#define __GTHREAD_COND_INIT_FUNCTION __gthread_cond_init_function
47+
48+
#define _GLIBCXX_THREAD_ABI_COMPAT 1
49+
#define _GLIBCXX_HAS_GTHREADS 1
50+
#define _GLIBCXX_USE_THRD_SLEEP 1
51+
52+
#include <threads.h>
53+
#include <time.h>
54+
55+
typedef thrd_t __gthread_t;
56+
typedef tss_t __gthread_key_t;
57+
typedef once_flag __gthread_once_t;
58+
typedef mtx_t __gthread_mutex_t;
59+
typedef mtx_t __gthread_recursive_mutex_t;
60+
typedef cnd_t __gthread_cond_t;
61+
typedef struct timespec __gthread_time_t;
62+
63+
static inline int __gthread_active_p(void)
64+
{
65+
return 1;
66+
}
67+
68+
static inline int
69+
__gthread_create (__gthread_t *__threadid, void *(*__func) (void*),
70+
void *__args)
71+
{
72+
return thrd_create(__threadid, (thrd_start_t)__func, __args) != thrd_success;
73+
}
74+
75+
static inline int
76+
__gthread_join (__gthread_t __threadid, void **__value_ptr)
77+
{
78+
return thrd_join(__threadid, (int *)__value_ptr) != thrd_success;
79+
}
80+
81+
static inline int
82+
__gthread_detach (__gthread_t __threadid)
83+
{
84+
return thrd_detach(__threadid) != thrd_success;
85+
}
86+
87+
static inline int
88+
__gthread_equal (__gthread_t __t1, __gthread_t __t2)
89+
{
90+
return thrd_equal(__t1, __t2);
91+
}
92+
93+
static inline __gthread_t
94+
__gthread_self (void)
95+
{
96+
return thrd_current();
97+
}
98+
99+
static inline int
100+
__gthread_yield (void)
101+
{
102+
(void)thrd_yield();
103+
return 0;
104+
}
105+
106+
static inline int
107+
__gthread_once (__gthread_once_t *__once, void (*__func) (void))
108+
{
109+
call_once(__once, __func);
110+
return 0;
111+
}
112+
113+
static inline int
114+
__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
115+
{
116+
return tss_create(__key, __dtor) != thrd_success;
117+
}
118+
119+
static inline int
120+
__gthread_key_delete (__gthread_key_t __key)
121+
{
122+
tss_delete(__key);
123+
return 0;
124+
}
125+
126+
static inline void *
127+
__gthread_getspecific (__gthread_key_t __key)
128+
{
129+
return tss_get(__key);
130+
}
131+
132+
static inline int
133+
__gthread_setspecific (__gthread_key_t __key, const void *__ptr)
134+
{
135+
return tss_set(__key, (void *)__ptr) != thrd_success;
136+
}
137+
138+
static inline void
139+
__gthread_mutex_init_function (__gthread_mutex_t *__mutex)
140+
{
141+
(void)mtx_init(__mutex, mtx_plain);
142+
}
143+
144+
static inline int
145+
__gthread_mutex_destroy (__gthread_mutex_t *__mutex)
146+
{
147+
mtx_destroy(__mutex);
148+
return 0;
149+
}
150+
151+
static inline int
152+
__gthread_mutex_lock (__gthread_mutex_t *__mutex)
153+
{
154+
return mtx_lock(__mutex) != thrd_success;
155+
}
156+
157+
static inline int
158+
__gthread_mutex_trylock (__gthread_mutex_t *__mutex)
159+
{
160+
return mtx_trylock(__mutex) != thrd_success;
161+
}
162+
163+
static inline int
164+
__gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
165+
const __gthread_time_t *__abs_timeout)
166+
{
167+
return mtx_timedlock(__mutex, __abs_timeout) != thrd_success;
168+
}
169+
170+
static inline int
171+
__gthread_mutex_unlock (__gthread_mutex_t *__mutex)
172+
{
173+
return mtx_unlock(__mutex) != thrd_success;
174+
}
175+
176+
static inline int
177+
__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
178+
{
179+
return mtx_init(__mutex, mtx_recursive) != thrd_success;
180+
}
181+
182+
static inline int
183+
__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
184+
{
185+
return mtx_lock(__mutex) != thrd_success;
186+
}
187+
188+
static inline int
189+
__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
190+
{
191+
return mtx_trylock(__mutex) != thrd_success;
192+
}
193+
194+
static inline int
195+
__gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
196+
const __gthread_time_t *__abs_timeout)
197+
{
198+
return __gthread_mutex_timedlock (__mutex, __abs_timeout);
199+
}
200+
201+
static inline int
202+
__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
203+
{
204+
return __gthread_mutex_unlock (__mutex);
205+
}
206+
207+
static inline int
208+
__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
209+
{
210+
return __gthread_mutex_destroy (__mutex);
211+
}
212+
213+
static inline void
214+
__gthread_cond_init_function (__gthread_cond_t *__cond)
215+
{
216+
(void)cnd_init(__cond);
217+
}
218+
219+
static inline int
220+
__gthread_cond_broadcast (__gthread_cond_t *__cond)
221+
{
222+
return cnd_broadcast(__cond) != thrd_success;
223+
}
224+
225+
static inline int
226+
__gthread_cond_signal (__gthread_cond_t *__cond)
227+
{
228+
return cnd_signal(__cond) != thrd_success;
229+
}
230+
231+
static inline int
232+
__gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
233+
{
234+
return cnd_wait(__cond, __mutex) != thrd_success;
235+
}
236+
237+
static inline int
238+
__gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
239+
const __gthread_time_t *__abs_timeout)
240+
{
241+
return cnd_timedwait(__cond, __mutex, __abs_timeout) != thrd_success;
242+
}
243+
244+
static inline int
245+
__gthread_cond_wait_recursive (__gthread_cond_t *__cond,
246+
__gthread_recursive_mutex_t *__mutex)
247+
{
248+
return __gthread_cond_wait (__cond, __mutex);
249+
}
250+
251+
static inline int
252+
__gthread_cond_destroy (__gthread_cond_t* __cond)
253+
{
254+
cnd_destroy(__cond);
255+
return 0;
256+
}
257+
258+
#endif /* ! _GLIBCXX_GCC_GTHR_C11_H */

libstdc++-v3/configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15764,6 +15764,7 @@ $as_echo "$target_thread_file" >&6; }
1576415764

1576515765
case $target_thread_file in
1576615766
aix) thread_header=config/rs6000/gthr-aix.h ;;
15767+
c11) thread_header=gthr-c11.h ;;
1576715768
dce) thread_header=config/pa/gthr-dce.h ;;
1576815769
gcn) thread_header=config/gcn/gthr-gcn.h ;;
1576915770
lynx) thread_header=config/gthr-lynx.h ;;

libstdc++-v3/include/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ thread_host_headers = \
10121012
${host_builddir}/gthr.h \
10131013
${host_builddir}/gthr-single.h \
10141014
${host_builddir}/gthr-posix.h \
1015+
${host_builddir}/gthr-c11.h \
10151016
${host_builddir}/gthr-default.h
10161017

10171018

@@ -1383,6 +1384,12 @@ ${host_builddir}/gthr-posix.h: ${toplevel_srcdir}/libgcc/gthr-posix.h \
13831384
-e 's/\(${uppercase}*USE_WEAK\)/_GLIBCXX_\1/g' \
13841385
< $< > $@
13851386

1387+
${host_builddir}/gthr-c11.h: ${toplevel_srcdir}/libgcc/gthr-c11.h \
1388+
stamp-${host_alias}
1389+
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
1390+
-e 's/\(GCC${uppercase}*_H\)/_GLIBCXX_\1/g' \
1391+
< $< > $@
1392+
13861393
${host_builddir}/gthr-default.h: ${toplevel_srcdir}/libgcc/${thread_header} \
13871394
stamp-${host_alias}
13881395
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \

libstdc++-v3/include/Makefile.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ thread_host_headers = \
13631363
${host_builddir}/gthr.h \
13641364
${host_builddir}/gthr-single.h \
13651365
${host_builddir}/gthr-posix.h \
1366+
${host_builddir}/gthr-c11.h \
13661367
${host_builddir}/gthr-default.h
13671368

13681369
pch1_source = ${glibcxx_srcdir}/include/precompiled/stdc++.h
@@ -1874,6 +1875,14 @@ ${host_builddir}/gthr-posix.h: ${toplevel_srcdir}/libgcc/gthr-posix.h \
18741875
-e 's/\(${uppercase}*USE_WEAK\)/_GLIBCXX_\1/g' \
18751876
< $< > $@
18761877

1878+
${host_builddir}/gthr-c11.h: ${toplevel_srcdir}/libgcc/gthr-c11.h \
1879+
stamp-${host_alias}
1880+
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
1881+
-e 's/\(GCC${uppercase}*_H\)/_GLIBCXX_\1/g' \
1882+
-e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
1883+
-e 's/\(${uppercase}*USE_WEAK\)/_GLIBCXX_\1/g' \
1884+
< $< > $@
1885+
18771886
${host_builddir}/gthr-default.h: ${toplevel_srcdir}/libgcc/${thread_header} \
18781887
stamp-${host_alias}
18791888
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \

0 commit comments

Comments
 (0)