Skip to content

Commit b64e602

Browse files
authored
Merge pull request #30 from isuruf/filetime
[runtime/util] implement filetime_to_int64
2 parents 23236a6 + a56292e commit b64e602

File tree

4 files changed

+62
-52
lines changed

4 files changed

+62
-52
lines changed

runtime/flang/dtime3f.c

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@
3131
#include <sys/types.h>
3232
#include <limits.h>
3333

34-
#ifndef CLK_TCK
35-
#define CLK_TCK sysconf(_SC_CLK_TCK)
34+
#ifdef _WIN32
35+
#include "times_win32.h"
36+
#define CLK_TCK 10000000.0
37+
#else
38+
#ifndef CLK_TCK
39+
#define CLK_TCK sysconf(_SC_CLK_TCK)
40+
#endif
3641
#endif
3742

38-
#ifndef _WIN32
3943
static clock_t accum_user = 0, accum_sys = 0;
4044

4145
float ENT3F(DTIME, dtime)(float *tarray)
@@ -50,33 +54,5 @@ float ENT3F(DTIME, dtime)(float *tarray)
5054
accum_sys = b.tms_stime;
5155
return (tarray[0] + tarray[1]);
5256
}
53-
#else
54-
#include <Windows.h>
55-
static FILETIME accum_user;
56-
static FILETIME accum_sys;
57-
58-
float convert_filetime( const FILETIME *ac_FileTime )
59-
{
60-
ULARGE_INTEGER lv_Large ;
61-
62-
lv_Large.LowPart = ac_FileTime->dwLowDateTime ;
63-
lv_Large.HighPart = ac_FileTime->dwHighDateTime ;
64-
65-
return (float)lv_Large.QuadPart ;
66-
}
6757

68-
float ENT3F(DTIME, dtime)(float *tarray)
69-
{
70-
71-
FILETIME time_create;
72-
FILETIME time_exit;
73-
74-
GetProcessTimes( GetCurrentProcess(),
75-
&time_create, &time_exit, &accum_sys, &accum_user );
76-
77-
tarray[0] = ((float)(convert_filetime(&accum_user)));
78-
tarray[1] = ((float)(convert_filetime(&accum_sys)));
79-
return (tarray[0] + tarray[1]);
80-
}
81-
#endif
8258

runtime/flang/etime3f.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@
3333
#include <sys/types.h>
3434
#include <limits.h>
3535

36-
#ifndef CLK_TCK
37-
#define CLK_TCK sysconf(_SC_CLK_TCK)
36+
37+
#ifdef _WIN32
38+
#include "times_win32.h"
39+
#define CLK_TCK 10000000.0
40+
#else
41+
#ifndef CLK_TCK
42+
#define CLK_TCK sysconf(_SC_CLK_TCK)
43+
#endif
3844
#endif
3945

40-
#ifndef _WIN32
4146
float ENT3F(ETIME, etime)(float *tarray)
4247
{
4348
struct tms b;
@@ -49,21 +54,3 @@ float ENT3F(ETIME, etime)(float *tarray)
4954
return (tarray[0] + tarray[1]);
5055
}
5156

52-
#else
53-
#include <Windows.h>
54-
55-
float ENT3F(ETIME, etime)(float *tarray)
56-
{
57-
FILETIME accum_user;
58-
FILETIME accum_sys;
59-
FILETIME time_create;
60-
FILETIME time_exit;
61-
62-
GetProcessTimes( GetCurrentProcess(),
63-
&time_create, &time_exit, &accum_sys, &accum_user );
64-
65-
tarray[0] = ((float)(convert_filetime(&accum_user)));
66-
tarray[1] = ((float)(convert_filetime(&accum_sys)));
67-
return (tarray[0] + tarray[1]);
68-
}
69-
#endif

runtime/flang/util.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,30 @@ void __fort_ftnstrcpy(char *dst, /* destination string, blank-filled */
331331
*dst++ = ' ';
332332
}
333333

334+
335+
#ifdef _WIN32
336+
#include "times_win32.h"
337+
338+
clock_t convert_filetime( const FILETIME *ac_FileTime )
339+
{
340+
ULARGE_INTEGER lv_Large ;
341+
342+
lv_Large.LowPart = ac_FileTime->dwLowDateTime ;
343+
lv_Large.HighPart = ac_FileTime->dwHighDateTime ;
344+
345+
return (clock_t)lv_Large.QuadPart ;
346+
}
347+
348+
/*
349+
Thin emulation of the unix times function
350+
*/
351+
void times(tms *time_struct) {
352+
FILETIME time_create, time_exit, accum_sys, accum_user;
353+
354+
GetProcessTimes( GetCurrentProcess(),
355+
&time_create, &time_exit, &accum_sys, &accum_user );
356+
357+
time_struct->tms_utime = convert_filetime(&accum_user);
358+
time_struct->tms_stime = convert_filetime(&accum_sys);
359+
}
360+
#endif

runtime/include/times_win32.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef _FLANG_TIMES_WIN32
2+
#define _FLANG_TIMES_WIN32
3+
#include <Windows.h>
4+
5+
typedef __int64 clock_t;
6+
7+
typedef struct tms {
8+
clock_t tms_utime; /* user time */
9+
clock_t tms_stime; /* system time */
10+
clock_t tms_cutime; /* user time of children */
11+
clock_t tms_cstime; /* system time of children */
12+
} tms;
13+
14+
clock_t convert_filetime( const FILETIME *ac_FileTime );
15+
16+
/*
17+
Thin emulation of the unix times function
18+
*/
19+
void times(tms *time_struct);
20+
#endif

0 commit comments

Comments
 (0)