you just port libgomp to mingw32 + pthreads-win32
and assuming pthreads-win32 is sufficiently rich and not too buggy, it will
just work.
With the attached patch, I can compile libgomp with
../gcc/configure --prefix=/mingw --disable-nls --with-ld=/mingw/bin/ld
--with-as=/mingw/bin/as --disable-werror --enable-bootstrap
--enable-threads=posix --with-win32-nlsapi=unicode
--host=i386-pc-mingw32 --enable-languages=c,fortran --enable-libgomp
and the resulting compiler and generated executables seem to work (I
tried a few C and Fortran toy codes). The main changes are to
libgomp/config/posix/time.c, which used functions not available on
mingw32. Would they be acceptable in this form (protected with #ifdef
_WIN32)? If so, I'll do some more testing, and officially submit the
patch.
FX
Index: libgomp/configure
===================================================================
--- libgomp/configure (revision 114196)
+++ libgomp/configure (working copy)
@@ -8397,7 +8397,9 @@
# Check for functions needed.
-for ac_func in getloadavg clock_gettime
+
+
+for ac_func in getloadavg clock_gettime gettimeofday sysconf
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
Index: libgomp/configure.ac
===================================================================
--- libgomp/configure.ac (revision 114196)
+++ libgomp/configure.ac (working copy)
@@ -162,7 +162,7 @@
[AC_MSG_ERROR([Pthreads are required to build libgomp])])])
# Check for functions needed.
-AC_CHECK_FUNCS(getloadavg clock_gettime)
+AC_CHECK_FUNCS(getloadavg clock_gettime gettimeofday sysconf)
# Check for broken semaphore implementation on darwin.
# sem_init returns: sem_init error: Function not implemented.
Index: libgomp/config.h.in
===================================================================
--- libgomp/config.h.in (revision 114196)
+++ libgomp/config.h.in (working copy)
@@ -18,6 +18,9 @@
/* Define to 1 if you have the `getloadavg' function. */
#undef HAVE_GETLOADAVG
+/* Define to 1 if you have the `gettimeofday' function. */
+#undef HAVE_GETTIMEOFDAY
+
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
@@ -42,6 +45,9 @@
/* Define to 1 if the target supports __sync_*_compare_and_swap */
#undef HAVE_SYNC_BUILTINS
+/* Define to 1 if you have the `sysconf' function. */
+#undef HAVE_SYSCONF
+
/* Define to 1 if you have the <sys/loadavg.h> header file. */
#undef HAVE_SYS_LOADAVG_H
Index: libgomp/config/posix/time.c
===================================================================
--- libgomp/config/posix/time.c (revision 114196)
+++ libgomp/config/posix/time.c (working copy)
@@ -48,32 +48,52 @@
double
omp_get_wtime (void)
{
-#ifdef HAVE_CLOCK_GETTIME
+#ifdef HAVE_GETTIMEOFDAY
+# ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
-# ifdef CLOCK_MONOTONIC
+# ifdef CLOCK_MONOTONIC
if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
-# endif
+# endif
clock_gettime (CLOCK_REALTIME, &ts);
return ts.tv_sec + ts.tv_nsec / 1e9;
-#else
+# else
struct timeval tv;
gettimeofday (&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1e6;
+# endif
+#else
+# ifdef _WIN32
+
+#include <sys/timeb.h>
+ struct _timeb timebuf;
+ _ftime (&timebuf);
+ return (timebuf.time + (long)(timebuf.millitm) / 1e3);
+# else
+# error "Either clock_gettime or gettimeofday are required"
+# endif
#endif
}
double
omp_get_wtick (void)
{
-#ifdef HAVE_CLOCK_GETTIME
+#ifdef HAVE_SYSCONF
+# ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
-# ifdef CLOCK_MONOTONIC
+# ifdef CLOCK_MONOTONIC
if (clock_getres (CLOCK_MONOTONIC, &ts) < 0)
-# endif
+# endif
clock_getres (CLOCK_REALTIME, &ts);
return ts.tv_sec + ts.tv_nsec / 1e9;
+# else
+ return 1.0 / sysconf(_SC_CLK_TCK);
+# endif
#else
- return 1.0 / sysconf(_SC_CLK_TCK);
+# ifdef _WIN32
+ return 1e-3;
+# else
+# error "Either clock_getres or sysconf are required"
+# endif
#endif
}
Index: gcc/config/i386/mingw32.h
===================================================================
--- gcc/config/i386/mingw32.h (revision 114196)
+++ gcc/config/i386/mingw32.h (working copy)
@@ -108,3 +108,8 @@
/* Define as short unsigned for compatibility with MS runtime. */
#undef WINT_TYPE
#define WINT_TYPE "short unsigned int"
+
+/* The mingw32 compiler doesn't know the -pthread option, but requires
+ explicitly linking the libpthread. */
+#undef GOMP_SELF_SPECS
+#define GOMP_SELF_SPECS "-lpthread"