Bug 1551203, Bug 1551203 - Give ThrottledEventQueues names, r=erahm

Differential Revision: https://phabricator.services.mozilla.com/D30920

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Olli Pettay 2019-05-13 18:12:24 +00:00
Родитель 6ff9c5c08a
Коммит bf41b4d6d7
6 изменённых файлов: 51 добавлений и 22 удалений

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

@ -80,8 +80,14 @@ void TabGroup::EnsureThrottledEventQueues() {
for (size_t i = 0; i < size_t(TaskCategory::Count); i++) {
TaskCategory category = static_cast<TaskCategory>(i);
if (category == TaskCategory::Worker || category == TaskCategory::Timer) {
mEventTargets[i] = ThrottledEventQueue::Create(mEventTargets[i]);
if (category == TaskCategory::Worker) {
mEventTargets[i] =
ThrottledEventQueue::Create(mEventTargets[i],
"TabGroup worker queue");
} else if (category == TaskCategory::Timer) {
mEventTargets[i] =
ThrottledEventQueue::Create(mEventTargets[i],
"TabGroup timer queue");
}
}
}

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

@ -2147,15 +2147,18 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent,
// Throttle events to the main thread using a ThrottledEventQueue specific to
// this tree of worker threads.
mMainThreadEventTargetForMessaging = ThrottledEventQueue::Create(target);
mMainThreadEventTargetForMessaging =
ThrottledEventQueue::Create(target, "Worker queue for messaging");
if (StaticPrefs::dom_worker_use_medium_high_event_queue()) {
mMainThreadEventTarget =
ThrottledEventQueue::Create(GetMainThreadSerialEventTarget(),
"Worker queue",
nsIRunnablePriority::PRIORITY_MEDIUMHIGH);
} else {
mMainThreadEventTarget = mMainThreadEventTargetForMessaging;
}
mMainThreadDebuggeeEventTarget = ThrottledEventQueue::Create(target);
mMainThreadDebuggeeEventTarget =
ThrottledEventQueue::Create(target, "Worker debuggee queue");
if (IsParentWindowPaused() || IsFrozen()) {
MOZ_ALWAYS_SUCCEEDS(mMainThreadDebuggeeEventTarget->SetIsPaused(true));
}

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

@ -62,7 +62,8 @@ TEST(TestEventTargetQI, Thread)
TEST(TestEventTargetQI, ThrottledEventQueue)
{
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
RefPtr<ThrottledEventQueue> thing = ThrottledEventQueue::Create(thread);
RefPtr<ThrottledEventQueue> thing =
ThrottledEventQueue::Create(thread, "test queue");
EXPECT_TRUE(thing);
EXPECT_TRUE(TestQITo<nsISerialEventTarget>(thing));

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

@ -122,7 +122,8 @@ TEST(ThrottledEventQueue, SimpleDispatch)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 1");
Enqueue(throttled, [&]() { log += 'a'; });
ASSERT_TRUE(NS_SUCCEEDED(base->Run()));
@ -137,7 +138,8 @@ TEST(ThrottledEventQueue, MixedDispatch)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 2");
// A ThrottledEventQueue limits its impact on the base target by only queuing
// its next event on the base once the prior event has been run. What it
@ -182,7 +184,8 @@ TEST(ThrottledEventQueue, EnqueueFromRun)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 3");
// When an event from the throttled queue dispatches a new event directly to
// the base target, it is queued after the executor, so the next event from
@ -207,7 +210,8 @@ TEST(ThrottledEventQueue, RunFromRun)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 4");
// Running the event queue from within an event (i.e., a nested event loop)
// does not stall the ThrottledEventQueue.
@ -236,7 +240,8 @@ TEST(ThrottledEventQueue, DropWhileRunning)
// If we drop the event queue while it still has events, they still run.
{
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 5");
Enqueue(throttled, [&]() { log += 'a'; });
}
@ -255,7 +260,8 @@ TEST(ThrottledEventQueue, AwaitIdle)
bool runnableFinished = false; // main thread only
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 6");
// Put an event in the queue so the AwaitIdle might block.
Enqueue(throttled, [&]() { runnableFinished = true; });
@ -318,7 +324,8 @@ TEST(ThrottledEventQueue, AwaitIdleMixed)
bool threadFinished = false;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 7");
Enqueue(throttled, [&]() {
MutexAutoLock lock(mutex);
@ -397,7 +404,8 @@ TEST(ThrottledEventQueue, SimplePauseResume)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 8");
ASSERT_FALSE(throttled->IsPaused());
@ -432,7 +440,8 @@ TEST(ThrottledEventQueue, MixedPauseResume)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 9");
ASSERT_FALSE(throttled->IsPaused());
@ -477,7 +486,8 @@ TEST(ThrottledEventQueue, AwaitIdlePaused)
bool runnableFinished = false; // main thread only
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 10");
ASSERT_TRUE(NS_SUCCEEDED(throttled->SetIsPaused(true)));
@ -545,7 +555,8 @@ TEST(ThrottledEventQueue, ExecutorTransitions)
string log;
auto base = MakeRefPtr<RunnableQueue>();
RefPtr<ThrottledEventQueue> throttled = ThrottledEventQueue::Create(base);
RefPtr<ThrottledEventQueue> throttled =
ThrottledEventQueue::Create(base, "test queue 11");
ASSERT_TRUE(NS_SUCCEEDED(throttled->SetIsPaused(true)));

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

@ -113,18 +113,24 @@ class ThrottledEventQueue::Inner final : public nsISupports {
// Used from any thread; protected by mMutex.
nsCOMPtr<nsIRunnable> mExecutor;
const char* mName;
const uint32_t mPriority;
// True if this queue is currently paused.
// Used from any thread; protected by mMutex.
bool mIsPaused;
explicit Inner(nsISerialEventTarget* aBaseTarget, uint32_t aPriority)
explicit Inner(nsISerialEventTarget* aBaseTarget, const char* aName,
uint32_t aPriority)
: mMutex("ThrottledEventQueue"),
mIdleCondVar(mMutex, "ThrottledEventQueue:Idle"),
mBaseTarget(aBaseTarget),
mName(aName),
mPriority(aPriority),
mIsPaused(false) {}
mIsPaused(false) {
MOZ_ASSERT(mName, "Must pass a valid name!");
}
~Inner() {
#ifdef DEBUG
@ -185,7 +191,7 @@ class ThrottledEventQueue::Inner final : public nsISupports {
return rv;
}
aName.AssignLiteral("non-nsINamed ThrottledEventQueue runnable");
aName.AssignASCII(mName);
return NS_OK;
}
@ -245,12 +251,13 @@ class ThrottledEventQueue::Inner final : public nsISupports {
public:
static already_AddRefed<Inner> Create(nsISerialEventTarget* aBaseTarget,
const char* aName,
uint32_t aPriority) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(ClearOnShutdown_Internal::sCurrentShutdownPhase ==
ShutdownPhase::NotInShutdown);
RefPtr<Inner> ref = new Inner(aBaseTarget, aPriority);
RefPtr<Inner> ref = new Inner(aBaseTarget, aName, aPriority);
return ref.forget();
}
@ -358,11 +365,11 @@ ThrottledEventQueue::ThrottledEventQueue(already_AddRefed<Inner> aInner)
}
already_AddRefed<ThrottledEventQueue> ThrottledEventQueue::Create(
nsISerialEventTarget* aBaseTarget, uint32_t aPriority) {
nsISerialEventTarget* aBaseTarget, const char* aName, uint32_t aPriority) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aBaseTarget);
RefPtr<Inner> inner = Inner::Create(aBaseTarget, aPriority);
RefPtr<Inner> inner = Inner::Create(aBaseTarget, aName, aPriority);
RefPtr<ThrottledEventQueue> ref = new ThrottledEventQueue(inner.forget());
return ref.forget();

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

@ -69,6 +69,7 @@ class ThrottledEventQueue final : public nsISerialEventTarget {
// Create a ThrottledEventQueue for the given target.
static already_AddRefed<ThrottledEventQueue> Create(
nsISerialEventTarget* aBaseTarget,
const char* aName,
uint32_t aPriority = nsIRunnablePriority::PRIORITY_NORMAL);
// Determine if there are any events pending in the queue.