Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e4c33b

Browse files
committed
Fix getrusage() emulation on Windows. Magnus Hagander
1 parent3cc2134 commit1e4c33b

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

‎src/port/getrusage.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/getrusage.c,v 1.6 2004/08/29 04:13:12 momjian Exp $
11+
* $PostgreSQL: pgsql/src/port/getrusage.c,v 1.7 2004/09/02 17:55:16 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -26,6 +26,7 @@
2626
*solaris_sparc
2727
*svr4
2828
*hpux 9.*
29+
*win32
2930
* which currently is all the supported platforms that don't have a
3031
* native version of getrusage(). So, if configure decides to compile
3132
* this file at all, we just use this version unconditionally.
@@ -35,9 +36,39 @@ int
3536
getrusage(intwho,structrusage*rusage)
3637
{
3738
#ifdefWIN32
38-
if (rusage)
39-
memset(rusage,0,sizeof(rusage));
40-
#else
39+
40+
FILETIMEstarttime;
41+
FILETIMEexittime;
42+
FILETIMEkerneltime;
43+
FILETIMEusertime;
44+
ULARGE_INTEGERli;
45+
46+
if (rusage== (structrusage*)NULL)
47+
{
48+
errno=EFAULT;
49+
return-1;
50+
}
51+
memset(rusage,0,sizeof(structrusage));
52+
if (GetProcessTimes(GetCurrentProcess(),
53+
&starttime,&exittime,&kerneltime,&usertime)==0)
54+
{
55+
_dosmaperr(GetLastError());
56+
return-1;
57+
}
58+
59+
/* Convert FILETIMEs (0.1 us) to struct timeval */
60+
memcpy(&li,&kerneltime,sizeof(FILETIME));
61+
li.QuadPart /=10L;/* Convert to microseconds */
62+
rusage->ru_stime.tv_sec=li.QuadPart /1000000L;
63+
rusage->ru_stime.tv_usec=li.QuadPart %1000000L;
64+
65+
memcpy(&li,&usertime,sizeof(FILETIME));
66+
li.QuadPart /=10L;/* Convert to microseconds */
67+
rusage->ru_utime.tv_sec=li.QuadPart /1000000L;
68+
rusage->ru_utime.tv_usec=li.QuadPart %1000000L;
69+
70+
#else/* all but WIN32 */
71+
4172
structtmstms;
4273
inttick_rate=CLK_TCK;/* ticks per second */
4374
clock_tu,
@@ -73,6 +104,8 @@ getrusage(int who, struct rusage * rusage)
73104
rusage->ru_utime.tv_usec=TICK_TO_USEC(u,tick_rate);
74105
rusage->ru_stime.tv_sec=TICK_TO_SEC(s,tick_rate);
75106
rusage->ru_stime.tv_usec=TICK_TO_USEC(u,tick_rate);
76-
#endif
107+
108+
#endif/* WIN32 */
109+
77110
return0;
78111
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp