This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran] patch for mingw


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);
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]