mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
Merge pull request #4346 from Cyan4973/wintime
fix a risk of overflow on a time counter on Windows
This commit is contained in:
@ -28,18 +28,20 @@
|
|||||||
UTIL_time_t UTIL_getTime(void)
|
UTIL_time_t UTIL_getTime(void)
|
||||||
{
|
{
|
||||||
static LARGE_INTEGER ticksPerSecond;
|
static LARGE_INTEGER ticksPerSecond;
|
||||||
|
static double nsFactor = 1.0;
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
if (!init) {
|
if (!init) {
|
||||||
if (!QueryPerformanceFrequency(&ticksPerSecond)) {
|
if (!QueryPerformanceFrequency(&ticksPerSecond)) {
|
||||||
perror("timefn::QueryPerformanceFrequency");
|
perror("timefn::QueryPerformanceFrequency");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
nsFactor = 1000000000.0 / (double)ticksPerSecond.QuadPart;
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
{ UTIL_time_t r;
|
{ UTIL_time_t r;
|
||||||
LARGE_INTEGER x;
|
LARGE_INTEGER x;
|
||||||
QueryPerformanceCounter(&x);
|
QueryPerformanceCounter(&x);
|
||||||
r.t = (PTime)(x.QuadPart * 1000000000ULL / ticksPerSecond.QuadPart);
|
r.t = (PTime)((double)x.QuadPart * nsFactor);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user