From 7d538284642073f7297eee9841453d1860d1edf8 Mon Sep 17 00:00:00 2001
From: lhmouse <lh_mouse@126.com>
Date: Mon, 18 Apr 2016 11:50:55 +0800
Subject: [PATCH] Added 'mcf' thread model support from mcfgthread.

---
 config/gthr.m4                        | 1 +
 gcc/config.gcc                        | 3 +++
 gcc/config/i386/mingw-mcfgthread.h    | 1 +
 gcc/config/i386/mingw-w64.h           | 2 +-
 gcc/config/i386/mingw32.h             | 8 +++++++-
 gcc/configure                         | 2 +-
 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 | 2 ++
 libgcc/configure                      | 1 +
 libstdc++-v3/configure                | 1 +
 13 files changed, 27 insertions(+), 5 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 7b29f1f..82e21fe 100644
--- a/config/gthr.m4
+++ b/config/gthr.m4
@@ -21,6 +21,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 4638567..dc64b09 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1660,6 +1660,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 0000000..ec381a7
--- /dev/null
+++ b/gcc/config/i386/mingw-mcfgthread.h
@@ -0,0 +1 @@
+#define TARGET_USE_MCFGTHREAD 1
diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index 578a7b7c..ca6f02b 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -48,7 +48,7 @@ along with GCC; see the file COPYING3.  If not see
 		 "%{mwindows:-lgdi32 -lcomdlg32} " \
      "%{fvtable-verify=preinit:-lvtv -lpsapi; \
         fvtable-verify=std:-lvtv -lpsapi} " \
-		 "-ladvapi32 -lshell32 -luser32 -lkernel32"
+		 LIB_MCFGTHREAD "-ladvapi32 -lshell32 -luser32 -lkernel32"
 
 #undef SPEC_32
 #undef SPEC_64
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index ca73137..c374529 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -61,6 +61,12 @@ along with GCC; see the file COPYING3.  If not see
 #define SPEC_PTHREAD2 "pthread"
 #endif
 
+#ifndef TARGET_USE_MCFGTHREAD
+#define LIB_MCFGTHREAD ""
+#else
+#define LIB_MCFGTHREAD " -lmcfgthread "
+#endif
+
 #undef SUB_LINK_ENTRY32
 #undef SUB_LINK_ENTRY64
 #define SUB_LINK_ENTRY32 "-e _DllMainCRTStartup@12"
@@ -93,7 +99,7 @@ along with GCC; see the file COPYING3.  If not see
 		 "%{mwindows:-lgdi32 -lcomdlg32} " \
      "%{fvtable-verify=preinit:-lvtv -lpsapi; \
         fvtable-verify=std:-lvtv -lpsapi} " \
-                 "-ladvapi32 -lshell32 -luser32 -lkernel32"
+                 LIB_MCFGTHREAD "-ladvapi32 -lshell32 -luser32 -lkernel32"
 
 /* Weak symbols do not get resolved if using a Windows dll import lib.
    Make the unwind registration references strong undefs.  */
diff --git a/gcc/configure b/gcc/configure
index 3c92795..668c7ae 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -11415,7 +11415,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/gcc/configure.ac b/gcc/configure.ac
index d414081..a960a21 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1535,7 +1535,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 3c1fedd..de6ab45 100644
--- a/libatomic/configure.tgt
+++ b/libatomic/configure.tgt
@@ -120,7 +120,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 4329891..0af7180 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -682,6 +682,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$enable_sjlj_exceptions = xyes; then
@@ -706,6 +709,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$enable_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 0000000..7b4951f
--- /dev/null
+++ b/libgcc/config/i386/gthr-mcf.h
@@ -0,0 +1 @@
+#include <mcfgthread/env/gthread.h>
diff --git a/libgcc/config/i386/t-mingw-mcfgthread b/libgcc/config/i386/t-mingw-mcfgthread
new file mode 100644
index 0000000..4b9b10e
--- /dev/null
+++ b/libgcc/config/i386/t-mingw-mcfgthread
@@ -0,0 +1,2 @@
+SHLIB_PTHREAD_CFLAG =
+SHLIB_PTHREAD_LDFLAG = -lmcfgthread
diff --git a/libgcc/configure b/libgcc/configure
index 203d384..a322158 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -5060,6 +5060,7 @@ case $target_thread_file 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
 
 
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 8cd4c76..d048d5c 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -15265,6 +15265,7 @@ case $target_thread_file 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
 
 
-- 
2.8.1

