Bug 1409664 - P8. Make explicit shutdown of TaskQueue optional. r=gerald

Summary:
With this change TaskQueue no longer requires an explicit call to BeginShutdown(). The taskqueue will automatically shutdown once it's now longer referenced.

Depends on D1620

Tags: #secure-revision

Bug #: 1409664

Differential Revision: https://phabricator.services.mozilla.com/D1621
This commit is contained in:
Jean-Yves Avenard 2018-06-07 14:46:28 +02:00
Родитель 84177fa544
Коммит 1fc1c669ce
2 изменённых файлов: 6 добавлений и 3 удалений

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

@ -89,8 +89,8 @@ TaskQueue::TaskQueue(already_AddRefed<nsIEventTarget> aTarget,
TaskQueue::~TaskQueue() TaskQueue::~TaskQueue()
{ {
MonitorAutoLock mon(mQueueMonitor); // No one is referencing this TaskQueue anymore, meaning no tasks can be
MOZ_ASSERT(mIsShutdown); // pending as all Runner hold a reference to this TaskQueue.
} }
TaskDispatcher& TaskDispatcher&
@ -178,7 +178,6 @@ TaskQueue::BeginShutdown()
if (AbstractThread* currentThread = AbstractThread::GetCurrent()) { if (AbstractThread* currentThread = AbstractThread::GetCurrent()) {
currentThread->TailDispatchTasksFor(this); currentThread->TailDispatchTasksFor(this);
} }
MonitorAutoLock mon(mQueueMonitor); MonitorAutoLock mon(mQueueMonitor);
mIsShutdown = true; mIsShutdown = true;
RefPtr<ShutdownPromise> p = mShutdownPromise.Ensure(__func__); RefPtr<ShutdownPromise> p = mShutdownPromise.Ensure(__func__);

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

@ -45,6 +45,10 @@ typedef MozPromise<bool, bool, false> ShutdownPromise;
// This arrangement lets you prioritize work by dispatching runnables directly // This arrangement lets you prioritize work by dispatching runnables directly
// to TQ1. You can issue many runnables for important work. Meanwhile the TQ2 // to TQ1. You can issue many runnables for important work. Meanwhile the TQ2
// and TQ3 work will always execute at most one runnable and then yield. // and TQ3 work will always execute at most one runnable and then yield.
//
// A TaskQueue does not require explicit shutdown, however it provides a
// BeginShutdown() method that places TaskQueue in a shut down state and returns
// a promise that gets resolved once all pending tasks have completed
class TaskQueue : public AbstractThread class TaskQueue : public AbstractThread
{ {
class EventTargetWrapper; class EventTargetWrapper;