Commit 64235fec authored by Robert Haas's avatar Robert Haas

Don't require users of src/port/gettimeofday.c to initialize it.

Commit 8001fe67 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
parent f2874feb
...@@ -261,12 +261,6 @@ startup_hacks(const char *progname) ...@@ -261,12 +261,6 @@ startup_hacks(const char *progname)
/* In case of general protection fault, don't show GUI popup box */ /* In case of general protection fault, don't show GUI popup box */
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
#ifndef HAVE_GETTIMEOFDAY
/* Figure out which syscall to use to capture timestamp information */
init_win32_gettimeofday();
#endif
} }
#endif /* WIN32 */ #endif /* WIN32 */
......
...@@ -328,8 +328,6 @@ extern FILE *pgwin32_popen(const char *command, const char *type); ...@@ -328,8 +328,6 @@ extern FILE *pgwin32_popen(const char *command, const char *type);
#ifndef HAVE_GETTIMEOFDAY #ifndef HAVE_GETTIMEOFDAY
/* Last parameter not used */ /* Last parameter not used */
extern int gettimeofday(struct timeval * tp, struct timezone * tzp); extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
/* On windows we need to call some backend start setup for accurate timing */
extern void init_win32_gettimeofday(void);
#endif #endif
#else /* !WIN32 */ #else /* !WIN32 */
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <sys/time.h> #include <sys/time.h>
static void init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime);
/* FILETIME of Jan 1 1970 00:00:00, the PostgreSQL epoch */ /* FILETIME of Jan 1 1970 00:00:00, the PostgreSQL epoch */
static const unsigned __int64 epoch = UINT64CONST(116444736000000000); static const unsigned __int64 epoch = UINT64CONST(116444736000000000);
...@@ -49,14 +50,15 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); ...@@ -49,14 +50,15 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000);
typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME); typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME);
/* Storage for the function we pick at runtime */ /* Storage for the function we pick at runtime */
static PgGetSystemTimeFn pg_get_system_time = NULL; static PgGetSystemTimeFn pg_get_system_time = &init_gettimeofday;
/* /*
* During backend startup, determine if GetSystemTimePreciseAsFileTime is * One time initializer. Determine whether GetSystemTimePreciseAsFileTime
* available and use it; if not, fall back to GetSystemTimeAsFileTime. * is available and if so, plan to use it; if not, fall back to
* GetSystemTimeAsFileTime.
*/ */
void static void
init_win32_gettimeofday(void) init_gettimeofday(LPFILETIME lpSystemTimeAsFileTime)
{ {
/* /*
* Because it's guaranteed that kernel32.dll will be linked into our * Because it's guaranteed that kernel32.dll will be linked into our
...@@ -80,14 +82,16 @@ init_win32_gettimeofday(void) ...@@ -80,14 +82,16 @@ init_win32_gettimeofday(void)
* The expected error from GetLastError() is ERROR_PROC_NOT_FOUND, if * The expected error from GetLastError() is ERROR_PROC_NOT_FOUND, if
* the function isn't present. No other error should occur. * the function isn't present. No other error should occur.
* *
* It's too early in startup to elog(...) if we get some unexpected * We can't report an error here because this might be running in
* error, and not serious enough to warrant a fprintf to stderr about * frontend code; and even if we're in the backend, it's too early
* it or save the error and report it later. So silently fall back to * to elog(...) if we get some unexpected error. Also, it's not a
* serious problem, so just silently fall back to
* GetSystemTimeAsFileTime irrespective of why the failure occurred. * GetSystemTimeAsFileTime irrespective of why the failure occurred.
*/ */
pg_get_system_time = &GetSystemTimeAsFileTime; pg_get_system_time = &GetSystemTimeAsFileTime;
} }
(*pg_get_system_time)(lpSystemTimeAsFileTime);
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment