Bug 1406793 - Make IsWindows* methods thread-safe. r?nfroyd
MozReview-Commit-ID: 9AmhHv2g983
--- 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;
}