commit 5644eaf736fa90ab53d1a25c79812099ded74d3e
parent b52889143abd3938669b0c2ce3c394507677fdaa
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Tue, 30 Sep 2025 20:41:34 +0000
Bug 1991395 - Better encapsulation for chaos mode r=necko-reviewers,kershaw
Use inline variable for the ne static members so that we don't need
definition in .cpp files. Those definitions are a pain because we don't
link libxul with the mfbt library.
Also remove an unused inclusion while we're at it.
Differential Revision: https://phabricator.services.mozilla.com/D266653
Diffstat:
4 files changed, 11 insertions(+), 33 deletions(-)
diff --git a/mfbt/ChaosMode.cpp b/mfbt/ChaosMode.cpp
@@ -1,17 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#include "mozilla/ChaosMode.h"
-
-namespace mozilla {
-
-namespace detail {
-
-Atomic<uint32_t, Relaxed> gChaosModeCounter(0);
-ChaosFeature gChaosFeatures = ChaosFeature::Any;
-
-} /* namespace detail */
-} /* namespace mozilla */
diff --git a/mfbt/ChaosMode.h b/mfbt/ChaosMode.h
@@ -7,11 +7,10 @@
#ifndef mozilla_ChaosMode_h
#define mozilla_ChaosMode_h
+#include "mozilla/Assertions.h"
#include "mozilla/Atomics.h"
-#include "mozilla/EnumSet.h"
-#include <stdint.h>
-#include <stdlib.h>
+#include <cstdint>
namespace mozilla {
@@ -36,25 +35,23 @@ enum class ChaosFeature : uint32_t {
Any = 0xffffffff,
};
-namespace detail {
-extern MFBT_DATA Atomic<uint32_t, Relaxed> gChaosModeCounter;
-extern MFBT_DATA ChaosFeature gChaosFeatures;
-} // namespace detail
-
/**
* When "chaos mode" is activated, code that makes implicitly nondeterministic
* choices is encouraged to make random and extreme choices, to test more
* code paths and uncover bugs.
*/
class ChaosMode {
+ static inline MFBT_DATA Atomic<uint32_t, Relaxed> ChaosModeCounter{0};
+ static inline MFBT_DATA ChaosFeature ChaosFeatures = ChaosFeature::Any;
+
public:
static void SetChaosFeature(ChaosFeature aChaosFeature) {
- detail::gChaosFeatures = aChaosFeature;
+ ChaosFeatures = aChaosFeature;
}
static bool isActive(ChaosFeature aFeature) {
- return detail::gChaosModeCounter > 0 &&
- (uint32_t(detail::gChaosFeatures) & uint32_t(aFeature));
+ return ChaosModeCounter > 0 &&
+ (uint32_t(ChaosFeatures) & uint32_t(aFeature));
}
/**
@@ -62,14 +59,14 @@ class ChaosMode {
* calls to leaveChaosMode must be made in order to restore the original
* chaos mode state.
*/
- static void enterChaosMode() { detail::gChaosModeCounter++; }
+ static void enterChaosMode() { ChaosModeCounter++; }
/**
* Decrease the chaos mode activation level. See enterChaosMode().
*/
static void leaveChaosMode() {
- MOZ_ASSERT(detail::gChaosModeCounter > 0);
- detail::gChaosModeCounter--;
+ MOZ_ASSERT(ChaosModeCounter > 0);
+ ChaosModeCounter--;
}
/**
diff --git a/mfbt/moz.build b/mfbt/moz.build
@@ -155,7 +155,6 @@ if CONFIG["OS_ARCH"] == "WASI":
UNIFIED_SOURCES += [
"Assertions.cpp",
- "ChaosMode.cpp",
"double-conversion/double-conversion/bignum-dtoa.cc",
"double-conversion/double-conversion/bignum.cc",
"double-conversion/double-conversion/cached-powers.cc",
diff --git a/netwerk/protocol/http/ConnectionEntry.cpp b/netwerk/protocol/http/ConnectionEntry.cpp
@@ -15,7 +15,6 @@
#include "ConnectionEntry.h"
#include "HttpConnectionUDP.h"
#include "nsQueryObject.h"
-#include "mozilla/ChaosMode.h"
#include "mozilla/StaticPrefs_network.h"
#include "nsHttpHandler.h"
#include "mozilla/net/neqo_glue_ffi_generated.h"