diff --git a/runtime/flang/dtime3f.c b/runtime/flang/dtime3f.c index b1433772cea..2745e1aa1f9 100644 --- a/runtime/flang/dtime3f.c +++ b/runtime/flang/dtime3f.c @@ -31,11 +31,15 @@ #include #include -#ifndef CLK_TCK -#define CLK_TCK sysconf(_SC_CLK_TCK) +#ifdef _WIN32 + #include "times_win32.h" + #define CLK_TCK 10000000.0 +#else + #ifndef CLK_TCK + #define CLK_TCK sysconf(_SC_CLK_TCK) + #endif #endif -#ifndef _WIN32 static clock_t accum_user = 0, accum_sys = 0; float ENT3F(DTIME, dtime)(float *tarray) @@ -50,33 +54,5 @@ float ENT3F(DTIME, dtime)(float *tarray) accum_sys = b.tms_stime; return (tarray[0] + tarray[1]); } -#else -#include -static FILETIME accum_user; -static FILETIME accum_sys; - -float convert_filetime( const FILETIME *ac_FileTime ) -{ - ULARGE_INTEGER lv_Large ; - - lv_Large.LowPart = ac_FileTime->dwLowDateTime ; - lv_Large.HighPart = ac_FileTime->dwHighDateTime ; - - return (float)lv_Large.QuadPart ; -} -float ENT3F(DTIME, dtime)(float *tarray) -{ - - FILETIME time_create; - FILETIME time_exit; - - GetProcessTimes( GetCurrentProcess(), - &time_create, &time_exit, &accum_sys, &accum_user ); - - tarray[0] = ((float)(convert_filetime(&accum_user))); - tarray[1] = ((float)(convert_filetime(&accum_sys))); - return (tarray[0] + tarray[1]); -} -#endif diff --git a/runtime/flang/etime3f.c b/runtime/flang/etime3f.c index cb8b6cc2ebd..e0931ee10e7 100644 --- a/runtime/flang/etime3f.c +++ b/runtime/flang/etime3f.c @@ -33,11 +33,16 @@ #include #include -#ifndef CLK_TCK -#define CLK_TCK sysconf(_SC_CLK_TCK) + +#ifdef _WIN32 + #include "times_win32.h" + #define CLK_TCK 10000000.0 +#else + #ifndef CLK_TCK + #define CLK_TCK sysconf(_SC_CLK_TCK) + #endif #endif -#ifndef _WIN32 float ENT3F(ETIME, etime)(float *tarray) { struct tms b; @@ -49,21 +54,3 @@ float ENT3F(ETIME, etime)(float *tarray) return (tarray[0] + tarray[1]); } -#else -#include - -float ENT3F(ETIME, etime)(float *tarray) -{ - FILETIME accum_user; - FILETIME accum_sys; - FILETIME time_create; - FILETIME time_exit; - - GetProcessTimes( GetCurrentProcess(), - &time_create, &time_exit, &accum_sys, &accum_user ); - - tarray[0] = ((float)(convert_filetime(&accum_user))); - tarray[1] = ((float)(convert_filetime(&accum_sys))); - return (tarray[0] + tarray[1]); -} -#endif diff --git a/runtime/flang/util.c b/runtime/flang/util.c index 7435d0533d2..8d122523475 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -331,3 +331,30 @@ void __fort_ftnstrcpy(char *dst, /* destination string, blank-filled */ *dst++ = ' '; } + +#ifdef _WIN32 +#include "times_win32.h" + +clock_t convert_filetime( const FILETIME *ac_FileTime ) +{ + ULARGE_INTEGER lv_Large ; + + lv_Large.LowPart = ac_FileTime->dwLowDateTime ; + lv_Large.HighPart = ac_FileTime->dwHighDateTime ; + + return (clock_t)lv_Large.QuadPart ; +} + +/* + Thin emulation of the unix times function +*/ +void times(tms *time_struct) { + FILETIME time_create, time_exit, accum_sys, accum_user; + + GetProcessTimes( GetCurrentProcess(), + &time_create, &time_exit, &accum_sys, &accum_user ); + + time_struct->tms_utime = convert_filetime(&accum_user); + time_struct->tms_stime = convert_filetime(&accum_sys); +} +#endif diff --git a/runtime/include/times_win32.h b/runtime/include/times_win32.h new file mode 100644 index 00000000000..4c76ee6e24e --- /dev/null +++ b/runtime/include/times_win32.h @@ -0,0 +1,20 @@ +#ifndef _FLANG_TIMES_WIN32 +#define _FLANG_TIMES_WIN32 + #include + + typedef __int64 clock_t; + + typedef struct tms { + clock_t tms_utime; /* user time */ + clock_t tms_stime; /* system time */ + clock_t tms_cutime; /* user time of children */ + clock_t tms_cstime; /* system time of children */ + } tms; + + clock_t convert_filetime( const FILETIME *ac_FileTime ); + + /* + Thin emulation of the unix times function + */ + void times(tms *time_struct); +#endif