Bug 1406793 - Make IsWindows* methods thread-safe. r=froydnj
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 09 Oct 2017 10:36:23 +0200
changeset 427865 4bf0f40c6755b92ab878a4c0a523499b2180a2e4
parent 427864 a4de1a9d965add037872c11a11eac026158be657
child 427866 134fc4fd4727638689539644498d1ddba5442b1e
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersfroydnj
bugs1406793
milestone58.0a1
Bug 1406793 - Make IsWindows* methods thread-safe. r=froydnj MozReview-Commit-ID: 9AmhHv2g983
mfbt/WindowsVersion.h
--- a/mfbt/WindowsVersion.h
+++ b/mfbt/WindowsVersion.h
@@ -2,27 +2,28 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_WindowsVersion_h
 #define mozilla_WindowsVersion_h
 
+#include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include <stdint.h>
 #include <windows.h>
 
 namespace mozilla {
 
 inline bool
 IsWindowsVersionOrLater(uint32_t aVersion)
 {
-  static uint32_t minVersion = 0;
-  static uint32_t maxVersion = UINT32_MAX;
+  static Atomic<uint32_t> minVersion(0);
+  static Atomic<uint32_t> maxVersion(UINT32_MAX);
 
   if (minVersion >= aVersion) {
     return true;
   }
 
   if (aVersion >= maxVersion) {
     return false;
   }
@@ -51,18 +52,18 @@ IsWindowsVersionOrLater(uint32_t aVersio
 
   maxVersion = aVersion;
   return false;
 }
 
 inline bool
 IsWindowsBuildOrLater(uint32_t aBuild)
 {
-  static uint32_t minBuild = 0;
-  static uint32_t maxBuild = UINT32_MAX;
+  static Atomic<uint32_t> minBuild(0);
+  static Atomic<uint32_t> maxBuild(UINT32_MAX);
 
   if (minBuild >= aBuild) {
     return true;
   }
 
   if (aBuild >= maxBuild) {
     return false;
   }
@@ -82,18 +83,18 @@ IsWindowsBuildOrLater(uint32_t aBuild)
 
   maxBuild = aBuild;
   return false;
 }
 
 inline bool
 IsWindows10BuildOrLater(uint32_t aBuild)
 {
-  static uint32_t minBuild = 0;
-  static uint32_t maxBuild = UINT32_MAX;
+  static Atomic<uint32_t> minBuild(0);
+  static Atomic<uint32_t> maxBuild(UINT32_MAX);
 
   if (minBuild >= aBuild) {
     return true;
   }
 
   if (aBuild >= maxBuild) {
     return false;
   }