commit 0a394e80d227e3c5d8259a74473395006ff4699c
parent 52296e3525e6eb23533e60cd69df3a0542c51bdf
Author: Cristina Horotan <chorotan@mozilla.com>
Date: Wed, 1 Oct 2025 11:13:46 +0300
Revert "Bug 1991395 - Better encapsulation for chaos mode r=necko-reviewers,kershaw" on request by dev
This reverts commit f784e4931b5330694451c47b79f77d4b91964086.
Diffstat:
4 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/mfbt/ChaosMode.cpp b/mfbt/ChaosMode.cpp
@@ -0,0 +1,17 @@
+/* -*- 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,10 +7,11 @@
#ifndef mozilla_ChaosMode_h
#define mozilla_ChaosMode_h
-#include "mozilla/Assertions.h"
#include "mozilla/Atomics.h"
+#include "mozilla/EnumSet.h"
-#include <cstdint>
+#include <stdint.h>
+#include <stdlib.h>
namespace mozilla {
@@ -35,23 +36,25 @@ 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 Atomic<uint32_t, Relaxed> ChaosModeCounter{0};
- static inline ChaosFeature ChaosFeatures = ChaosFeature::Any;
-
public:
static void SetChaosFeature(ChaosFeature aChaosFeature) {
- ChaosFeatures = aChaosFeature;
+ detail::gChaosFeatures = aChaosFeature;
}
static bool isActive(ChaosFeature aFeature) {
- return ChaosModeCounter > 0 &&
- (uint32_t(ChaosFeatures) & uint32_t(aFeature));
+ return detail::gChaosModeCounter > 0 &&
+ (uint32_t(detail::gChaosFeatures) & uint32_t(aFeature));
}
/**
@@ -59,14 +62,14 @@ class ChaosMode {
* calls to leaveChaosMode must be made in order to restore the original
* chaos mode state.
*/
- static void enterChaosMode() { ChaosModeCounter++; }
+ static void enterChaosMode() { detail::gChaosModeCounter++; }
/**
* Decrease the chaos mode activation level. See enterChaosMode().
*/
static void leaveChaosMode() {
- MOZ_ASSERT(ChaosModeCounter > 0);
- ChaosModeCounter--;
+ MOZ_ASSERT(detail::gChaosModeCounter > 0);
+ detail::gChaosModeCounter--;
}
/**
diff --git a/mfbt/moz.build b/mfbt/moz.build
@@ -155,6 +155,7 @@ 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,6 +15,7 @@
#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"