util/os_time: Safe os_time_get_nano for Windows

Avoid small possibility of reading torn write on 32-bit platforms.

If frequency caching is desired, it's probably better to initialize from
C++ and extern "C" instead. It's not a tremendous optimization though.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7138>
This commit is contained in:
James Park 2020-11-03 10:03:13 -08:00 committed by Marge Bot
parent 192d721e3b
commit 4a94527ca1

View file

@ -67,11 +67,10 @@ os_time_get_nano(void)
#elif DETECT_OS_WINDOWS
static LARGE_INTEGER frequency;
LARGE_INTEGER frequency;
LARGE_INTEGER counter;
int64_t secs, nanosecs;
if(!frequency.QuadPart)
QueryPerformanceFrequency(&frequency);
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&counter);
/* Compute seconds and nanoseconds parts separately to
* reduce severity of precision loss.