This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gfortran] patch for mingw
- From: FX Coudert <fxcoudert at gmail dot com>
- To: Paul Brook <paul at codesourcery dot com>
- Cc: fortran at gcc dot gnu dot org, patch <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 10 Sep 2005 13:05:50 +0200
- Subject: Re: [gfortran] patch for mingw
- References: <43220979.7060408@gmail.com> <200509100116.02044.paul@codesourcery.com>
Attached patch adds the Windows version of cpu_time, conditionnal on
__MINGW32__. Danny Smith said the patch was (except the part i fixed) OK
for him: as a mingw maintainer, can his approval be enough for such
patches (I will probably submit a few mingw-specific patches for
libgfortran in the next few days) provided that I did regtest on linux
and mingw? Or do I need explicit approval under the usual gfortran rules?
FX
2005-09-10 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* intrinsics/cpu_time.c (__cpu_time_1): Provide a MS Windows
version.
Index: libgfortran/intrinsics/cpu_time.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/cpu_time.c,v
retrieving revision 1.6
diff -u -3 -p -r1.6 cpu_time.c
--- libgfortran/intrinsics/cpu_time.c 17 Aug 2005 02:48:51 -0000 1.6
+++ libgfortran/intrinsics/cpu_time.c 10 Sep 2005 11:00:55 -0000
@@ -88,6 +88,44 @@ static inline void __cpu_time_1 (long *,
/* Helper function for the actual implementation of the CPU_TIME
intrnsic. Returns a CPU time in microseconds or -1 if no CPU time
could be computed. */
+
+#ifdef __MINGW32__
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+static void
+__cpu_time_1 (long *sec, long *usec)
+{
+ union {
+ FILETIME ft;
+ unsigned long long ulltime;
+ } kernel_time, user_time;
+
+ FILETIME unused1, unused2;
+ unsigned long long total_time;
+
+ /* No support for Win9x. The high order bit of the DWORD
+ returned by GetVersion is 0 for NT and higher. */
+ if (GetVersion () >= 0x80000000)
+ {
+ *sec = -1;
+ *usec = 0;
+ return;
+ }
+
+ /* The FILETIME structs filled in by GetProcessTimes represent
+ time in 100 nanosecond units. */
+ GetProcessTimes (GetCurrentProcess (), &unused1, &unused2,
+ &kernel_time.ft, &user_time.ft);
+
+ total_time = (kernel_time.ulltime + user_time.ulltime)/10;
+ *sec = total_time / 1000000;
+ *usec = total_time % 1000000;
+}
+
+#else
+
static inline void
__cpu_time_1 (long *sec, long *usec)
{
@@ -110,6 +148,8 @@ __cpu_time_1 (long *sec, long *usec)
#endif /* HAVE_GETRUSAGE */
}
+#endif
+
extern void cpu_time_4 (GFC_REAL_4 *);
iexport_proto(cpu_time_4);