Permalink
Browse files

Use high-precision clock time on Windows 8 and up.

  • Loading branch information...
1 parent 8f7bd84 commit 15982a28189454d5b7b3b065db5aac9816781bde @burgerrg burgerrg committed Sep 22, 2016
Showing with 21 additions and 1 deletion.
  1. +2 −0 LOG
  2. +14 −1 c/stats.c
  3. +5 −0 release_notes/release_notes.stex
View
@@ -320,3 +320,5 @@
the full buffer (but reporting that it did) in the case of errors from
write.
examples/csocket.c, examples/socket.ss
+- use high-precision clock time on Windows 8 and up
+ c/stats.c
View
@@ -115,6 +115,10 @@ ptr S_unique_id() {
static __int64 hires_cps = 0;
+typedef void (WINAPI *GetSystemTimeAsFileTime_t)(LPFILETIME lpSystemTimeAsFileTime);
+
+static GetSystemTimeAsFileTime_t s_GetSystemTimeAsFileTime = GetSystemTimeAsFileTime;
+
static void s_gettime(INT typeno, struct timespec *tp) {
switch (typeno) {
case time_process: {
@@ -189,7 +193,7 @@ static void s_gettime(INT typeno, struct timespec *tp) {
case time_utc: {
FILETIME ft; __int64 total;
- GetSystemTimeAsFileTime(&ft);
+ s_GetSystemTimeAsFileTime(&ft);
total = ft.dwHighDateTime;
total <<= 32;
total |= ft.dwLowDateTime;
@@ -459,5 +463,14 @@ ptr S_realtime(void) {
/******** initialization ********/
void S_stats_init() {
+ /* Use GetSystemTimePreciseAsFileTime when available (Windows 8 and later). */
+ HMODULE h = LoadLibrary("kernel32.dll");
+ if (h != NULL) {
+ GetSystemTimeAsFileTime_t proc = (GetSystemTimeAsFileTime_t)GetProcAddress(h, "GetSystemTimePreciseAsFileTime");
+ if (proc != NULL)
+ s_GetSystemTimeAsFileTime = proc;
+ else
+ FreeLibrary(h);
+ }
s_gettime(time_monotonic, &starting_mono_tp);
}
@@ -58,6 +58,11 @@ Online versions of both books can be found at
%-----------------------------------------------------------------------------
\section{Functionality Changes}\label{section:functionality}
+\subsection{High-precision clock time in Windows 8 and up (9.4.1)}
+
+When running on Windows 8 and up, Chez Scheme uses the high-precision
+clock time function for the current date and time.
+
\subsection{Printing of non-standard (extended) identifiers (9.4.1)}
Chez Scheme extends the syntax of identifiers as described in the

2 comments on commit 15982a2

@alflanagan

This breaks non-Windows builds: S_stats_init() needs #ifdef WIN32 / #else / #endif

@burgerrg
Contributor

Thanks for finding this mistake! It should be corrected in the latest commit.

Please sign in to comment.