Bug 1406793 - Make IsWindows* methods thread-safe. r?nfroyd draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 09 Oct 2017 10:36:23 +0200
changeset 676663 42b2ae84f14b00d67ecdc3e0ecf8d7e442d451fe
parent 676552 5eba13f5b3a6ad80decdd8c7b30bff5fa477844f
child 676669 6bc550e58fc6540ca49a426307fa62d4ad9fd215
push id83573
push userbmo:jyavenard@mozilla.com
push dateMon, 09 Oct 2017 08:39:26 +0000
reviewersnfroyd
bugs1406793
milestone58.0a1
Bug 1406793 - Make IsWindows* methods thread-safe. r?nfroyd 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;
   }