From 4a94527ca18cbbd288e0e808c46b3e2dcb1d42ba Mon Sep 17 00:00:00 2001 From: James Park Date: Tue, 3 Nov 2020 10:03:13 -0800 Subject: [PATCH] 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 Part-of: --- src/util/os_time.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/os_time.c b/src/util/os_time.c index 92fc363..d2edd88 100644 --- a/src/util/os_time.c +++ b/src/util/os_time.c @@ -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. -- 2.7.4