diff options
author | Francois-Xavier Coudert <coudert@clipper.ens.fr> | 2005-09-24 10:39:35 +0200 |
---|---|---|
committer | François-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2005-09-24 08:39:35 +0000 |
commit | 399a39c720380bb2c7403a572027e3fd889a8da4 (patch) | |
tree | fc7f442daf92d26a16b48078ac129f9ef8ddb4b8 /libgfortran/intrinsics | |
parent | 46919f9ce37de6d0c8779b8160300698b1e56591 (diff) | |
download | gcc-399a39c720380bb2c7403a572027e3fd889a8da4.tar.gz |
re PR libfortran/23380 ([mingw32] cpu_time intrinsic malfunction)
PR libfortran/23380
* intrinsics/cpu_time.c (__cpu_time_1): Provide a MS Windows
version.
From-SVN: r104598
Diffstat (limited to 'libgfortran/intrinsics')
-rw-r--r-- | libgfortran/intrinsics/cpu_time.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libgfortran/intrinsics/cpu_time.c b/libgfortran/intrinsics/cpu_time.c index 4d9525a2adb..8469a4381aa 100644 --- a/libgfortran/intrinsics/cpu_time.c +++ b/libgfortran/intrinsics/cpu_time.c @@ -88,6 +88,44 @@ static inline void __cpu_time_1 (long *, long *) ATTRIBUTE_ALWAYS_INLINE; /* 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); |