]> granicus.if.org Git - curl/commitdiff
Curl_now: figure out windows version in win32_init
authorDaniel Stenberg <daniel@haxx.se>
Thu, 14 Feb 2019 16:08:29 +0000 (17:08 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 15 Feb 2019 22:23:14 +0000 (23:23 +0100)
... and avoid use of static variables that aren't thread safe.

Fixes regression from e9ababd4f5a (present in the 7.64.0 release)

Reported-by: Paul Groke
Fixes #3572
Closes #3573

lib/easy.c
lib/timeval.c

index 6fcad3decdf8d3da8302168985d00d3337f05c52..d2d4166d5e3c01554287bc0c851e2cc4fd7b7f80 100644 (file)
@@ -75,6 +75,7 @@
 #include "ssh.h"
 #include "setopt.h"
 #include "http_digest.h"
+#include "system_win32.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -95,6 +96,11 @@ static void win32_cleanup(void)
 #endif
 }
 
+#ifdef WIN32
+LARGE_INTEGER Curl_freq;
+bool Curl_isVistaOrGreater;
+#endif
+
 /* win32_init() performs win32 socket initialization to properly setup the
    stack to allow networking */
 static CURLcode win32_init(void)
@@ -144,6 +150,16 @@ static CURLcode win32_init(void)
   }
 #endif
 
+#ifdef WIN32
+  if(Curl_verify_windows_version(6, 0, PLATFORM_WINNT,
+                                 VERSION_GREATER_THAN_EQUAL)) {
+    Curl_isVistaOrGreater = TRUE;
+    QueryPerformanceFrequency(&Curl_freq);
+  }
+  else
+    Curl_isVistaOrGreater = FALSE;
+#endif
+
   return CURLE_OK;
 }
 
index 2569f175c345dbb9af00a41a827b178cca696089..ff8d8a69af1ae2eaf7b55950ff6a5282e4a6741f 100644 (file)
  ***************************************************************************/
 
 #include "timeval.h"
-#include "system_win32.h"
 
 #if defined(WIN32) && !defined(MSDOS)
 
+/* set in win32_init() */
+extern LARGE_INTEGER Curl_freq;
+extern bool Curl_isVistaOrGreater;
+
 struct curltime Curl_now(void)
 {
   struct curltime now;
-  static LARGE_INTEGER freq;
-  static int isVistaOrGreater = -1;
-  if(isVistaOrGreater == -1) {
-    if(Curl_verify_windows_version(6, 0, PLATFORM_WINNT,
-                                   VERSION_GREATER_THAN_EQUAL)) {
-      isVistaOrGreater = 1;
-      QueryPerformanceFrequency(&freq);
-    }
-    else
-      isVistaOrGreater = 0;
-  }
-  if(isVistaOrGreater == 1) { /* QPC timer might have issues pre-Vista */
+  if(Curl_isVistaOrGreater) { /* QPC timer might have issues pre-Vista */
     LARGE_INTEGER count;
     QueryPerformanceCounter(&count);
-    now.tv_sec = (time_t)(count.QuadPart / freq.QuadPart);
-    now.tv_usec =
-      (int)((count.QuadPart % freq.QuadPart) * 1000000 / freq.QuadPart);
+    now.tv_sec = (time_t)(count.QuadPart / Curl_freq.QuadPart);
+    now.tv_usec = (int)((count.QuadPart % Curl_freq.QuadPart) * 1000000 /
+                        Curl_freq.QuadPart);
   }
   else {
     /* Disable /analyze warning that GetTickCount64 is preferred  */