Mesa (master): util/os_time: Safe os_time_get_nano for Windows

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 26 08:16:53 UTC 2020


Module: Mesa
Branch: master
Commit: 4a94527ca18cbbd288e0e808c46b3e2dcb1d42ba
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4a94527ca18cbbd288e0e808c46b3e2dcb1d42ba

Author: James Park <jpark37 at lagfreegames.com>
Date:   Tue Nov  3 10:03:13 2020 -0800

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 at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7138>

---

 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 92fc3638ddb..d2edd88104a 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.



More information about the mesa-commit mailing list