nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From 86f2f767ddffd9f7c6f1470b987ae7b0d251b988 Mon Sep 17 00:00:00 2001
2From: Liu Hao <lh_mouse@126.com>
3Date: Wed, 25 Apr 2018 21:54:19 +0800
4Subject: [PATCH] Added 'mcf' thread model support from mcfgthread.
5
6Signed-off-by: Liu Hao <lh_mouse@126.com>
7---
8 config/gthr.m4 | 1 +
9 gcc/config.gcc | 3 +++
10 gcc/config/i386/mingw-mcfgthread.h | 1 +
11 gcc/config/i386/mingw-w64.h | 2 +-
12 gcc/config/i386/mingw32.h | 11 ++++++++++-
13 gcc/configure | 2 +-
14 gcc/configure.ac | 2 +-
15 libatomic/configure.tgt | 2 +-
16 libgcc/config.host | 6 ++++++
17 libgcc/config/i386/gthr-mcf.h | 1 +
18 libgcc/config/i386/t-mingw-mcfgthread | 2 ++
19 libgcc/configure | 1 +
20 libstdc++-v3/configure | 1 +
21 libstdc++-v3/libsupc++/atexit_thread.cc | 18 ++++++++++++++++++
22 libstdc++-v3/libsupc++/guard.cc | 23 +++++++++++++++++++++++
23 libstdc++-v3/src/c++11/thread.cc | 9 +++++++++
24 16 files changed, 80 insertions(+), 5 deletions(-)
25 create mode 100644 gcc/config/i386/mingw-mcfgthread.h
26 create mode 100644 libgcc/config/i386/gthr-mcf.h
27 create mode 100644 libgcc/config/i386/t-mingw-mcfgthread
28
29diff --git a/config/gthr.m4 b/config/gthr.m4
30index 7b29f1f3327..82e21fe1709 100644
31--- a/config/gthr.m4
32+++ b/config/gthr.m4
33@@ -21,6 +21,7 @@ case $1 in
34 tpf) thread_header=config/s390/gthr-tpf.h ;;
35 vxworks) thread_header=config/gthr-vxworks.h ;;
36 win32) thread_header=config/i386/gthr-win32.h ;;
37+ mcf) thread_header=config/i386/gthr-mcf.h ;;
38 esac
39 AC_SUBST(thread_header)
40 ])
41diff --git a/gcc/config.gcc b/gcc/config.gcc
42index 46a9029acec..112c24e95a3 100644
43--- a/gcc/config.gcc
44+++ b/gcc/config.gcc
45@@ -1758,6 +1758,9 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
46 if test x$enable_threads = xposix ; then
47 tm_file="${tm_file} i386/mingw-pthread.h"
48 fi
49+ if test x$enable_threads = xmcf ; then
50+ tm_file="${tm_file} i386/mingw-mcfgthread.h"
51+ fi
52 tm_file="${tm_file} i386/mingw32.h"
53 # This makes the logic if mingw's or the w64 feature set has to be used
54 case ${target} in
55diff --git a/gcc/config/i386/mingw-mcfgthread.h b/gcc/config/i386/mingw-mcfgthread.h
56new file mode 100644
57index 00000000000..ec381a7798f
58--- /dev/null
59+++ b/gcc/config/i386/mingw-mcfgthread.h
60@@ -0,0 +1 @@
61+#define TARGET_USE_MCFGTHREAD 1
62diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
63index 484dc7a9e9f..a15bbeea500 100644
64--- a/gcc/config/i386/mingw-w64.h
65+++ b/gcc/config/i386/mingw-w64.h
66@@ -48,7 +48,7 @@ along with GCC; see the file COPYING3. If not see
67 "%{mwindows:-lgdi32 -lcomdlg32} " \
68 "%{fvtable-verify=preinit:-lvtv -lpsapi; \
69 fvtable-verify=std:-lvtv -lpsapi} " \
70- "-ladvapi32 -lshell32 -luser32 -lkernel32"
71+ LIB_MCFGTHREAD "-ladvapi32 -lshell32 -luser32 -lkernel32"
72
73 #undef SPEC_32
74 #undef SPEC_64
75diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
76index 0612b87199a..76cea94f3b7 100644
77--- a/gcc/config/i386/mingw32.h
78+++ b/gcc/config/i386/mingw32.h
79@@ -32,6 +32,14 @@ along with GCC; see the file COPYING3. If not see
80 | MASK_STACK_PROBE | MASK_ALIGN_DOUBLE \
81 | MASK_MS_BITFIELD_LAYOUT)
82
83+#ifndef TARGET_USE_MCFGTHREAD
84+#define CPP_MCFGTHREAD() ((void)0)
85+#define LIB_MCFGTHREAD ""
86+#else
87+#define CPP_MCFGTHREAD() (builtin_define("__USING_MCFGTHREAD__"))
88+#define LIB_MCFGTHREAD " -lmcfgthread "
89+#endif
90+
91 /* See i386/crtdll.h for an alternative definition. _INTEGRAL_MAX_BITS
92 is for compatibility with native compiler. */
93 #define EXTRA_OS_CPP_BUILTINS() \
94@@ -50,6 +58,7 @@ along with GCC; see the file COPYING3. If not see
95 builtin_define_std ("WIN64"); \
96 builtin_define ("_WIN64"); \
97 } \
98+ CPP_MCFGTHREAD(); \
99 } \
100 while (0)
101
102@@ -93,7 +102,7 @@ along with GCC; see the file COPYING3. If not see
103 "%{mwindows:-lgdi32 -lcomdlg32} " \
104 "%{fvtable-verify=preinit:-lvtv -lpsapi; \
105 fvtable-verify=std:-lvtv -lpsapi} " \
106- "-ladvapi32 -lshell32 -luser32 -lkernel32"
107+ LIB_MCFGTHREAD "-ladvapi32 -lshell32 -luser32 -lkernel32"
108
109 /* Weak symbols do not get resolved if using a Windows dll import lib.
110 Make the unwind registration references strong undefs. */
111diff --git a/gcc/configure b/gcc/configure
112index 6121e163259..52f0e00efe6 100755
113--- a/gcc/configure
114+++ b/gcc/configure
115@@ -11693,7 +11693,7 @@ case ${enable_threads} in
116 target_thread_file='single'
117 ;;
118 aix | dce | lynx | mipssde | posix | rtems | \
119- single | tpf | vxworks | win32)
120+ single | tpf | vxworks | win32 | mcf)
121 target_thread_file=${enable_threads}
122 ;;
123 *)
124diff --git a/gcc/configure.ac b/gcc/configure.ac
125index b066cc609e1..4ecdba88de7 100644
126--- a/gcc/configure.ac
127+++ b/gcc/configure.ac
128@@ -1612,7 +1612,7 @@ case ${enable_threads} in
129 target_thread_file='single'
130 ;;
131 aix | dce | lynx | mipssde | posix | rtems | \
132- single | tpf | vxworks | win32)
133+ single | tpf | vxworks | win32 | mcf)
134 target_thread_file=${enable_threads}
135 ;;
136 *)
137diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt
138index ea8c34f8c71..23134ad7363 100644
139--- a/libatomic/configure.tgt
140+++ b/libatomic/configure.tgt
141@@ -145,7 +145,7 @@ case "${target}" in
142 *-*-mingw*)
143 # OS support for atomic primitives.
144 case ${target_thread_file} in
145- win32)
146+ win32 | mcf)
147 config_path="${config_path} mingw"
148 ;;
149 posix)
150diff --git a/libgcc/config.host b/libgcc/config.host
151index 11b4acaff55..9fbd38650bd 100644
152--- a/libgcc/config.host
153+++ b/libgcc/config.host
154@@ -737,6 +737,9 @@ i[34567]86-*-mingw*)
155 posix)
156 tmake_file="i386/t-mingw-pthread $tmake_file"
157 ;;
158+ mcf)
159+ tmake_file="i386/t-mingw-mcfgthread $tmake_file"
160+ ;;
161 esac
162 # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h
163 if test x$ac_cv_sjlj_exceptions = xyes; then
164@@ -761,6 +764,9 @@ x86_64-*-mingw*)
165 posix)
166 tmake_file="i386/t-mingw-pthread $tmake_file"
167 ;;
168+ mcf)
169+ tmake_file="i386/t-mingw-mcfgthread $tmake_file"
170+ ;;
171 esac
172 # This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h
173 if test x$ac_cv_sjlj_exceptions = xyes; then
174diff --git a/libgcc/config/i386/gthr-mcf.h b/libgcc/config/i386/gthr-mcf.h
175new file mode 100644
176index 00000000000..5ea2908361f
177--- /dev/null
178+++ b/libgcc/config/i386/gthr-mcf.h
179@@ -0,0 +1 @@
180+#include <mcfgthread/gthread.h>
181diff --git a/libgcc/config/i386/t-mingw-mcfgthread b/libgcc/config/i386/t-mingw-mcfgthread
182new file mode 100644
183index 00000000000..4b9b10e32d6
184--- /dev/null
185+++ b/libgcc/config/i386/t-mingw-mcfgthread
186@@ -0,0 +1,2 @@
187+SHLIB_PTHREAD_CFLAG =
188+SHLIB_PTHREAD_LDFLAG = -lmcfgthread
189diff --git a/libgcc/configure b/libgcc/configure
190index b2f3f870844..eff889dc3b3 100644
191--- a/libgcc/configure
192+++ b/libgcc/configure
193@@ -5451,6 +5451,7 @@ case $target_thread_file in
194 tpf) thread_header=config/s390/gthr-tpf.h ;;
195 vxworks) thread_header=config/gthr-vxworks.h ;;
196 win32) thread_header=config/i386/gthr-win32.h ;;
197+ mcf) thread_header=config/i386/gthr-mcf.h ;;
198 esac
199
200
201diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
202index ba094be6f15..979a5ab9ace 100755
203--- a/libstdc++-v3/configure
204+++ b/libstdc++-v3/configure
205@@ -15187,6 +15187,7 @@ case $target_thread_file in
206 tpf) thread_header=config/s390/gthr-tpf.h ;;
207 vxworks) thread_header=config/gthr-vxworks.h ;;
208 win32) thread_header=config/i386/gthr-win32.h ;;
209+ mcf) thread_header=config/i386/gthr-mcf.h ;;
210 esac
211
212
213diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
214index de920d714c6..665fb74bd6b 100644
215--- a/libstdc++-v3/libsupc++/atexit_thread.cc
216+++ b/libstdc++-v3/libsupc++/atexit_thread.cc
217@@ -25,6 +25,22 @@
218 #include <cstdlib>
219 #include <new>
220 #include "bits/gthr.h"
221+
222+#ifdef __USING_MCFGTHREAD__
223+
224+#include <mcfgthread/gthread.h>
225+namespace __cxxabiv1 {
226+extern "C" int
227+__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
228+ void *obj, void *dso_handle)
229+ _GLIBCXX_NOTHROW
230+{
231+ return ::_MCFCRT_AtThreadExit((void (*)(_MCFCRT_STD intptr_t))dtor, (_MCFCRT_STD intptr_t)obj) ? 0 : -1;
232+ (void)dso_handle;
233+}
234+}
235+#else // __USING_MCFGTHREAD__
236+
237 #ifdef _GLIBCXX_THREAD_ATEXIT_WIN32
238 #define WIN32_LEAN_AND_MEAN
239 #include <windows.h>
240@@ -167,3 +183,5 @@ __cxxabiv1::__cxa_thread_atexit (void (*dtor)(void *), void *obj, void */*dso_ha
241 }
242
243 #endif /* _GLIBCXX_HAVE___CXA_THREAD_ATEXIT_IMPL */
244+
245+#endif // __USING_MCFGTHREAD__
246diff --git a/libstdc++-v3/libsupc++/guard.cc b/libstdc++-v3/libsupc++/guard.cc
247index 3a2ec3ad0d6..8b4cc96199b 100644
248--- a/libstdc++-v3/libsupc++/guard.cc
249+++ b/libstdc++-v3/libsupc++/guard.cc
250@@ -28,6 +28,27 @@
251 #include <cxxabi.h>
252 #include <exception>
253 #include <new>
254+
255+#ifdef __USING_MCFGTHREAD__
256+
257+#include <mcfgthread/gthread.h>
258+
259+namespace __cxxabiv1 {
260+
261+extern "C" int __cxa_guard_acquire(__guard *g){
262+ return ::_MCFCRT_WaitForOnceFlagForever((::_MCFCRT_OnceFlag *)g) == ::_MCFCRT_kOnceResultInitial;
263+}
264+extern "C" void __cxa_guard_abort(__guard *g) throw() {
265+ ::_MCFCRT_SignalOnceFlagAsAborted((::_MCFCRT_OnceFlag *)g);
266+}
267+extern "C" void __cxa_guard_release(__guard *g) throw() {
268+ ::_MCFCRT_SignalOnceFlagAsFinished((::_MCFCRT_OnceFlag *)g);
269+}
270+
271+}
272+
273+#else // __USING_MCFGTHREAD__
274+
275 #include <ext/atomicity.h>
276 #include <ext/concurrence.h>
277 #include <bits/atomic_lockfree_defines.h>
278@@ -425,3 +446,5 @@ namespace __cxxabiv1
279 #endif
280 }
281 }
282+
283+#endif
284diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
285index 8238817c2e9..0c6a1f85f6f 100644
286--- a/libstdc++-v3/src/c++11/thread.cc
287+++ b/libstdc++-v3/src/c++11/thread.cc
288@@ -55,6 +55,15 @@ static inline int get_nprocs()
289 #elif defined(_GLIBCXX_USE_SC_NPROC_ONLN)
290 # include <unistd.h>
291 # define _GLIBCXX_NPROCS sysconf(_SC_NPROC_ONLN)
292+#elif defined(_WIN32)
293+# include <windows.h>
294+static inline int get_nprocs()
295+{
296+ SYSTEM_INFO sysinfo;
297+ GetSystemInfo(&sysinfo);
298+ return (int)sysinfo.dwNumberOfProcessors;
299+}
300+# define _GLIBCXX_NPROCS get_nprocs()
301 #else
302 # define _GLIBCXX_NPROCS 0
303 #endif
304--
3052.17.0
306