Bug 1731564: Use motivated SpinEventLoopUntil inside dom/*. r=smaug

Depends on D126714

Differential Revision: https://phabricator.services.mozilla.com/D126957
This commit is contained in:
Jens Stutte 2021-10-07 08:06:11 +00:00
Родитель cd08f3b728
Коммит 2c7cda331d
16 изменённых файлов: 55 добавлений и 34 удалений

Просмотреть файл

@ -5045,8 +5045,9 @@ nsGlobalWindowInner::ShowSlowScriptDialog(JSContext* aCx,
// script.
RefPtr<nsGlobalWindowOuter> outer = GetOuterWindowInternal();
outer->EnterModalState();
SpinEventLoopUntil(
[&]() { return monitor->IsDebuggerStartupComplete(); });
SpinEventLoopUntil("nsGlobalWindowInner::ShowSlowScriptDialog"_ns, [&]() {
return monitor->IsDebuggerStartupComplete();
});
outer->LeaveModalState();
return ContinueSlowScript;
}

Просмотреть файл

@ -5438,7 +5438,8 @@ Nullable<WindowProxyHolder> nsGlobalWindowOuter::Print(
}();
if (shouldBlock) {
SpinEventLoopUntil([&] { return bc->IsDiscarded(); });
SpinEventLoopUntil("nsGlobalWindowOuter::Print"_ns,
[&] { return bc->IsDiscarded(); });
}
return WindowProxyHolder(std::move(bc));

Просмотреть файл

@ -755,7 +755,8 @@ void FileHandleThreadPool::Shutdown() {
return;
}
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return mShutdownComplete; }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil("FileHandleThreadPool::Shutdown"_ns,
[&]() { return mShutdownComplete; }));
}
nsresult FileHandleThreadPool::Init() {

Просмотреть файл

@ -8124,8 +8124,9 @@ void ConnectionPool::Shutdown() {
return;
}
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
[&]() { return static_cast<bool>(mShutdownComplete); }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil("ConnectionPool::Shutdown"_ns, [&]() {
return static_cast<bool>(mShutdownComplete);
}));
}
void ConnectionPool::Cleanup() {
@ -8939,20 +8940,21 @@ nsresult ConnectionPool::ThreadRunnable::Run() {
}
#endif // DEBUG
DebugOnly<bool> b = SpinEventLoopUntil([&]() -> bool {
if (!mContinueRunning) {
return true;
}
DebugOnly<bool> b =
SpinEventLoopUntil("ConnectionPool::ThreadRunnable"_ns, [&]() -> bool {
if (!mContinueRunning) {
return true;
}
#ifdef DEBUG
if (kDEBUGTransactionThreadSleepMS) {
MOZ_ALWAYS_TRUE(PR_Sleep(PR_MillisecondsToInterval(
kDEBUGTransactionThreadSleepMS)) == PR_SUCCESS);
}
if (kDEBUGTransactionThreadSleepMS) {
MOZ_ALWAYS_TRUE(PR_Sleep(PR_MillisecondsToInterval(
kDEBUGTransactionThreadSleepMS)) == PR_SUCCESS);
}
#endif // DEBUG
return false;
});
return false;
});
// MSVC can't stringify lambdas, so we have to separate the expression
// generating the value from the assert itself.
#if DEBUG

Просмотреть файл

@ -1224,7 +1224,8 @@ nsresult ContentChild::ProvideWindowCommon(
// already have to guard against an inner event loop spinning in the
// non-e10s case because of the need to spin one to create a new chrome
// window.
SpinEventLoopUntil([&]() { return ready; });
SpinEventLoopUntil("ContentChild::ProvideWindowCommon"_ns,
[&]() { return ready; });
MOZ_RELEASE_ASSERT(ready,
"We are on the main thread, so we should not exit this "
"loop without ready being true.");

Просмотреть файл

@ -1220,6 +1220,7 @@ nsresult RequestHelper::StartAndReturnResponse(LSRequestResponse& aResponse) {
"RequestHelper::StartAndReturnResponse::SpinEventLoopTimer"));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"RequestHelper::StartAndReturnResponse"_ns,
[&]() {
if (mCancelled) {
return true;

Просмотреть файл

@ -36,7 +36,7 @@ class FuzzRunner {
[&](uint32_t aDecodeFps) { done = true; }, [&]() { done = true; });
// Wait until benchmark completes.
SpinEventLoopUntil([&]() { return done; });
SpinEventLoopUntil("FuzzRunner::Run"_ns, [&]() { return done; });
return;
}

Просмотреть файл

@ -277,7 +277,10 @@ GeckoMediaPluginServiceParent::Observe(nsISupports* aSubject,
NS_DISPATCH_NORMAL);
// Wait for UnloadPlugins() to do sync shutdown...
SpinEventLoopUntil([&]() { return !mWaitingForPluginsSyncShutdown; });
SpinEventLoopUntil(
"GeckoMediaPluginServiceParent::Observe "
"WaitingForPluginsSyncShutdown"_ns,
[&]() { return !mWaitingForPluginsSyncShutdown; });
} else {
// GMP thread has already shutdown.
MOZ_ASSERT(mPlugins.IsEmpty());

Просмотреть файл

@ -16,7 +16,8 @@ class GMPTestMonitor {
void AwaitFinished() {
MOZ_ASSERT(NS_IsMainThread());
mozilla::SpinEventLoopUntil([&]() { return mFinished; });
mozilla::SpinEventLoopUntil("GMPTestMonitor::AwaitFinished"_ns,
[&]() { return mFinished; });
mFinished = false;
}

Просмотреть файл

@ -1076,7 +1076,8 @@ class CDMStorageTest {
}
void AwaitFinished() {
mozilla::SpinEventLoopUntil([&]() -> bool { return mFinished; });
mozilla::SpinEventLoopUntil("CDMStorageTest::AwaitFinished"_ns,
[&]() -> bool { return mFinished; });
mFinished = false;
}

Просмотреть файл

@ -27,7 +27,8 @@ class DriftCompensatorTest : public ::testing::Test {
bool updated = false;
NS_DispatchToCurrentThread(
NS_NewRunnableFunction(__func__, [&] { updated = true; }));
SpinEventLoopUntil([&] { return updated; });
SpinEventLoopUntil("DriftCompensatorTest::DriftCompensatorTest"_ns,
[&] { return updated; });
}
}

Просмотреть файл

@ -37,7 +37,7 @@ class BenchmarkRunner {
[&]() { done = true; });
// Wait until benchmark completes.
SpinEventLoopUntil([&]() { return done; });
SpinEventLoopUntil("BenchmarkRunner::Run"_ns, [&]() { return done; });
return result;
}

Просмотреть файл

@ -195,7 +195,8 @@ void WaitForShutdown(RefPtr<MediaDataEncoder> aEncoder) {
result = Some(true);
},
[]() { FAIL() << "Shutdown should never be rejected"; });
SpinEventLoopUntil([&result]() { return result; });
SpinEventLoopUntil("TestMediaDataEncoder.cpp:WaitForShutdown"_ns,
[&result]() { return result; });
}
TEST_F(MediaDataEncoderTest, H264Create) {

Просмотреть файл

@ -2938,7 +2938,9 @@ QuotaManager::Observer::Observe(nsISupports* aSubject, const char* aTopic,
return NS_ERROR_FAILURE;
}
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return mShutdownComplete; }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"QuotaManager::Observer::Observe profile-before-change-qm"_ns,
[&]() { return mShutdownComplete; }));
gBasePath = nullptr;
@ -3882,13 +3884,15 @@ void QuotaManager::Shutdown() {
this, SHUTDOWN_FORCE_KILL_TIMEOUT_MS, nsITimer::TYPE_ONE_SHOT,
"quota::QuotaManager::ForceKillTimer"));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([this, &allClientTypes] {
return !gNormalOriginOps &&
std::all_of(allClientTypes.cbegin(), allClientTypes.cend(),
[&self = *this](const auto type) {
return (*self.mClients)[type]->IsShutdownCompleted();
});
}));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"QuotaManager::Shutdown"_ns, [this, &allClientTypes] {
return !gNormalOriginOps &&
std::all_of(
allClientTypes.cbegin(), allClientTypes.cend(),
[&self = *this](const auto type) {
return (*self.mClients)[type]->IsShutdownCompleted();
});
}));
}
for (Client::Type type : allClientTypes) {

Просмотреть файл

@ -449,7 +449,9 @@ StorageObserver::Observe(nsISupports* aSubject, const char* aTopic,
MOZ_ALWAYS_SUCCEEDS(mBackgroundThread[id]->Dispatch(
shutdownRunnable, NS_DISPATCH_NORMAL));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return done; }));
MOZ_ALWAYS_TRUE(SpinEventLoopUntil(
"StorageObserver::Observe profile-before-change"_ns,
[&]() { return done; }));
mBackgroundThread[id] = nullptr;
}

Просмотреть файл

@ -3060,7 +3060,8 @@ void XMLHttpRequestMainThread::SendInternal(const BodyExtractorBase* aBody,
nsAutoSyncOperation sync(suspendedDoc,
SyncOperationBehavior::eSuspendInput);
if (!SpinEventLoopUntil([&]() { return !mFlagSyncLooping; })) {
if (!SpinEventLoopUntil("XMLHttpRequestMainThread::SendInternal"_ns,
[&]() { return !mFlagSyncLooping; })) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}