Skip to content

Commit

Permalink
Bug 1767875: Avoid ever waking up more than one thread at a time. r=s…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas-moz committed May 10, 2022
1 parent c090c57 commit ca7f5a1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions xpcom/threads/TaskController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ void TaskController::RunPoolThread() {
task->mIterator = mThreadableTasks.end();
task->mInProgress = true;

if (!mThreadableTasks.empty()) {
// Ensure at least one additional thread is woken up if there are
// more threadable tasks to process. Notifying all threads at once
// isn't actually better for performance since they all need the
// GraphMutex to proceed anyway.
mThreadPoolCV.Notify();
}

bool taskCompleted = false;
{
MutexAutoUnlock unlock(mGraphMutex);
Expand Down Expand Up @@ -812,12 +820,10 @@ bool TaskController::DoExecuteNextTaskOnlyMainThreadInternal(
task->mDependencies.clear();

if (!mThreadableTasks.empty()) {
// Since this could have multiple dependencies thare are not
// restricted to the main thread. Let's wake up our thread pool.
// There is a cost to this, it's possible we will want to wake up
// only as many threads as we have unblocked tasks, but we currently
// have no way to determine that easily.
mThreadPoolCV.NotifyAll();
// We're going to wake up a single thread in our pool. This thread
// is responsible for waking up additional threads in the situation
// where more than one task became available.
mThreadPoolCV.Notify();
}
}

Expand Down

0 comments on commit ca7f5a1

Please sign in to comment.