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

Commit8001fe6

Browse files
Windows: use GetSystemTimePreciseAsFileTime if available
PostgreSQL on Windows 8 or Windows Server 2012 will nowget high-resolution timestamps by dynamically loading theGetSystemTimePreciseAsFileTime function. It'll fall back toto GetSystemTimeAsFileTime if the higher precision variantisn't found, so the same binaries without problems on olderWindows releases.No attempt is made to detect the Windows version. Only thepresence or absence of the desired function is considered.Craig Ringer
1 parent519b075 commit8001fe6

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

‎src/backend/main/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ startup_hacks(const char *progname)
260260

261261
/* In case of general protection fault, don't show GUI popup box */
262262
SetErrorMode(SEM_FAILCRITICALERRORS |SEM_NOGPFAULTERRORBOX);
263+
264+
#ifndefHAVE_GETTIMEOFDAY
265+
/* Figure out which syscall to use to capture timestamp information */
266+
init_win32_gettimeofday();
267+
#endif
268+
263269
}
264270
#endif/* WIN32 */
265271

‎src/include/port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ extern FILE *pgwin32_popen(const char *command, const char *type);
328328
#ifndefHAVE_GETTIMEOFDAY
329329
/* Last parameter not used */
330330
externintgettimeofday(structtimeval*tp,structtimezone*tzp);
331+
/* On windows we need to call some backend start setup for accurate timing */
332+
externvoidinit_win32_gettimeofday(void);
331333
#endif
332334
#else/* !WIN32 */
333335

‎src/port/gettimeofday.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,59 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000);
4141
#defineFILETIME_UNITS_PER_SEC10000000L
4242
#defineFILETIME_UNITS_PER_USEC10
4343

44+
/*
45+
* Both GetSystemTimeAsFileTime and GetSystemTimePreciseAsFileTime share a
46+
* signature, so we can just store a pointer to whichever we find. This
47+
* is the pointer's type.
48+
*/
49+
typedefVOID (WINAPI*PgGetSystemTimeFn)(LPFILETIME);
50+
51+
/* Storage for the function we pick at runtime */
52+
staticPgGetSystemTimeFnpg_get_system_time=NULL;
53+
54+
/*
55+
* During backend startup, determine if GetSystemTimePreciseAsFileTime is
56+
* available and use it; if not, fall back to GetSystemTimeAsFileTime.
57+
*/
58+
void
59+
init_win32_gettimeofday(void)
60+
{
61+
/*
62+
* Because it's guaranteed that kernel32.dll will be linked into our
63+
* address space already, we don't need to LoadLibrary it and worry about
64+
* closing it afterwards, so we're not using Pg's dlopen/dlsym() wrapper.
65+
*
66+
* We'll just look up the address of GetSystemTimePreciseAsFileTime if
67+
* present.
68+
*
69+
* While we could look up the Windows version and skip this on Windows
70+
* versions below Windows 8 / Windows Server 2012 there isn't much point,
71+
* and determining the windows version is its self somewhat Windows version
72+
* and development SDK specific...
73+
*/
74+
pg_get_system_time= (PgGetSystemTimeFn)GetProcAddress(
75+
GetModuleHandle(TEXT("kernel32.dll")),
76+
"GetSystemTimePreciseAsFileTime");
77+
if (pg_get_system_time==NULL)
78+
{
79+
/*
80+
* The expected error from GetLastError() is ERROR_PROC_NOT_FOUND, if
81+
* the function isn't present. No other error should occur.
82+
*
83+
* It's too early in startup to elog(...) if we get some unexpected
84+
* error, and not serious enough to warrant a fprintf to stderr about
85+
* it or save the error and report it later. So silently fall back to
86+
* GetSystemTimeAsFileTime irrespective of why the failure occurred.
87+
*/
88+
pg_get_system_time=&GetSystemTimeAsFileTime;
89+
}
90+
91+
}
92+
4493
/*
4594
* timezone information is stored outside the kernel so tzp isn't used anymore.
4695
*
47-
* Note: this function is not for Win32 high precision timingpurpose. See
96+
* Note: this function is not for Win32 high precision timingpurposes. See
4897
* elapsed_time().
4998
*/
5099
int
@@ -53,7 +102,7 @@ gettimeofday(struct timeval * tp, struct timezone * tzp)
53102
FILETIMEfile_time;
54103
ULARGE_INTEGERularge;
55104

56-
GetSystemTimeAsFileTime(&file_time);
105+
(*pg_get_system_time)(&file_time);
57106
ularge.LowPart=file_time.dwLowDateTime;
58107
ularge.HighPart=file_time.dwHighDateTime;
59108

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp