Bug 1678149 - Use a mozilla::Queue in TaskQueue r=xpcom-reviewers,mccr8

It looks like we can do a mostly direct swap from `std::Queue` to `mozilla::Queue` without needing to expose any new API, so that's what I've done here.

Differential Revision: https://phabricator.services.mozilla.com/D123523
This commit is contained in:
kriswright 2021-08-25 14:10:06 +00:00
parent 69af86dd8e
commit 568caecfff
2 changed files with 10 additions and 11 deletions

View File

@ -59,7 +59,7 @@ nsresult TaskQueue::DispatchLocked(nsCOMPtr<nsIRunnable>& aRunnable,
}
LogRunnable::LogDispatch(aRunnable);
mTasks.push({std::move(aRunnable), aFlags});
mTasks.Push({std::move(aRunnable), aFlags});
if (mIsRunning) {
return NS_OK;
@ -87,7 +87,7 @@ void TaskQueue::AwaitIdleLocked() {
!AbstractThread::GetCurrent()->HasTailTasksFor(this));
mQueueMonitor.AssertCurrentThreadOwns();
MOZ_ASSERT(mIsRunning || mTasks.empty());
MOZ_ASSERT(mIsRunning || mTasks.IsEmpty());
while (mIsRunning) {
mQueueMonitor.Wait();
}
@ -170,7 +170,7 @@ RefPtr<ShutdownPromise> TaskQueue::BeginShutdown() {
bool TaskQueue::IsEmpty() {
MonitorAutoLock mon(mQueueMonitor);
return mTasks.empty();
return mTasks.IsEmpty();
}
bool TaskQueue::IsCurrentThreadIn() const {
@ -183,14 +183,14 @@ nsresult TaskQueue::Runner::Run() {
{
MonitorAutoLock mon(mQueue->mQueueMonitor);
MOZ_ASSERT(mQueue->mIsRunning);
if (mQueue->mTasks.empty()) {
if (mQueue->mTasks.IsEmpty()) {
mQueue->mIsRunning = false;
mQueue->MaybeResolveShutdown();
mon.NotifyAll();
return NS_OK;
}
event = std::move(mQueue->mTasks.front());
mQueue->mTasks.pop();
event = std::move(mQueue->mTasks.FirstElement());
mQueue->mTasks.Pop();
}
MOZ_ASSERT(event.event);
@ -218,7 +218,7 @@ nsresult TaskQueue::Runner::Run() {
{
MonitorAutoLock mon(mQueue->mQueueMonitor);
if (mQueue->mTasks.empty()) {
if (mQueue->mTasks.IsEmpty()) {
// No more events to run. Exit the task runner.
mQueue->mIsRunning = false;
mQueue->MaybeResolveShutdown();
@ -236,7 +236,7 @@ nsresult TaskQueue::Runner::Run() {
{
MonitorAutoLock mon(mQueue->mQueueMonitor);
rv = mQueue->mTarget->Dispatch(
this, mQueue->mTasks.front().flags | NS_DISPATCH_AT_END);
this, mQueue->mTasks.FirstElement().flags | NS_DISPATCH_AT_END);
}
if (NS_FAILED(rv)) {
// Failed to dispatch, shutdown!

View File

@ -7,12 +7,11 @@
#ifndef TaskQueue_h_
#define TaskQueue_h_
#include <queue>
#include "mozilla/AbstractThread.h"
#include "mozilla/Maybe.h"
#include "mozilla/Monitor.h"
#include "mozilla/MozPromise.h"
#include "mozilla/Queue.h"
#include "mozilla/RefPtr.h"
#include "mozilla/TaskDispatcher.h"
#include "nsIDelayedRunnableObserver.h"
@ -166,7 +165,7 @@ class TaskQueue : public AbstractThread,
} TaskStruct;
// Queue of tasks to run.
std::queue<TaskStruct> mTasks;
Queue<TaskStruct> mTasks;
// DelayedRunnables (from DelayedDispatch) that are managed by their
// respective timers, but have not yet run. Accessed only on this