diff --git a/xpcom/base/AppShutdown.cpp b/xpcom/base/AppShutdown.cpp index 3cb08d650666..6ae6c4502048 100644 --- a/xpcom/base/AppShutdown.cpp +++ b/xpcom/base/AppShutdown.cpp @@ -227,7 +227,7 @@ void AppShutdown::MaybeFastShutdown(ShutdownPhase aPhase) { nsCOMPtr certStorage = do_GetService("@mozilla.org/security/certstorage;1", &rv); if (NS_SUCCEEDED(rv)) { - SpinEventLoopUntil([&]() { + SpinEventLoopUntil("AppShutdown::MaybeFastShutdown"_ns, [&]() { int32_t remainingOps; nsresult rv = certStorage->GetRemainingOperationCount(&remainingOps); NS_ASSERTION(NS_SUCCEEDED(rv), diff --git a/xpcom/tests/gtest/TestAvailableMemoryWatcherWin.cpp b/xpcom/tests/gtest/TestAvailableMemoryWatcherWin.cpp index 6cd7a1cd27a4..df37b4eb9fb5 100644 --- a/xpcom/tests/gtest/TestAvailableMemoryWatcherWin.cpp +++ b/xpcom/tests/gtest/TestAvailableMemoryWatcherWin.cpp @@ -49,7 +49,7 @@ bool WaitUntil(const ConditionT& aCondition, uint32_t aTimeoutMs) { }, &isTimeout, aTimeoutMs, nsITimer::TYPE_ONE_SHOT, __func__); - SpinEventLoopUntil([&]() -> bool { + SpinEventLoopUntil("xpcom-tests:WaitUntil"_ns, [&]() -> bool { if (isTimeout) { return true; } diff --git a/xpcom/tests/gtest/TestEventPriorities.cpp b/xpcom/tests/gtest/TestEventPriorities.cpp index c85c35bbc61c..874fc81a331e 100644 --- a/xpcom/tests/gtest/TestEventPriorities.cpp +++ b/xpcom/tests/gtest/TestEventPriorities.cpp @@ -64,7 +64,8 @@ TEST(EventPriorities, IdleAfterNormal) NS_DispatchToMainThread(evNormal); MOZ_ALWAYS_TRUE( - SpinEventLoopUntil([&]() { return normalRan == 3 && idleRan == 3; })); + SpinEventLoopUntil("xpcom:TEST(EventPriorities, IdleAfterNormal)"_ns, + [&]() { return normalRan == 3 && idleRan == 3; })); } TEST(EventPriorities, HighNormal) @@ -85,5 +86,6 @@ TEST(EventPriorities, HighNormal) NS_DispatchToMainThread(evHigh); MOZ_ALWAYS_TRUE( - SpinEventLoopUntil([&]() { return normalRan == 3 && highRan == 3; })); + SpinEventLoopUntil("xpcom:TEST(EventPriorities, HighNormal)"_ns, + [&]() { return normalRan == 3 && highRan == 3; })); } diff --git a/xpcom/tests/gtest/TestInputStreamLengthHelper.cpp b/xpcom/tests/gtest/TestInputStreamLengthHelper.cpp index 10357d217f78..96121d7ef4b1 100644 --- a/xpcom/tests/gtest/TestInputStreamLengthHelper.cpp +++ b/xpcom/tests/gtest/TestInputStreamLengthHelper.cpp @@ -27,7 +27,9 @@ TEST(TestInputStreamLengthHelper, NonLengthStream) called = true; }); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return called; })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestInputStreamLengthHelper, NonLengthStream)"_ns, + [&]() { return called; })); } class LengthStream final : public nsIInputStreamLength, @@ -103,7 +105,9 @@ TEST(TestInputStreamLengthHelper, LengthStream) called = true; }); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return called; })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestInputStreamLengthHelper, LengthStream)"_ns, + [&]() { return called; })); } TEST(TestInputStreamLengthHelper, InvalidLengthStream) @@ -117,7 +121,9 @@ TEST(TestInputStreamLengthHelper, InvalidLengthStream) called = true; }); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return called; })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestInputStreamLengthHelper, InvalidLengthStream)"_ns, + [&]() { return called; })); } TEST(TestInputStreamLengthHelper, AsyncLengthStream) @@ -131,7 +137,9 @@ TEST(TestInputStreamLengthHelper, AsyncLengthStream) called = true; }); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return called; })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestInputStreamLengthHelper, AsyncLengthStream)"_ns, + [&]() { return called; })); } TEST(TestInputStreamLengthHelper, FallbackLengthStream) @@ -145,5 +153,7 @@ TEST(TestInputStreamLengthHelper, FallbackLengthStream) called = true; }); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return called; })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestInputStreamLengthHelper, FallbackLengthStream)"_ns, + [&]() { return called; })); } diff --git a/xpcom/tests/gtest/TestMemoryPressure.cpp b/xpcom/tests/gtest/TestMemoryPressure.cpp index 15225719ba81..8435848aa4b8 100644 --- a/xpcom/tests/gtest/TestMemoryPressure.cpp +++ b/xpcom/tests/gtest/TestMemoryPressure.cpp @@ -131,22 +131,26 @@ TEST(MemoryPressure, Singlethread) { RefPtr observer(new MemoryPressureObserver); NS_NotifyOfEventualMemoryPressure(MemoryPressureState::LowMemory); - SpinEventLoopUntil([&observer]() { return observer->GetCount() == 1; }); + SpinEventLoopUntil("xpcom:TEST(MemoryPressure, Singlethread) 1"_ns, + [&observer]() { return observer->GetCount() == 1; }); EXPECT_EQ(observer->Top(), MemoryPressureEventType::LowMemory); observer->Reset(); NS_NotifyOfEventualMemoryPressure(MemoryPressureState::LowMemory); - SpinEventLoopUntil([&observer]() { return observer->GetCount() == 1; }); + SpinEventLoopUntil("xpcom:TEST(MemoryPressure, Singlethread) 2"_ns, + [&observer]() { return observer->GetCount() == 1; }); EXPECT_EQ(observer->Top(), MemoryPressureEventType::LowMemoryOngoing); observer->Reset(); NS_NotifyOfEventualMemoryPressure(MemoryPressureState::LowMemory); - SpinEventLoopUntil([&observer]() { return observer->GetCount() == 1; }); + SpinEventLoopUntil("xpcom:TEST(MemoryPressure, Singlethread) 3"_ns, + [&observer]() { return observer->GetCount() == 1; }); EXPECT_EQ(observer->Top(), MemoryPressureEventType::LowMemoryOngoing); observer->Reset(); NS_NotifyOfEventualMemoryPressure(MemoryPressureState::NoPressure); - SpinEventLoopUntil([&observer]() { return observer->GetCount() == 1; }); + SpinEventLoopUntil("xpcom:TEST(MemoryPressure, Singlethread) 4"_ns, + [&observer]() { return observer->GetCount() == 1; }); EXPECT_EQ(observer->Top(), MemoryPressureEventType::Stop); } @@ -183,6 +187,7 @@ TEST(MemoryPressure, Multithread) // We cannot sleep here because the main thread needs to keep running. SpinEventLoopUntil( + "xpcom:TEST(MemoryPressure, Multithread)"_ns, [&observer]() { return observer->GetCount() >= kNumEventsToValidate; }); shouldContinue = false; diff --git a/xpcom/tests/gtest/TestMultiplexInputStream.cpp b/xpcom/tests/gtest/TestMultiplexInputStream.cpp index e19b21b6fcac..d3c31fb97608 100644 --- a/xpcom/tests/gtest/TestMultiplexInputStream.cpp +++ b/xpcom/tests/gtest/TestMultiplexInputStream.cpp @@ -352,7 +352,9 @@ TEST(MultiplexInputStream, AsyncWait_withEventTarget) ASSERT_FALSE(cb->Called()); // Eventually it is called. - MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); })); + MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil( + "xpcom:TEST(MultiplexInputStream, AsyncWait_withEventTarget)"_ns, + [&]() { return cb->Called(); })); ASSERT_TRUE(cb->Called()); } @@ -393,7 +395,9 @@ TEST(MultiplexInputStream, AsyncWait_withEventTarget_closureOnly) ASSERT_FALSE(cb->Called()); // Eventually it is called. - MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil([&]() { return cb->Called(); })); + MOZ_ALWAYS_TRUE(mozilla::SpinEventLoopUntil( + "xpcom:TEST(MultiplexInputStream, AsyncWait_withEventTarget_closureOnly)"_ns, + [&]() { return cb->Called(); })); ASSERT_TRUE(cb->Called()); } @@ -776,7 +780,9 @@ TEST(MultiplexInputStream, LengthInputStream) rv = afsis->AsyncLengthWait(callback, GetCurrentSerialEventTarget()); ASSERT_EQ(NS_OK, rv); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(MultiplexInputStream, LengthInputStream) 1"_ns, + [&]() { return callback->Called(); })); ASSERT_EQ(buf.Length() * 3, callback->Size()); // Now a negative stream @@ -808,7 +814,9 @@ TEST(MultiplexInputStream, LengthInputStream) rv = afsis->AsyncLengthWait(callback2, GetCurrentSerialEventTarget()); ASSERT_EQ(NS_OK, rv); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback2->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(MultiplexInputStream, LengthInputStream) 2"_ns, + [&]() { return callback2->Called(); })); ASSERT_FALSE(callback1->Called()); ASSERT_TRUE(callback2->Called()); } diff --git a/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp b/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp index b26d48cddea0..292f7df8a29c 100644 --- a/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp +++ b/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp @@ -135,7 +135,9 @@ TEST(TestNonBlockingAsyncInputStream, AsyncWait_Simple) ASSERT_EQ(NS_OK, async->AsyncWait(cb, 0, 0, thread)); ASSERT_FALSE(cb->Called()); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return cb->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestNonBlockingAsyncInputStream, AsyncWait_Simple)"_ns, + [&]() { return cb->Called(); })); ASSERT_TRUE(cb->Called()); // Read works fine. @@ -202,7 +204,9 @@ TEST(TestNonBlockingAsyncInputStream, AsyncWait_ClosureOnly_withEventTarget) ASSERT_EQ(NS_OK, async->Close()); ASSERT_FALSE(cb->Called()); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return cb->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestNonBlockingAsyncInputStream, AsyncWait_ClosureOnly_withEventTarget)"_ns, + [&]() { return cb->Called(); })); ASSERT_TRUE(cb->Called()); } diff --git a/xpcom/tests/gtest/TestSlicedInputStream.cpp b/xpcom/tests/gtest/TestSlicedInputStream.cpp index 269e7f1e2f31..2ce9c22cc10a 100644 --- a/xpcom/tests/gtest/TestSlicedInputStream.cpp +++ b/xpcom/tests/gtest/TestSlicedInputStream.cpp @@ -597,7 +597,9 @@ TEST(TestSlicedInputStream, AsyncInputStreamLength) nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget()); ASSERT_EQ(NS_OK, rv); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestSlicedInputStream, AsyncInputStreamLength)"_ns, + [&]() { return callback->Called(); })); ASSERT_EQ(5, callback->Size()); } @@ -622,7 +624,9 @@ TEST(TestSlicedInputStream, NegativeAsyncInputStreamLength) nsresult rv = qi->AsyncLengthWait(callback, GetCurrentSerialEventTarget()); ASSERT_EQ(NS_OK, rv); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestSlicedInputStream, NegativeAsyncInputStreamLength)"_ns, + [&]() { return callback->Called(); })); ASSERT_EQ(-1, callback->Size()); } @@ -650,7 +654,9 @@ TEST(TestSlicedInputStream, AbortLengthCallback) rv = qi->AsyncLengthWait(callback2, GetCurrentSerialEventTarget()); ASSERT_EQ(NS_OK, rv); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return callback2->Called(); })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(TestSlicedInputStream, AbortLengthCallback)"_ns, + [&]() { return callback2->Called(); })); ASSERT_TRUE(!callback1->Called()); ASSERT_EQ(-1, callback2->Size()); } diff --git a/xpcom/tests/gtest/TestThreadManager.cpp b/xpcom/tests/gtest/TestThreadManager.cpp index 2f23eacb6323..c10ea43b04c8 100644 --- a/xpcom/tests/gtest/TestThreadManager.cpp +++ b/xpcom/tests/gtest/TestThreadManager.cpp @@ -47,7 +47,7 @@ class SpinRunnable final : public Runnable { do_GetService("@mozilla.org/thread-manager;1"); mResult = threadMan->SpinEventLoopUntil( - "gtest TestThreadManager.cpp: SpinRunnable->Run()"_ns, mCondition); + "xpcom:TestThreadManager.cpp:SpinRunnable->Run()"_ns, mCondition); return NS_OK; } diff --git a/xpcom/tests/gtest/TestThreadUtils.cpp b/xpcom/tests/gtest/TestThreadUtils.cpp index df2d885611f5..dd5dd62ae049 100644 --- a/xpcom/tests/gtest/TestThreadUtils.cpp +++ b/xpcom/tests/gtest/TestThreadUtils.cpp @@ -836,29 +836,35 @@ TEST(ThreadUtils, IdleTaskRunner) TimeDuration::FromMilliseconds(3), false, nullptr); // Firstly we wait until the two repeating tasks reach their limits. - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return cnt1 >= 100; })); - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return cnt2 >= 100; })); + MOZ_ALWAYS_TRUE( + SpinEventLoopUntil("xpcom:TEST(ThreadUtils, IdleTaskRunner) cnt1"_ns, + [&]() { return cnt1 >= 100; })); + MOZ_ALWAYS_TRUE( + SpinEventLoopUntil("xpcom:TEST(ThreadUtils, IdleTaskRunner) cnt2"_ns, + [&]() { return cnt2 >= 100; })); // At any point ==> 0 <= cnt3 <= 2 since MayStopProcessing() would return // true when cnt3 >= 2. - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { - if (cnt3 > 2) { - EXPECT_TRUE(false) << "MaybeContinueProcess() doesn't work."; - return true; // Stop on failure. - } - return cnt3 == 2; // Stop finish if we have reached its max value. - })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(ThreadUtils, IdleTaskRunner) cnt3"_ns, [&]() { + if (cnt3 > 2) { + EXPECT_TRUE(false) << "MaybeContinueProcess() doesn't work."; + return true; // Stop on failure. + } + return cnt3 == 2; // Stop finish if we have reached its max value. + })); // At any point ==> 0 <= cnt4 <= 1 since this is a non-repeating // idle runner. - MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { - // At any point: 0 <= cnt4 <= 1 - if (cnt4 > 1) { - EXPECT_TRUE(false) << "The 'mRepeating' flag doesn't work."; - return true; // Stop on failure. - } - return cnt4 == 1; - })); + MOZ_ALWAYS_TRUE(SpinEventLoopUntil( + "xpcom:TEST(ThreadUtils, IdleTaskRunner) cnt4"_ns, [&]() { + // At any point: 0 <= cnt4 <= 1 + if (cnt4 > 1) { + EXPECT_TRUE(false) << "The 'mRepeating' flag doesn't work."; + return true; // Stop on failure. + } + return cnt4 == 1; + })); // The repeating timers require an explicit Cancel() call. runner1->Cancel(); diff --git a/xpcom/threads/SharedThreadPool.cpp b/xpcom/threads/SharedThreadPool.cpp index 76ab34c7be62..d359d85b5332 100644 --- a/xpcom/threads/SharedThreadPool.cpp +++ b/xpcom/threads/SharedThreadPool.cpp @@ -85,7 +85,7 @@ bool SharedThreadPool::IsEmpty() { /* static */ void SharedThreadPool::SpinUntilEmpty() { MOZ_ASSERT(NS_IsMainThread()); - SpinEventLoopUntil([]() -> bool { + SpinEventLoopUntil("SharedThreadPool::SpinUntilEmpty"_ns, []() -> bool { sMonitor->AssertNotCurrentThreadIn(); return IsEmpty(); }); diff --git a/xpcom/threads/ThreadEventTarget.cpp b/xpcom/threads/ThreadEventTarget.cpp index 5c14eca98d32..3e36b000289a 100644 --- a/xpcom/threads/ThreadEventTarget.cpp +++ b/xpcom/threads/ThreadEventTarget.cpp @@ -86,6 +86,7 @@ ThreadEventTarget::Dispatch(already_AddRefed aEvent, // Allows waiting; ensure no locks are held that would deadlock us! SpinEventLoopUntil( + "ThreadEventTarget::Dispatch"_ns, [&, wrapper]() -> bool { return !wrapper->IsPending(); }); return NS_OK; diff --git a/xpcom/threads/nsThreadPool.cpp b/xpcom/threads/nsThreadPool.cpp index 8c1e55ca5324..c86a7b41d893 100644 --- a/xpcom/threads/nsThreadPool.cpp +++ b/xpcom/threads/nsThreadPool.cpp @@ -348,8 +348,9 @@ nsThreadPool::Dispatch(already_AddRefed aEvent, uint32_t aFlags) { new nsThreadSyncDispatch(thread.forget(), std::move(aEvent)); PutEvent(wrapper); - SpinEventLoopUntil( - [&, wrapper]() -> bool { return !wrapper->IsPending(); }); + SpinEventLoopUntil("nsThreadPool::Dispatch"_ns, [&, wrapper]() -> bool { + return !wrapper->IsPending(); + }); } else { NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL || aFlags == NS_DISPATCH_AT_END, "unexpected dispatch flags");