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

Commit519b075

Browse files
Use GetSystemTimeAsFileTime directly in win32
PostgreSQL was calling GetSystemTime followed by SystemTimeToFileTime in thewin32 port gettimeofday function. This is not necessary and limits the reportedprecision to the 1ms granularity that the SYSTEMTIME struct can represent. Byusing GetSystemTimeAsFileTime we avoid unnecessary conversions and capturetimestamps at 100ns granularity, which is then rounded to 1µs granularity forstorage in a PostgreSQL timestamp.On most Windows systems this change will actually have no significant effect ontimestamp resolution as the system timer tick is typically between 1ms and 15msdepending on what timer resolution currently running applications haverequested. You can check this with clockres.exe from sysinternals. Despite theplatform limiation this change still permits capture of finer timestamps wherethe system is capable of producing them and it gets rid of an unnecessarysyscall.The higher resolution GetSystemTimePreciseAsFileTime call available on Windows8 and Windows Server 2012 has the same interface as GetSystemTimeAsFileTime, soswitching to GetSystemTimeAsFileTime makes it easier to use the Precise variantlater.Craig Ringer, reviewed by David Rowley
1 parent611d46e commit519b075

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

‎src/port/gettimeofday.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@
3131
#include<sys/time.h>
3232

3333

34-
/* FILETIME of Jan 1 1970 00:00:00. */
34+
/* FILETIME of Jan 1 1970 00:00:00, the PostgreSQL epoch */
3535
staticconstunsigned__int64epoch=UINT64CONST(116444736000000000);
3636

37+
/*
38+
* FILETIME represents the number of 100-nanosecond intervals since
39+
* January 1, 1601 (UTC).
40+
*/
41+
#defineFILETIME_UNITS_PER_SEC10000000L
42+
#defineFILETIME_UNITS_PER_USEC10
43+
3744
/*
3845
* timezone information is stored outside the kernel so tzp isn't used anymore.
3946
*
@@ -44,16 +51,15 @@ int
4451
gettimeofday(structtimeval*tp,structtimezone*tzp)
4552
{
4653
FILETIMEfile_time;
47-
SYSTEMTIMEsystem_time;
4854
ULARGE_INTEGERularge;
4955

50-
GetSystemTime(&system_time);
51-
SystemTimeToFileTime(&system_time,&file_time);
56+
GetSystemTimeAsFileTime(&file_time);
5257
ularge.LowPart=file_time.dwLowDateTime;
5358
ularge.HighPart=file_time.dwHighDateTime;
5459

55-
tp->tv_sec= (long) ((ularge.QuadPart-epoch) /10000000L);
56-
tp->tv_usec= (long) (system_time.wMilliseconds*1000);
60+
tp->tv_sec= (long) ((ularge.QuadPart-epoch) /FILETIME_UNITS_PER_SEC);
61+
tp->tv_usec= (long) (((ularge.QuadPart-epoch) %FILETIME_UNITS_PER_SEC)
62+
/FILETIME_UNITS_PER_USEC);
5763

5864
return0;
5965
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp