On 2 December 2014 at 15:36, Craig Ringer <cr...@2ndquadrant.com> wrote:
> On 12/01/2014 09:51 PM, Marco Nenciarini wrote: > > I think this is a leftover, as you don't use elog afterwards. > > Good catch, fixed. > > I've looked over this again and tested it on a windows 8.1 machine. I cannot find any problems The only comments about the code I have would maybe be to use some constants like: #define FILETIME_PER_SEC 10000000L #define FILETIME_PER_USEC 10 I had to read the Microsoft documentation to see that "A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC)." http://msdn.microsoft.com/en-us/library/windows/desktop/dn553408%28v=vs.85%29.aspx The attached patch gets rid of those magic numbers, and hopefully makes it a bit easier to see what's going on. I agree with the lack of real need to log any sort of errors if init_win32_gettimeofday() gets any unexpected errors while trying to lookup GetSystemTimePreciseAsFileTime. I'm marking this as ready for committer. It seems worth going in just for the performance improvement alone, never mind the increased clock accuracy. I'll leave it up to the committer to decide if it's better with or without the attached patch. Regards David Rowley
diff --git a/src/port/gettimeofday.c b/src/port/gettimeofday.c index ab4f491..f4d8393 100644 --- a/src/port/gettimeofday.c +++ b/src/port/gettimeofday.c @@ -35,6 +35,13 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); /* + * FILETIME represents the number of 100-nanosecond intervals since + * January 1, 1601 (UTC). + */ +#define FILETIME_PER_SEC 10000000L +#define FILETIME_PER_USEC 10 + +/* * Both GetSystemTimeAsFileTime and GetSystemTimePreciseAsFileTime share a * signature, so we can just store a pointer to whichever we find. This * is the pointer's type. @@ -98,8 +105,9 @@ gettimeofday(struct timeval * tp, struct timezone * tzp) ularge.LowPart = file_time.dwLowDateTime; ularge.HighPart = file_time.dwHighDateTime; - tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); - tp->tv_usec = (long) (((ularge.QuadPart - epoch) % 10000000L) / 10); + tp->tv_sec = (long) ((ularge.QuadPart - epoch) / FILETIME_PER_SEC); + tp->tv_usec = (long) (((ularge.QuadPart - epoch) % FILETIME_PER_SEC) + / FILETIME_PER_USEC); return 0; }
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers