Skip to content

Commit

Permalink
Curl_now: figure out windows version in win32_init
Browse files Browse the repository at this point in the history
... and avoid use of static variables that aren't thread safe.

Fixes regression from e9ababd (present in the 7.64.0 release)

Reported-by: Paul Groke
Fixes #3572
Closes #3573
  • Loading branch information
bagder committed Feb 15, 2019
1 parent 208c777 commit ca597ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
16 changes: 16 additions & 0 deletions lib/easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -95,6 +96,11 @@ static void win32_cleanup(void)
#endif
}

#ifdef WIN32
LARGE_INTEGER Curl_freq;
bool Curl_isVistaOrGreater;
#endif

This comment has been minimized.

Copy link
@gvanem

gvanem Feb 24, 2019

Contributor

This change causes these 2 new warnings when using clang-cl:

easy.c(110,15):  warning: no previous extern declaration for non-static variable 'Curl_freq' [-Wmissing-variable-declarations]
LARGE_INTEGER Curl_freq;
              ^
easy.c(111,6):  warning: no previous extern declaration for non-static variable 'Curl_isVistaOrGreater' [-Wmissing-variable-declarations]
bool Curl_isVistaOrGreater;
     ^

So IMHO, those should be put in some .h-file, but which?

This comment has been minimized.

Copy link
@bagder

bagder Feb 24, 2019

Author Member

How about we put them in system_win32.h ?

This comment has been minimized.

Copy link
@gvanem

gvanem Feb 24, 2019

Contributor

Probably a good idea.


/* win32_init() performs win32 socket initialization to properly setup the
stack to allow networking */
static CURLcode win32_init(void)
Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 8 additions & 16 deletions lib/timeval.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,22 @@
***************************************************************************/

#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 */
Expand Down

0 comments on commit ca597ad

Please sign in to comment.