From: LIU Hao <lh_mouse@126.com>
To: gcc-patches@gcc.gnu.org
Cc: 10walls@gmail.com
Subject: Re: Adding a new thread model to GCC
Date: Tue, 4 Oct 2022 20:44:45 +0800 [thread overview]
Message-ID: <fa1858ac-23b2-673c-5ab7-d6ee2389fb4b@126.com> (raw)
In-Reply-To: <0F33BB41-41EC-4068-84F1-9AD6DCCF190A@gmail.com>
[-- Attachment #1.1.1: Type: text/plain, Size: 828 bytes --]
Attached are revised patches. These are exported from trunk.
There is a change since my last message:
* A new Makefile variable `SHLIB_MCFGTHREAD_LIBS` has been introduced, to keep
the other thread models from being affected.
After applying these patches, configure scripts in these subdirectories need to be regenerated:
* gcc
* libgcc
* libatomic
* libstdc++-v3
The patch for libgfortran fixes
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105764
I have successfully bootstrapped GCC 12 with these patches, on i686-w64-mingw32 (with MSVCRT) and
x86_64-w64-mingw32 (with MSVCRT and UCRT). No errors have been observed so far.
Once these patches land in GCC, we can start the work in mingw-w64 basing on `__USING_MCFGTHREAD__`.
--
Best regards,
LIU Hao
[-- Attachment #1.1.2: 0001-libgfortran-Use-__gthread_t-instead-of-pthread_t.patch --]
[-- Type: text/plain, Size: 970 bytes --]
From e1ab15fc95ac8180156feed410cacb64a41a9567 Mon Sep 17 00:00:00 2001
From: LIU Hao <lh_mouse@126.com>
Date: Fri, 27 May 2022 23:12:48 +0800
Subject: [PATCH 1/3] libgfortran: Use `__gthread_t` instead of `pthread_t`
It used to cause errors if a thread model other than `posix` was selected,
which looks like a leftover from a79878585a1c5e32bafbc6d1e73f91fd6e4293bf.
libgfortran/ChangeLog:
* io/async.h (struct async_unit): Use `__gthread_t` instead
of `pthread_t`.
---
libgfortran/io/async.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libgfortran/io/async.h b/libgfortran/io/async.h
index efd542a45e82..d57722a95e44 100644
--- a/libgfortran/io/async.h
+++ b/libgfortran/io/async.h
@@ -351,7 +351,7 @@ typedef struct async_unit
struct adv_cond work;
struct adv_cond emptysignal;
struct st_parameter_dt *pdt;
- pthread_t thread;
+ __gthread_t thread;
struct transfer_queue *head;
struct transfer_queue *tail;
--
2.37.3
[-- Attachment #1.1.3: 0002-libstdc-thread-Implement-_GLIBCXX_NPROCS-for-Windows.patch --]
[-- Type: text/plain, Size: 1167 bytes --]
From 0376949aae74b92a7ba327881672e038c3c0d825 Mon Sep 17 00:00:00 2001
From: LIU Hao <lh_mouse@126.com>
Date: Sun, 2 Oct 2022 00:57:08 +0800
Subject: [PATCH 2/3] libstdc++/thread: Implement `_GLIBCXX_NPROCS` for Windows
This makes `std::thread::hardware_concurrency()` return the number of
logical processors, instead of zero.
libstdc++-v3/ChangeLog:
* src/c++11/thread.cc (get_nprocs): Add new implementation
for native Windows targets
---
libstdc++-v3/src/c++11/thread.cc | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libstdc++-v3/src/c++11/thread.cc b/libstdc++-v3/src/c++11/thread.cc
index 707a4ad415b9..b39d9f4a9e29 100644
--- a/libstdc++-v3/src/c++11/thread.cc
+++ b/libstdc++-v3/src/c++11/thread.cc
@@ -68,6 +68,15 @@ static inline int get_nprocs()
#elif defined(_GLIBCXX_USE_SC_NPROC_ONLN)
# include <unistd.h>
# define _GLIBCXX_NPROCS sysconf(_SC_NPROC_ONLN)
+#elif defined(_WIN32)
+# include <windows.h>
+static inline int get_nprocs()
+{
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+ return (int)sysinfo.dwNumberOfProcessors;
+}
+# define _GLIBCXX_NPROCS get_nprocs()
#else
# define _GLIBCXX_NPROCS 0
#endif
--
2.37.3
[-- Attachment #1.1.4: 0003-gcc-Add-mcf-thread-model-support-from-mcfgthread.patch --]
[-- Type: text/plain, Size: 9629 bytes --]
From d69cbaca07cd7b0e2d725574c8d5913b1c5e0bd5 Mon Sep 17 00:00:00 2001
From: LIU Hao <lh_mouse@126.com>
Date: Sat, 16 Apr 2022 00:46:23 +0800
Subject: [PATCH 3/3] gcc: Add 'mcf' thread model support from mcfgthread
This patch adds the new thread model `mcf`, which implements mutexes
and condition variables with the mcfgthread library.
Source code for mcfgthread is available at <https://github.com/lhmouse/mcfgthread>.
config/ChangeLog:
* gthr.m4 (GCC_AC_THREAD_HEADER): Add new case for `mcf` thread
model
gcc/config/ChangeLog:
* i386/mingw-mcfgthread.h: New file
* i386/mingw32.h: Add builtin macro and default libraries for
mcfgthread when thread model is `mcf`
gcc/ChangeLog:
* config.gcc: Include 'i386/mingw-mcfgthread.h' when thread model
is `mcf`
* configure.ac: Recognize `mcf` as a valid thread model
libatomic/ChangeLog:
* configure.tgt: Add new case for `mcf` thread model
libgcc/ChangeLog:
* config.host: Add new cases for `mcf` thread model
* config/i386/gthr-mcf.h: New file
* config/i386/t-mingw-mcfgthread: New file
* config/i386/t-slibgcc-cygming: Add mcfgthread for libgcc DLL
libstdc++-v3/ChangeLog:
* libsupc++/atexit_thread.cc (__cxa_thread_atexit): Use
implementation from mcfgthread if available
* libsupc++/guard.cc (__cxa_guard_acquire, __cxa_guard_release,
__cxa_guard_abort): Use implementations from mcfgthread if
available
---
config/gthr.m4 | 1 +
gcc/config.gcc | 3 +++
gcc/config/i386/mingw-mcfgthread.h | 1 +
gcc/config/i386/mingw32.h | 11 ++++++++-
gcc/configure.ac | 2 +-
libatomic/configure.tgt | 2 +-
libgcc/config.host | 6 +++++
libgcc/config/i386/gthr-mcf.h | 1 +
libgcc/config/i386/t-mingw-mcfgthread | 1 +
libgcc/config/i386/t-slibgcc-cygming | 6 ++++-
libstdc++-v3/libsupc++/atexit_thread.cc | 20 ++++++++++++++++
libstdc++-v3/libsupc++/guard.cc | 31 +++++++++++++++++++++++++
12 files changed, 81 insertions(+), 4 deletions(-)
create mode 100644 gcc/config/i386/mingw-mcfgthread.h
create mode 100644 libgcc/config/i386/gthr-mcf.h
create mode 100644 libgcc/config/i386/t-mingw-mcfgthread
diff --git a/config/gthr.m4 b/config/gthr.m4
index 4b937306ad08..11996247f150 100644
--- a/config/gthr.m4
+++ b/config/gthr.m4
@@ -22,6 +22,7 @@ case $1 in
tpf) thread_header=config/s390/gthr-tpf.h ;;
vxworks) thread_header=config/gthr-vxworks.h ;;
win32) thread_header=config/i386/gthr-win32.h ;;
+ mcf) thread_header=config/i386/gthr-mcf.h ;;
esac
AC_SUBST(thread_header)
])
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 35dfc00fe4d9..d82396f50309 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2090,6 +2090,9 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
if test x$enable_threads = xposix ; then
tm_file="${tm_file} i386/mingw-pthread.h"
fi
+ if test x$enable_threads = xmcf ; then
+ tm_file="${tm_file} i386/mingw-mcfgthread.h"
+ fi
tm_file="${tm_file} i386/mingw32.h"
# This makes the logic if mingw's or the w64 feature set has to be used
case ${target} in
diff --git a/gcc/config/i386/mingw-mcfgthread.h b/gcc/config/i386/mingw-mcfgthread.h
new file mode 100644
index 000000000000..ec381a7798f1
--- /dev/null
+++ b/gcc/config/i386/mingw-mcfgthread.h
@@ -0,0 +1 @@
+#define TARGET_USE_MCFGTHREAD 1
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index d3ca0cd0279d..307a803b92c2 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -32,6 +32,14 @@ along with GCC; see the file COPYING3. If not see
| MASK_STACK_PROBE | MASK_ALIGN_DOUBLE \
| MASK_MS_BITFIELD_LAYOUT)
+#ifndef TARGET_USE_MCFGTHREAD
+#define CPP_MCFGTHREAD() ((void)0)
+#define LIB_MCFGTHREAD ""
+#else
+#define CPP_MCFGTHREAD() (builtin_define("__USING_MCFGTHREAD__"))
+#define LIB_MCFGTHREAD " -lmcfgthread "
+#endif
+
/* See i386/crtdll.h for an alternative definition. _INTEGRAL_MAX_BITS
is for compatibility with native compiler. */
#define EXTRA_OS_CPP_BUILTINS() \
@@ -50,6 +58,7 @@ along with GCC; see the file COPYING3. If not see
builtin_define_std ("WIN64"); \
builtin_define ("_WIN64"); \
} \
+ CPP_MCFGTHREAD(); \
} \
while (0)
@@ -185,7 +194,7 @@ along with GCC; see the file COPYING3. If not see
#define REAL_LIBGCC_SPEC \
"%{mthreads:-lmingwthrd} -lmingw32 \
" SHARED_LIBGCC_SPEC " \
- -lmoldname -lmingwex -lmsvcrt -lkernel32"
+ -lmoldname -lmingwex -lmsvcrt " LIB_MCFGTHREAD " -lkernel32 -lntdll"
#undef STARTFILE_SPEC
#define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
diff --git a/gcc/configure.ac b/gcc/configure.ac
index b6bafa8b7d69..0641b8a61dae 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1991,7 +1991,7 @@ case ${enable_threads} in
target_thread_file='single'
;;
aix | dce | lynx | mipssde | posix | rtems | \
- single | tpf | vxworks | win32)
+ single | tpf | vxworks | win32 | mcf)
target_thread_file=${enable_threads}
;;
*)
diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt
index 33f8c91ce771..86a59475b6e7 100644
--- a/libatomic/configure.tgt
+++ b/libatomic/configure.tgt
@@ -159,7 +159,7 @@ case "${target}" in
*-*-mingw*)
# OS support for atomic primitives.
case ${target_thread_file} in
- win32)
+ win32 | mcf)
config_path="${config_path} mingw"
;;
posix)
diff --git a/libgcc/config.host b/libgcc/config.host
index 9dcc2538dc86..44a8218a31d3 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -825,6 +825,9 @@ i[34567]86-*-mingw*)
posix)
tmake_file="i386/t-mingw-pthread $tmake_file"
;;
+ mcf)
+ tmake_file="i386/t-mingw-mcfgthread $tmake_file"
+ ;;
esac
# This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h
if test x$ac_cv_sjlj_exceptions = xyes; then
@@ -849,6 +852,9 @@ x86_64-*-mingw*)
posix)
tmake_file="i386/t-mingw-pthread $tmake_file"
;;
+ mcf)
+ tmake_file="i386/t-mingw-mcfgthread $tmake_file"
+ ;;
esac
# This has to match the logic for DWARF2_UNWIND_INFO in gcc/config/i386/cygming.h
if test x$ac_cv_sjlj_exceptions = xyes; then
diff --git a/libgcc/config/i386/gthr-mcf.h b/libgcc/config/i386/gthr-mcf.h
new file mode 100644
index 000000000000..58131bb7ca92
--- /dev/null
+++ b/libgcc/config/i386/gthr-mcf.h
@@ -0,0 +1 @@
+#include <mcfgthread/gthr.h>
diff --git a/libgcc/config/i386/t-mingw-mcfgthread b/libgcc/config/i386/t-mingw-mcfgthread
new file mode 100644
index 000000000000..c5b817f09b71
--- /dev/null
+++ b/libgcc/config/i386/t-mingw-mcfgthread
@@ -0,0 +1 @@
+SHLIB_MCFGTHREAD_LIBS = -lmcfgthread -lkernel32 -lntdll
diff --git a/libgcc/config/i386/t-slibgcc-cygming b/libgcc/config/i386/t-slibgcc-cygming
index 6236c78e4668..6871498cf60e 100644
--- a/libgcc/config/i386/t-slibgcc-cygming
+++ b/libgcc/config/i386/t-slibgcc-cygming
@@ -27,6 +27,9 @@ endif
ifndef SHLIB_PTHREAD_LDFLAG
SHLIB_PTHREAD_LDFLAG =
endif
+ifndef SHLIB_MCFGTHREAD_LIBS
+SHLIB_MCFGTHREAD_LIBS =
+endif
SHLIB_LINK = $(LN_S) -f $(SHLIB_MAP) $(SHLIB_MAP).def && \
if [ ! -d $(SHLIB_DIR) ]; then \
@@ -37,7 +40,8 @@ SHLIB_LINK = $(LN_S) -f $(SHLIB_MAP) $(SHLIB_MAP).def && \
$(SHLIB_MAP).def \
-Wl,--out-implib,$(SHLIB_DIR)/$(SHLIB_IMPLIB).tmp \
-o $(SHLIB_DIR)/$(SHLIB_SONAME).tmp @multilib_flags@ \
- $(SHLIB_OBJS) ${SHLIB_PTHREAD_LDFLAG} $(SHLIB_LC) && \
+ $(SHLIB_OBJS) ${SHLIB_PTHREAD_LDFLAG} $(SHLIB_LC) \
+ $(SHLIB_MCFGTHREAD_LIBS) && \
if [ -f $(SHLIB_DIR)/$(SHLIB_SONAME) ]; then \
mv -f $(SHLIB_DIR)/$(SHLIB_SONAME) \
$(SHLIB_DIR)/$(SHLIB_SONAME).backup; \
diff --git a/libstdc++-v3/libsupc++/atexit_thread.cc b/libstdc++-v3/libsupc++/atexit_thread.cc
index a2693d0424e1..2f936ab02ce2 100644
--- a/libstdc++-v3/libsupc++/atexit_thread.cc
+++ b/libstdc++-v3/libsupc++/atexit_thread.cc
@@ -25,6 +25,24 @@
#include <cstdlib>
#include <new>
#include "bits/gthr.h"
+
+#ifdef __USING_MCFGTHREAD__
+
+#include <mcfgthread/cxa.h>
+
+namespace __cxxabiv1 {
+
+extern "C" int
+__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
+ void *obj, void *dso_handle) _GLIBCXX_NOTHROW
+{
+ return __MCF_cxa_thread_atexit (dtor, obj, dso_handle);
+}
+
+} // namespace __cxxabiv1
+
+#else // __USING_MCFGTHREAD__
+
#ifdef _GLIBCXX_THREAD_ATEXIT_WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -173,3 +191,5 @@ __cxxabiv1::__cxa_thread_atexit (void (_GLIBCXX_CDTOR_CALLABI *dtor)(void *),
}
#endif /* _GLIBCXX_HAVE___CXA_THREAD_ATEXIT_IMPL */
+
+#endif // __USING_MCFGTHREAD__
diff --git a/libstdc++-v3/libsupc++/guard.cc b/libstdc++-v3/libsupc++/guard.cc
index abb57117cdfd..0f81a22c6845 100644
--- a/libstdc++-v3/libsupc++/guard.cc
+++ b/libstdc++-v3/libsupc++/guard.cc
@@ -28,6 +28,35 @@
#include <cxxabi.h>
#include <exception>
#include <new>
+
+#ifdef __USING_MCFGTHREAD__
+
+#include <mcfgthread/cxa.h>
+
+namespace __cxxabiv1 {
+
+extern "C" int
+__cxa_guard_acquire (__guard* g) _GLIBCXX_NOTHROW
+ {
+ return __MCF_cxa_guard_acquire(g);
+ }
+
+extern "C" void
+__cxa_guard_release (__guard* g) _GLIBCXX_NOTHROW
+ {
+ __MCF_cxa_guard_release(g);
+ }
+
+extern "C" void
+__cxa_guard_abort (__guard* g) _GLIBCXX_NOTHROW
+ {
+ __MCF_cxa_guard_abort(g);
+ }
+
+} // namespace __cxxabiv1
+
+#else // __USING_MCFGTHREAD__
+
#include <ext/atomicity.h>
#include <ext/concurrence.h>
#include <bits/atomic_lockfree_defines.h>
@@ -458,3 +487,5 @@ namespace __cxxabiv1
#endif
}
}
+
+#endif // __USING_MCFGTHREAD__
--
2.37.3
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2022-10-04 12:44 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-01 18:34 LIU Hao
2022-10-01 20:02 ` Bernhard Reutner-Fischer
2022-10-02 12:54 ` LIU Hao
2022-10-03 5:03 ` Bernhard Reutner-Fischer
2022-10-04 8:06 ` LIU Hao
2022-10-04 19:45 ` Bernhard Reutner-Fischer
2022-10-04 12:44 ` LIU Hao [this message]
2022-10-04 13:13 ` Xi Ruoyao
2022-10-04 13:45 ` LIU Hao
2022-10-05 1:23 ` Xi Ruoyao
2022-10-10 15:56 ` LIU Hao
2022-10-11 13:22 ` LIU Hao
2022-10-14 9:39 ` Jonathan Yong
2022-10-19 13:55 ` Jonathan Yong
2022-10-19 19:53 ` Bernhard Reutner-Fischer
2022-10-20 1:25 ` LIU Hao
2022-10-21 9:58 ` Jonathan Wakely
2022-10-21 10:09 ` i.nixman
2022-10-21 10:48 ` Jonathan Wakely
2022-10-21 10:55 ` i.nixman
2022-10-21 11:36 ` LIU Hao
2022-10-21 11:54 ` i.nixman
2022-10-21 12:19 ` LIU Hao
2022-10-21 12:34 ` i.nixman
2022-10-24 3:40 ` LIU Hao
2022-10-24 20:50 ` Jacek Caban
2022-10-21 12:13 ` Jacek Caban
2022-10-21 12:29 ` LIU Hao
2022-10-21 12:40 ` Jacek Caban
2022-10-21 11:44 ` Eric Botcazou
2022-10-21 11:55 ` i.nixman
2022-10-21 12:30 ` Jacek Caban
2022-10-23 0:36 ` NightStrike
2022-10-24 6:53 ` i.nixman
2022-10-24 8:15 ` Eric Botcazou
2022-10-24 8:20 ` i.nixman
2022-10-31 9:18 ` Eric Botcazou
2022-10-31 15:22 ` i.nixman
2022-12-18 11:14 ` Jonathan Yong
2022-11-01 5:22 ` i.nixman
2022-11-01 9:09 ` Eric Botcazou
2022-11-02 12:05 ` i.nixman
2022-11-02 21:27 ` Eric Botcazou
2022-11-02 21:40 ` i.nixman
2022-12-16 17:18 ` Jonathan Wakely
2022-12-16 19:20 ` Eric Botcazou
2022-12-22 12:21 ` Jonathan Yong
2022-12-22 12:28 ` i.nixman
2022-12-23 23:59 ` Jonathan Yong
2022-12-24 5:58 ` NightStrike
2022-12-24 6:27 ` i.nixman
2022-12-24 13:50 ` i.nixman
2022-12-24 15:42 ` i.nixman
2022-12-24 15:57 ` i.nixman
2022-12-24 21:22 ` i.nixman
2022-12-25 1:10 ` Jonathan Yong
2023-01-09 21:56 ` Eric Botcazou
2022-12-24 6:22 ` i.nixman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fa1858ac-23b2-673c-5ab7-d6ee2389fb4b@126.com \
--to=lh_mouse@126.com \
--cc=10walls@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).