33 *
44 * Copyright (c) 2000-2007, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.54 2007/01/05 22:19:49 momjian Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.55 2007/04/13 20:40:59 mha Exp $
77 */
88#ifndef COMMON_H
99#define COMMON_H
@@ -63,10 +63,6 @@ extern const char *session_username(void);
6363
6464extern char * expand_tilde (char * * filename );
6565
66- /* Workarounds for Windows */
67- /* Probably to be moved up the source tree in the future, perhaps to be replaced by
68- * more specific checks like configure-style HAVE_GETTIMEOFDAY macros.
69- */
7066#ifndef WIN32
7167
7268#include <sys/time.h>
@@ -78,16 +74,25 @@ typedef struct timeval TimevalStruct;
7874((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
7975 ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
8076#else
77+ /*
78+ * To get good resolution (better than ~15ms) on Windows, use
79+ * the high resolution performance counters. They can't be used
80+ * to get absolute times, but are good for measuring differences.
81+ */
82+ static __inline__double
83+ GetTimerFrequency (void )
84+ {
85+ LARGE_INTEGER f ;
8186
82- #include <sys/types.h>
83- #include <sys/timeb.h>
87+ QueryPerformanceFrequency (& f );
88+ return (double )f .QuadPart ;
89+ }
8490
85- typedef struct _timeb TimevalStruct ;
91+ typedef LARGE_INTEGER TimevalStruct ;
8692
87- #define GETTIMEOFDAY (T )_ftime(T )
93+ #define GETTIMEOFDAY (T )QueryPerformanceCounter((T) )
8894#define DIFF_MSEC (T ,U ) \
89- (((T)->time - (U)->time) * 1000.0 + \
90- ((T)->millitm - (U)->millitm))
91- #endif
95+ (((T)->QuadPart - (U)->QuadPart) * 1000.0 / GetTimerFrequency())
96+ #endif /* WIN32 */
9297
9398#endif /* COMMON_H */