Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 64235fe

Browse files
committed
Don't require users of src/port/gettimeofday.c to initialize it.
Commit 8001fe6 introduced this requirement, but per discussion, we want to avoid requirements of this type to make things easier on the calling code. An especially important consideration is that this may be used in frontend code, not just the backend. Asif Naeem, reviewed by Michael Paquier
1 parent f2874fe commit 64235fe

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/backend/main/main.c

-6
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ startup_hacks(const char *progname)
261261

262262
/* In case of general protection fault, don't show GUI popup box */
263263
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
264-
265-
#ifndef HAVE_GETTIMEOFDAY
266-
/* Figure out which syscall to use to capture timestamp information */
267-
init_win32_gettimeofday();
268-
#endif
269-
270264
}
271265
#endif /* WIN32 */
272266

src/include/port.h

-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,6 @@ extern FILE *pgwin32_popen(const char *command, const char *type);
328328
#ifndef HAVE_GETTIMEOFDAY
329329
/* Last parameter not used */
330330
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
331-
/* On windows we need to call some backend start setup for accurate timing */
332-
extern void init_win32_gettimeofday(void);
333331
#endif
334332
#else /* !WIN32 */
335333

src/port/gettimeofday.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <sys/time.h>
3232

33+
static void init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime);
3334

3435
/* FILETIME of Jan 1 1970 00:00:00, the PostgreSQL epoch */
3536
static const unsigned __int64 epoch = UINT64CONST(116444736000000000);
@@ -49,14 +50,15 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000);
4950
typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME);
5051

5152
/* Storage for the function we pick at runtime */
52-
static PgGetSystemTimeFn pg_get_system_time = NULL;
53+
static PgGetSystemTimeFn pg_get_system_time = &init_gettimeofday;
5354

5455
/*
55-
* During backend startup, determine if GetSystemTimePreciseAsFileTime is
56-
* available and use it; if not, fall back to GetSystemTimeAsFileTime.
56+
* One time initializer. Determine whether GetSystemTimePreciseAsFileTime
57+
* is available and if so, plan to use it; if not, fall back to
58+
* GetSystemTimeAsFileTime.
5759
*/
58-
void
59-
init_win32_gettimeofday(void)
60+
static void
61+
init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime)
6062
{
6163
/*
6264
* Because it's guaranteed that kernel32.dll will be linked into our
@@ -80,14 +82,16 @@ init_win32_gettimeofday(void)
8082
* The expected error from GetLastError() is ERROR_PROC_NOT_FOUND, if
8183
* the function isn't present. No other error should occur.
8284
*
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
85+
* We can't report an error here because this might be running in
86+
* frontend code; and even if we're in the backend, it's too early
87+
* to elog(...) if we get some unexpected error. Also, it's not a
88+
* serious problem, so just silently fall back to
8689
* GetSystemTimeAsFileTime irrespective of why the failure occurred.
8790
*/
8891
pg_get_system_time = &GetSystemTimeAsFileTime;
8992
}
9093

94+
(*pg_get_system_time)(lpSystemTimeAsFileTime);
9195
}
9296

9397
/*

0 commit comments

Comments
 (0)