PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gettimeofday.c File Reference
#include "c.h"
#include <sys/time.h>
Include dependency graph for gettimeofday.c:

Go to the source code of this file.

Macros

#define FILETIME_UNITS_PER_SEC   10000000L
 
#define FILETIME_UNITS_PER_USEC   10
 

Functions

typedef VOID (WINAPI *PgGetSystemTimeFn)(LPFILETIME)
 
static void WINAPI init_gettimeofday (LPFILETIME lpSystemTimeAsFileTime)
 
int gettimeofday (struct timeval *tp, struct timezone *tzp)
 

Variables

static const unsigned __int64 epoch = UINT64CONST(116444736000000000)
 
static PgGetSystemTimeFn pg_get_system_time = &init_gettimeofday
 

Macro Definition Documentation

#define FILETIME_UNITS_PER_SEC   10000000L

Definition at line 40 of file gettimeofday.c.

Referenced by gettimeofday().

#define FILETIME_UNITS_PER_USEC   10

Definition at line 41 of file gettimeofday.c.

Referenced by gettimeofday().

Function Documentation

int gettimeofday ( struct timeval *  tp,
struct timezone tzp 
)

Definition at line 105 of file gettimeofday.c.

References epoch, FILETIME_UNITS_PER_SEC, and FILETIME_UNITS_PER_USEC.

Referenced by BootStrapXLOG(), doLog(), feGetCurrentTimestamp(), GetCurrentTimestamp(), GuessControlValues(), IsCheckpointOnSchedule(), log_line_prefix(), PerformRadiusTransaction(), pg_backend_random(), pg_frontend_random(), pg_rusage_init(), PostmasterMain(), RandomCancelKey(), ResetUsage(), setup_formatted_log_time(), ShowUsage(), threadRun(), timeofday(), and try_complete_step().

106 {
107  FILETIME file_time;
108  ULARGE_INTEGER ularge;
109 
110  (*pg_get_system_time) (&file_time);
111  ularge.LowPart = file_time.dwLowDateTime;
112  ularge.HighPart = file_time.dwHighDateTime;
113 
114  tp->tv_sec = (long) ((ularge.QuadPart - epoch) / FILETIME_UNITS_PER_SEC);
115  tp->tv_usec = (long) (((ularge.QuadPart - epoch) % FILETIME_UNITS_PER_SEC)
117 
118  return 0;
119 }
#define FILETIME_UNITS_PER_USEC
Definition: gettimeofday.c:41
#define FILETIME_UNITS_PER_SEC
Definition: gettimeofday.c:40
static const unsigned __int64 epoch
Definition: gettimeofday.c:34
static void WINAPI init_gettimeofday ( LPFILETIME  lpSystemTimeAsFileTime)
static

Definition at line 62 of file gettimeofday.c.

References pg_get_system_time.

63 {
64  /*
65  * Because it's guaranteed that kernel32.dll will be linked into our
66  * address space already, we don't need to LoadLibrary it and worry about
67  * closing it afterwards, so we're not using Pg's dlopen/dlsym() wrapper.
68  *
69  * We'll just look up the address of GetSystemTimePreciseAsFileTime if
70  * present.
71  *
72  * While we could look up the Windows version and skip this on Windows
73  * versions below Windows 8 / Windows Server 2012 there isn't much point,
74  * and determining the windows version is its self somewhat Windows
75  * version and development SDK specific...
76  */
77  pg_get_system_time = (PgGetSystemTimeFn) GetProcAddress(
78  GetModuleHandle(TEXT("kernel32.dll")),
79  "GetSystemTimePreciseAsFileTime");
80  if (pg_get_system_time == NULL)
81  {
82  /*
83  * The expected error from GetLastError() is ERROR_PROC_NOT_FOUND, if
84  * the function isn't present. No other error should occur.
85  *
86  * We can't report an error here because this might be running in
87  * frontend code; and even if we're in the backend, it's too early to
88  * elog(...) if we get some unexpected error. Also, it's not a
89  * serious problem, so just silently fall back to
90  * GetSystemTimeAsFileTime irrespective of why the failure occurred.
91  */
92  pg_get_system_time = &GetSystemTimeAsFileTime;
93  }
94 
95  (*pg_get_system_time) (lpSystemTimeAsFileTime);
96 }
static PgGetSystemTimeFn pg_get_system_time
Definition: gettimeofday.c:54
typedef VOID ( WINAPI *  PgGetSystemTimeFn)

Variable Documentation

const unsigned __int64 epoch = UINT64CONST(116444736000000000)
static
PgGetSystemTimeFn pg_get_system_time = &init_gettimeofday
static

Definition at line 54 of file gettimeofday.c.

Referenced by init_gettimeofday().