Bug 1406793 - Make IsWindows* methods thread-safe. r=froydnj
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 09 Oct 2017 10:36:23 +0200
changeset 385211 4bf0f40c6755b92ab878a4c0a523499b2180a2e4
parent 385210 a4de1a9d965add037872c11a11eac026158be657
child 385212 134fc4fd4727638689539644498d1ddba5442b1e
push id32649
push userarchaeopteryx@coole-files.de
push dateTue, 10 Oct 2017 09:11:18 +0000
treeherdermozilla-central@87ca0b304342 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1406793
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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;
   }