forked from mirrors/gecko-dev
Bug 1785162 - [2/3] refactor to specify stall count and time r=glandium,gsvelto
Refactor to allow specifying a potentially variable stall-count and -time, rather than a binary stall/don't-stall cue. No functional changes; this facility will actually be used in the next commit. Differential Revision: https://phabricator.services.mozilla.com/D157139
This commit is contained in:
parent
f30c547ca5
commit
adac61618a
1 changed files with 19 additions and 11 deletions
|
|
@ -1386,23 +1386,33 @@ constexpr size_t kMaxAttempts = 10;
|
||||||
// Microsoft's documentation for ::Sleep() for details.)
|
// Microsoft's documentation for ::Sleep() for details.)
|
||||||
constexpr size_t kDelayMs = 50;
|
constexpr size_t kDelayMs = 50;
|
||||||
|
|
||||||
|
struct StallSpecs {
|
||||||
|
size_t maxAttempts;
|
||||||
|
size_t delayMs;
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr StallSpecs maxStall = {.maxAttempts = kMaxAttempts,
|
||||||
|
.delayMs = kDelayMs};
|
||||||
|
static constexpr StallSpecs doNotStall
|
||||||
|
[[maybe_unused]] = {.maxAttempts = 0, .delayMs = 0};
|
||||||
|
|
||||||
Atomic<bool> sHasStalled{false};
|
Atomic<bool> sHasStalled{false};
|
||||||
static inline bool ShouldStallAndRetry() {
|
static inline StallSpecs GetStallSpecs() {
|
||||||
# if defined(JS_STANDALONE)
|
# if defined(JS_STANDALONE)
|
||||||
// GetGeckoProcessType() isn't available in this configuration. (SpiderMonkey
|
// GetGeckoProcessType() isn't available in this configuration. (SpiderMonkey
|
||||||
// on Windows mostly skips this in favor of directly calling ::VirtualAlloc(),
|
// on Windows mostly skips this in favor of directly calling ::VirtualAlloc(),
|
||||||
// though, so it's probably not going to matter whether we stall here or not.)
|
// though, so it's probably not going to matter whether we stall here or not.)
|
||||||
return true;
|
return maxStall;
|
||||||
# elif defined(NIGHTLY_BUILD)
|
# elif defined(NIGHTLY_BUILD)
|
||||||
// On Nightly, always stall, for experiment's sake (bug 1785162).
|
// On Nightly, always stall, for experiment's sake (bug 1785162).
|
||||||
return true;
|
return maxStall;
|
||||||
# else
|
# else
|
||||||
// In the main process, always stall.
|
// In the main process, always stall.
|
||||||
if (GetGeckoProcessType() == GeckoProcessType::GeckoProcessType_Default) {
|
if (GetGeckoProcessType() == GeckoProcessType::GeckoProcessType_Default) {
|
||||||
return true;
|
return maxStall;
|
||||||
}
|
}
|
||||||
// Otherwise, stall at most once.
|
// Otherwise, stall at most once.
|
||||||
return sHasStalled.compareExchange(false, true);
|
return sHasStalled.compareExchange(false, true) ? maxStall : doNotStall;
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1438,13 +1448,11 @@ static inline bool ShouldStallAndRetry() {
|
||||||
if (!(flAllocationType & MEM_COMMIT)) return nullptr;
|
if (!(flAllocationType & MEM_COMMIT)) return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also return if we just aren't supposed to be retrying at the moment, for
|
// Retry as many times as desired (possibly zero).
|
||||||
// whatever reason.
|
const StallSpecs stallSpecs = GetStallSpecs();
|
||||||
if (!ShouldStallAndRetry()) return nullptr;
|
|
||||||
|
|
||||||
// Otherwise, retry.
|
for (size_t i = 0; i < stallSpecs.maxAttempts; ++i) {
|
||||||
for (size_t i = 0; i < kMaxAttempts; ++i) {
|
::Sleep(stallSpecs.delayMs);
|
||||||
::Sleep(kDelayMs);
|
|
||||||
void* ptr = ::VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
|
void* ptr = ::VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
|
||||||
|
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue