Bug 1948068 - Make ChaosMode::isActive cheaper when disabled. r=glandium,nika
This changes a bit the semantics of .enterChaosMode(), but only when already combined with MOZ_CHAOSMODE, to respect the MOZ_CHAOSMODE feature set, which seems in general like a sensible and more flexible behavior? Differential Revision: https://phabricator.services.mozilla.com/D238078
This commit is contained in:
@@ -1063,14 +1063,16 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
|
||||
PR_SetEnv("MOZ_DISABLE_ASAN_REPORTER=1");
|
||||
#endif
|
||||
|
||||
if (PR_GetEnv("MOZ_CHAOSMODE")) {
|
||||
if (auto* featureStr = PR_GetEnv("MOZ_CHAOSMODE")) {
|
||||
ChaosFeature feature = ChaosFeature::Any;
|
||||
long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16);
|
||||
long featureInt = strtol(featureStr, nullptr, 16);
|
||||
if (featureInt) {
|
||||
// NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
|
||||
feature = static_cast<ChaosFeature>(featureInt);
|
||||
}
|
||||
ChaosMode::SetChaosFeature(feature);
|
||||
ChaosMode::enterChaosMode();
|
||||
MOZ_ASSERT(ChaosMode::isActive(ChaosFeature::Any));
|
||||
}
|
||||
|
||||
if (ChaosMode::isActive(ChaosFeature::Any)) {
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace mozilla {
|
||||
|
||||
namespace detail {
|
||||
|
||||
Atomic<uint32_t, SequentiallyConsistent> gChaosModeCounter(0);
|
||||
ChaosFeature gChaosFeatures = None;
|
||||
Atomic<uint32_t, Relaxed> gChaosModeCounter(0);
|
||||
ChaosFeature gChaosFeatures = ChaosFeature::Any;
|
||||
|
||||
} /* namespace detail */
|
||||
} /* namespace mozilla */
|
||||
|
||||
@@ -37,7 +37,7 @@ enum ChaosFeature {
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
extern MFBT_DATA Atomic<uint32_t, SequentiallyConsistent> gChaosModeCounter;
|
||||
extern MFBT_DATA Atomic<uint32_t, Relaxed> gChaosModeCounter;
|
||||
extern MFBT_DATA ChaosFeature gChaosFeatures;
|
||||
} // namespace detail
|
||||
|
||||
@@ -53,17 +53,13 @@ class ChaosMode {
|
||||
}
|
||||
|
||||
static bool isActive(ChaosFeature aFeature) {
|
||||
if (detail::gChaosModeCounter > 0) {
|
||||
return true;
|
||||
}
|
||||
return detail::gChaosFeatures & aFeature;
|
||||
return detail::gChaosModeCounter > 0 && (detail::gChaosFeatures & aFeature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the chaos mode activation level. An equivalent number of
|
||||
* calls to leaveChaosMode must be made in order to restore the original
|
||||
* chaos mode state. If the activation level is nonzero all chaos mode
|
||||
* features are activated.
|
||||
* chaos mode state.
|
||||
*/
|
||||
static void enterChaosMode() { detail::gChaosModeCounter++; }
|
||||
|
||||
|
||||
@@ -3999,14 +3999,16 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
|
||||
}
|
||||
#endif // ANDROID
|
||||
|
||||
if (PR_GetEnv("MOZ_CHAOSMODE")) {
|
||||
if (auto* featureStr = PR_GetEnv("MOZ_CHAOSMODE")) {
|
||||
ChaosFeature feature = ChaosFeature::Any;
|
||||
long featureInt = strtol(PR_GetEnv("MOZ_CHAOSMODE"), nullptr, 16);
|
||||
long featureInt = strtol(featureStr, nullptr, 16);
|
||||
if (featureInt) {
|
||||
// NOTE: MOZ_CHAOSMODE=0 or a non-hex value maps to Any feature.
|
||||
feature = static_cast<ChaosFeature>(featureInt);
|
||||
}
|
||||
ChaosMode::SetChaosFeature(feature);
|
||||
ChaosMode::enterChaosMode();
|
||||
MOZ_ASSERT(ChaosMode::isActive(ChaosFeature::Any));
|
||||
}
|
||||
|
||||
if (CheckArgExists("fxr")) {
|
||||
|
||||
Reference in New Issue
Block a user