Bug 1409664 - P9. Remove AutoTaskQueue and its use r=bryce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 07 Jun 2018 14:50:10 +0200
changeset 424858 dcb3d64ed7616faa35f4605e83f4d2f45f8a4eb4
parent 424857 75ea1b10a4372754e6c6762c1512a617654c642e
child 424859 c9ebc35c018f71dd580f95c0b39ff08c74976367
push id34225
push usershindli@mozilla.com
push dateTue, 03 Jul 2018 21:57:02 +0000
treeherdermozilla-central@987ea0d6a000 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1409664
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1409664 - P9. Remove AutoTaskQueue and its use r=bryce Summary: TaskQueue no longer requires an explicit call to BeginShutdown() as such we no longer have a need for AutoTaskQueue. Depends on D1621 Tags: #secure-revision Bug #: 1409664 Differential Revision: https://phabricator.services.mozilla.com/D1622
dom/media/MediaFormatReader.cpp
dom/media/gtest/TestMP4Demuxer.cpp
dom/media/hls/HLSDemuxer.cpp
dom/media/hls/HLSDemuxer.h
dom/media/mediasource/AutoTaskQueue.h
dom/media/mediasource/MediaSourceDemuxer.cpp
dom/media/mediasource/MediaSourceDemuxer.h
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/mediasource/TrackBuffersManager.h
dom/media/mediasource/moz.build
dom/media/systemservices/MediaUtils.h
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1,28 +1,28 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaFormatReader.h"
 
-#include "AutoTaskQueue.h"
 #include "MediaData.h"
 #include "MediaInfo.h"
 #include "VideoFrameContainer.h"
 #include "VideoUtils.h"
 #include "mozilla/AbstractThread.h"
 #include "mozilla/CDMProxy.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/NotNull.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/SharedThreadPool.h"
 #include "mozilla/StaticPrefs.h"
+#include "mozilla/TaskQueue.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 #include "nsContentUtils.h"
 #include "nsPrintfCString.h"
 #ifdef MOZ_WIDGET_ANDROID
 #include "mozilla/jni/Utils.h"
 #endif
 
@@ -916,19 +916,19 @@ MediaFormatReader::DecoderFactory::DoIni
 // is itself blocked attempting to access the MediaCache or the MediaResource.
 class MediaFormatReader::DemuxerProxy
 {
   using TrackType = TrackInfo::TrackType;
   class Wrapper;
 
 public:
   explicit DemuxerProxy(MediaDataDemuxer* aDemuxer)
-    : mTaskQueue(new AutoTaskQueue(
-        GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
-        "DemuxerProxy::mTaskQueue"))
+    : mTaskQueue(
+        new TaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
+                      "DemuxerProxy::mTaskQueue"))
     , mData(new Data(aDemuxer))
   {
     MOZ_COUNT_CTOR(DemuxerProxy);
   }
 
   ~DemuxerProxy()
   {
     MOZ_COUNT_DTOR(DemuxerProxy);
@@ -1011,17 +1011,17 @@ public:
   bool ShouldComputeStartTime() const
   {
     MOZ_RELEASE_ASSERT(mData && mData->mInitDone);
 
     return mData->mShouldComputeStartTime;
   }
 
 private:
-  const RefPtr<AutoTaskQueue> mTaskQueue;
+  const RefPtr<TaskQueue> mTaskQueue;
   struct Data
   {
     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Data)
 
     explicit Data(MediaDataDemuxer* aDemuxer)
       : mInitDone(false)
       , mDemuxer(aDemuxer)
     {
@@ -1044,17 +1044,17 @@ private:
     ~Data() { }
   };
   RefPtr<Data> mData;
 };
 
 class MediaFormatReader::DemuxerProxy::Wrapper : public MediaTrackDemuxer
 {
 public:
-  Wrapper(MediaTrackDemuxer* aTrackDemuxer, AutoTaskQueue* aTaskQueue)
+  Wrapper(MediaTrackDemuxer* aTrackDemuxer, TaskQueue* aTaskQueue)
     : mMutex("TrackDemuxer Mutex")
     , mTaskQueue(aTaskQueue)
     , mGetSamplesMayBlock(aTrackDemuxer->GetSamplesMayBlock())
     , mInfo(aTrackDemuxer->GetInfo())
     , mTrackDemuxer(aTrackDemuxer)
   {
     DecoderDoctorLogger::LogConstructionAndBase(
       "MediaFormatReader::DemuxerProxy::Wrapper",
@@ -1161,17 +1161,17 @@ public:
     MutexAutoLock lock(mMutex);
     return mBuffered;
   }
 
   void BreakCycles() override { }
 
 private:
   Mutex mMutex;
-  const RefPtr<AutoTaskQueue> mTaskQueue;
+  const RefPtr<TaskQueue> mTaskQueue;
   const bool mGetSamplesMayBlock;
   const UniquePtr<TrackInfo> mInfo;
   // mTrackDemuxer is only ever accessed on demuxer's task queue.
   RefPtr<MediaTrackDemuxer> mTrackDemuxer;
   // All following members are protected by mMutex
   nsresult mNextRandomAccessPointResult = NS_OK;
   TimeUnit mNextRandomAccessPoint;
   TimeIntervals mBuffered;
@@ -1215,17 +1215,17 @@ private:
 };
 
 RefPtr<MediaDataDemuxer::InitPromise>
 MediaFormatReader::DemuxerProxy::Init()
 {
   using InitPromise = MediaDataDemuxer::InitPromise;
 
   RefPtr<Data> data = mData;
-  RefPtr<AutoTaskQueue> taskQueue = mTaskQueue;
+  RefPtr<TaskQueue> taskQueue = mTaskQueue;
   return InvokeAsync(mTaskQueue, __func__,
                      [data, taskQueue]() {
                        if (!data->mDemuxer) {
                          return InitPromise::CreateAndReject(
                            NS_ERROR_DOM_MEDIA_CANCELED, __func__);
                        }
                        return data->mDemuxer->Init();
                      })
--- a/dom/media/gtest/TestMP4Demuxer.cpp
+++ b/dom/media/gtest/TestMP4Demuxer.cpp
@@ -12,18 +12,16 @@
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Unused.h"
 #include "MockMediaResource.h"
 #include "VideoUtils.h"
 
 using namespace mozilla;
 using media::TimeUnit;
 
-class AutoTaskQueue;
-
 #define DO_FAIL [binding]()->void { EXPECT_TRUE(false); binding->mTaskQueue->BeginShutdown(); }
 
 class MP4DemuxerBinding
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MP4DemuxerBinding);
 
   RefPtr<MockMediaResource> resource;
--- a/dom/media/hls/HLSDemuxer.cpp
+++ b/dom/media/hls/HLSDemuxer.cpp
@@ -127,18 +127,18 @@ public:
   Mutex mMutex;
 private:
   ~HLSDemuxerCallbacksSupport() { }
   HLSDemuxer* mDemuxer;
 
 };
 
 HLSDemuxer::HLSDemuxer(int aPlayerId)
-  : mTaskQueue(new AutoTaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
-                                 /* aSupportsTailDispatch = */ false))
+  : mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
+                             /* aSupportsTailDispatch = */ false))
 {
   MOZ_ASSERT(NS_IsMainThread());
   HLSDemuxerCallbacksSupport::Init();
   mJavaCallbacks = GeckoHLSDemuxerWrapper::Callbacks::New();
   MOZ_ASSERT(mJavaCallbacks);
 
   mCallbackSupport = new HLSDemuxerCallbacksSupport(this);
   HLSDemuxerCallbacksSupport::AttachNative(mJavaCallbacks,
--- a/dom/media/hls/HLSDemuxer.h
+++ b/dom/media/hls/HLSDemuxer.h
@@ -2,25 +2,25 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(HLSDemuxer_h_)
 #define HLSDemuxer_h_
 
-#include "AutoTaskQueue.h"
 #include "GeneratedJNINatives.h"
 #include "GeneratedJNIWrappers.h"
 #include "MediaCodec.h"
 #include "MediaDataDemuxer.h"
 #include "MediaDecoder.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Mutex.h"
+#include "mozilla/TaskQueue.h"
 
 #include "VideoUtils.h"
 
 namespace mozilla {
 
 class AbstractThread;
 class MediaResult;
 class HLSTrackDemuxer;
@@ -46,28 +46,28 @@ public:
   bool IsSeekable() const override;
 
   UniquePtr<EncryptionInfo> GetCrypto() override;
 
   bool ShouldComputeStartTime() const override { return true; }
 
   void NotifyDataArrived() override;
 
-  AutoTaskQueue* GetTaskQueue() const { return mTaskQueue; }
+  TaskQueue* GetTaskQueue() const { return mTaskQueue; }
   void OnInitialized(bool aHasAudio, bool aHasVideo);
   void OnError(int aErrorCode);
 
 private:
   media::TimeUnit GetNextKeyFrameTime();
 
   bool OnTaskQueue() const;
   ~HLSDemuxer();
   friend class HLSTrackDemuxer;
 
-  const RefPtr<AutoTaskQueue> mTaskQueue;
+  const RefPtr<TaskQueue> mTaskQueue;
   RefPtr<HLSTrackDemuxer> mAudioDemuxer;
   RefPtr<HLSTrackDemuxer> mVideoDemuxer;
 
   MozPromiseHolder<InitPromise> mInitPromise;
   RefPtr<HLSDemuxerCallbacksSupport> mCallbackSupport;
 
   java::GeckoHLSDemuxerWrapper::Callbacks::GlobalRef mJavaCallbacks;
   java::GeckoHLSDemuxerWrapper::GlobalRef mHLSDemuxerWrapper;
deleted file mode 100644
--- a/dom/media/mediasource/AutoTaskQueue.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef MOZILLA_AUTOTASKQUEUE_H_
-#define MOZILLA_AUTOTASKQUEUE_H_
-
-#include "mozilla/RefPtr.h"
-#include "mozilla/SystemGroup.h"
-#include "mozilla/TaskQueue.h"
-
-class nsIEventTarget;
-
-namespace mozilla {
-
-// A convenience TaskQueue not requiring explicit shutdown.
-class AutoTaskQueue : public AbstractThread
-{
-public:
-  explicit AutoTaskQueue(already_AddRefed<nsIEventTarget> aPool,
-                         bool aSupportsTailDispatch = false)
-    : AbstractThread(aSupportsTailDispatch)
-    , mTaskQueue(new TaskQueue(std::move(aPool), aSupportsTailDispatch))
-    , mMonitor("AutoTaskQueue")
-  {
-  }
-
-  AutoTaskQueue(already_AddRefed<nsIEventTarget> aPool,
-                const char* aName,
-                bool aSupportsTailDispatch = false)
-    : AbstractThread(aSupportsTailDispatch)
-    , mTaskQueue(new TaskQueue(std::move(aPool), aName, aSupportsTailDispatch))
-    , mMonitor("AutoTaskQueue")
-  {
-  }
-
-  TaskDispatcher& TailDispatcher() override
-  {
-    return mTaskQueue->TailDispatcher();
-  }
-
-  MOZ_MUST_USE nsresult
-  Dispatch(already_AddRefed<nsIRunnable> aRunnable,
-           DispatchReason aReason = NormalDispatch) override
-  {
-    return mTaskQueue->Dispatch(std::move(aRunnable), aReason);
-  }
-
-  // Prevent a GCC warning about the other overload of Dispatch being hidden.
-  using AbstractThread::Dispatch;
-
-  // Blocks until all tasks finish executing.
-  void AwaitIdle() { mTaskQueue->AwaitIdle(); }
-
-  bool IsEmpty() { return mTaskQueue->IsEmpty(); }
-
-  // Returns true if the current thread is currently running a Runnable in
-  // the task queue.
-  bool IsCurrentThreadIn() override { return mTaskQueue->IsCurrentThreadIn(); }
-
-  mozilla::Monitor& Monitor() { return mMonitor; }
-
-private:
-  ~AutoTaskQueue() { mTaskQueue->BeginShutdown(); }
-  RefPtr<TaskQueue> mTaskQueue;
-  mozilla::Monitor mMonitor;
-};
-
-} // namespace mozilla
-
-#endif
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -19,18 +19,18 @@
 
 namespace mozilla {
 
 typedef TrackInfo::TrackType TrackType;
 using media::TimeUnit;
 using media::TimeIntervals;
 
 MediaSourceDemuxer::MediaSourceDemuxer(AbstractThread* aAbstractMainThread)
-  : mTaskQueue(new AutoTaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
-                                 "MediaSourceDemuxer::mTaskQueue"))
+  : mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
+                             "MediaSourceDemuxer::mTaskQueue"))
   , mMonitor("MediaSourceDemuxer")
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 constexpr TimeUnit MediaSourceDemuxer::EOS_FUZZ;
 
 RefPtr<MediaSourceDemuxer::InitPromise>
--- a/dom/media/mediasource/MediaSourceDemuxer.h
+++ b/dom/media/mediasource/MediaSourceDemuxer.h
@@ -2,25 +2,25 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(MediaSourceDemuxer_h_)
 #define MediaSourceDemuxer_h_
 
-#include "mozilla/Atomics.h"
-#include "mozilla/Maybe.h"
-#include "mozilla/Monitor.h"
-#include "AutoTaskQueue.h"
-
 #include "MediaDataDemuxer.h"
 #include "MediaResource.h"
 #include "MediaSource.h"
 #include "TrackBuffersManager.h"
+#include "mozilla/Atomics.h"
+#include "mozilla/Maybe.h"
+#include "mozilla/Monitor.h"
+#include "mozilla/TaskQueue.h"
+
 
 namespace mozilla {
 
 class AbstractThread;
 class MediaResult;
 class MediaSourceTrackDemuxer;
 
 DDLoggedTypeDeclNameAndBase(MediaSourceDemuxer, MediaDataDemuxer);
@@ -44,17 +44,17 @@ public:
 
   UniquePtr<EncryptionInfo> GetCrypto() override;
 
   bool ShouldComputeStartTime() const override { return false; }
 
   /* interface for TrackBuffersManager */
   void AttachSourceBuffer(RefPtr<TrackBuffersManager>& aSourceBuffer);
   void DetachSourceBuffer(RefPtr<TrackBuffersManager>& aSourceBuffer);
-  AutoTaskQueue* GetTaskQueue() { return mTaskQueue; }
+  TaskQueue* GetTaskQueue() { return mTaskQueue; }
   void NotifyInitDataArrived();
 
   // Returns a string describing the state of the MediaSource internal
   // buffered data. Used for debugging purposes.
   void GetMozDebugReaderData(nsACString& aString);
 
   void AddSizeOfResources(MediaSourceDecoder::ResourceSizes* aSizes);
 
@@ -73,17 +73,17 @@ private:
   TrackInfo* GetTrackInfo(TrackInfo::TrackType);
   void DoAttachSourceBuffer(RefPtr<TrackBuffersManager>&& aSourceBuffer);
   void DoDetachSourceBuffer(RefPtr<TrackBuffersManager>&& aSourceBuffer);
   bool OnTaskQueue()
   {
     return !GetTaskQueue() || GetTaskQueue()->IsCurrentThreadIn();
   }
 
-  RefPtr<AutoTaskQueue> mTaskQueue;
+  RefPtr<TaskQueue> mTaskQueue;
   nsTArray<RefPtr<MediaSourceTrackDemuxer>> mDemuxers;
 
   nsTArray<RefPtr<TrackBuffersManager>> mSourceBuffers;
 
   MozPromiseHolder<InitPromise> mInitPromise;
 
   // Monitor to protect members below across multiple threads.
   mutable Monitor mMonitor;
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -172,17 +172,17 @@ TrackBuffersManager::DoAppendData(alread
 }
 
 void
 TrackBuffersManager::QueueTask(SourceBufferTask* aTask)
 {
   // The source buffer is a wrapped native, it would be unlinked twice and so
   // the TrackBuffersManager::Detach() would also be called twice. Since the
   // detach task has been done before, we could ignore this task.
-  RefPtr<AutoTaskQueue> taskQueue = GetTaskQueueSafe();
+  RefPtr<TaskQueue> taskQueue = GetTaskQueueSafe();
   if (!taskQueue) {
     MOZ_ASSERT(aTask->GetType() == SourceBufferTask::Type::Detach,
                "only detach task could happen here!");
     MSE_DEBUG("Could not queue the task '%s' without task queue",
               aTask->GetTypeName());
     return;
   }
 
--- a/dom/media/mediasource/TrackBuffersManager.h
+++ b/dom/media/mediasource/TrackBuffersManager.h
@@ -6,17 +6,17 @@
 
 #ifndef MOZILLA_TRACKBUFFERSMANAGER_H_
 #define MOZILLA_TRACKBUFFERSMANAGER_H_
 
 #include "mozilla/Atomics.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/NotNull.h"
-#include "AutoTaskQueue.h"
+#include "mozilla/TaskQueue.h"
 
 #include "MediaContainerType.h"
 #include "MediaData.h"
 #include "MediaDataDemuxer.h"
 #include "MediaResult.h"
 #include "MediaSourceDecoder.h"
 #include "SourceBufferTask.h"
 #include "TimeUnits.h"
@@ -460,25 +460,25 @@ private:
       default:
         return mAudioTracks;
     }
   }
   TrackData mVideoTracks;
   TrackData mAudioTracks;
 
   // TaskQueue methods and objects.
-  RefPtr<AutoTaskQueue> GetTaskQueueSafe() const
+  RefPtr<TaskQueue> GetTaskQueueSafe() const
   {
     MutexAutoLock mut(mMutex);
     return mTaskQueue;
   }
   NotNull<AbstractThread*> TaskQueueFromTaskQueue() const
   {
 #ifdef DEBUG
-    RefPtr<AutoTaskQueue> taskQueue = GetTaskQueueSafe();
+    RefPtr<TaskQueue> taskQueue = GetTaskQueueSafe();
     MOZ_ASSERT(taskQueue && taskQueue->IsCurrentThreadIn());
 #endif
     return WrapNotNull(mTaskQueue.get());
   }
   bool OnTaskQueue() const
   {
     auto taskQueue = TaskQueueFromTaskQueue();
     return taskQueue->IsCurrentThreadIn();
@@ -528,17 +528,17 @@ private:
   };
   Atomic<EvictionState> mEvictionState;
 
   // Monitor to protect following objects accessed across multiple threads.
   mutable Mutex mMutex;
   // mTaskQueue is only ever written after construction on the task queue.
   // As such, it can be accessed while on task queue without the need for the
   // mutex.
-  RefPtr<AutoTaskQueue> mTaskQueue;
+  RefPtr<TaskQueue> mTaskQueue;
   // Stable audio and video track time ranges.
   media::TimeIntervals mVideoBufferedRanges;
   media::TimeIntervals mAudioBufferedRanges;
   // MediaInfo of the first init segment read.
   MediaInfo mInfo;
 };
 
 } // namespace mozilla
--- a/dom/media/mediasource/moz.build
+++ b/dom/media/mediasource/moz.build
@@ -2,17 +2,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 MOCHITEST_MANIFESTS += ['test/mochitest.ini']
 
 EXPORTS += [
     'AsyncEventRunner.h',
-    'AutoTaskQueue.h',
     'MediaSourceDecoder.h',
     'MediaSourceDemuxer.h',
     'SourceBufferAttributes.h',
     'SourceBufferTask.h',
     'TrackBuffersManager.h',
 ]
 
 EXPORTS.mozilla.dom += [
--- a/dom/media/systemservices/MediaUtils.h
+++ b/dom/media/systemservices/MediaUtils.h
@@ -2,22 +2,22 @@
 /* vim: set sw=2 ts=8 et ft=cpp : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_MediaUtils_h
 #define mozilla_MediaUtils_h
 
-#include "AutoTaskQueue.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/MozPromise.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/SharedThreadPool.h"
+#include "mozilla/TaskQueue.h"
 #include "mozilla/UniquePtr.h"
 #include "nsCOMPtr.h"
 #include "nsIAsyncShutdown.h"
 #include "nsISupportsImpl.h"
 #include "nsThreadUtils.h"
 
 class nsIEventTarget;
 
@@ -433,20 +433,19 @@ template<typename ResolveValueType,
          typename RejectFunction>
 void
 Await(
   already_AddRefed<nsIEventTarget> aPool,
   RefPtr<MozPromise<ResolveValueType, RejectValueType, true>> aPromise,
   ResolveFunction&& aResolveFunction,
   RejectFunction&& aRejectFunction)
 {
-  RefPtr<AutoTaskQueue> taskQueue =
-    new AutoTaskQueue(std::move(aPool), "MozPromiseAwait");
-  // We can't use a Monitor allocated on the stack (see bug 1426067)
-  Monitor& mon = taskQueue->Monitor();
+  RefPtr<TaskQueue> taskQueue =
+    new TaskQueue(std::move(aPool), "MozPromiseAwait");
+  Monitor mon(__func__);
   bool done = false;
 
   aPromise->Then(taskQueue,
                  __func__,
                  [&](ResolveValueType&& aResolveValue) {
                    MonitorAutoLock lock(mon);
                    aResolveFunction(std::forward<ResolveValueType>(aResolveValue));
                    done = true;
@@ -466,20 +465,19 @@ Await(
 }
 
 template<typename ResolveValueType, typename RejectValueType, bool Excl>
 typename MozPromise<ResolveValueType, RejectValueType, Excl>::
   ResolveOrRejectValue
 Await(already_AddRefed<nsIEventTarget> aPool,
       RefPtr<MozPromise<ResolveValueType, RejectValueType, Excl>> aPromise)
 {
-  RefPtr<AutoTaskQueue> taskQueue =
-    new AutoTaskQueue(std::move(aPool), "MozPromiseAwait");
-  // We can't use a Monitor allocated on the stack (see bug 1426067)
-  Monitor& mon = taskQueue->Monitor();
+  RefPtr<TaskQueue> taskQueue =
+    new TaskQueue(std::move(aPool), "MozPromiseAwait");
+  Monitor mon(__func__);
   bool done = false;
 
   typename MozPromise<ResolveValueType, RejectValueType, Excl>::ResolveOrRejectValue val;
   aPromise->Then(taskQueue,
                  __func__,
                  [&](ResolveValueType aResolveValue) {
                    val.SetResolve(std::move(aResolveValue));
                    MonitorAutoLock lock(mon);
@@ -513,36 +511,38 @@ void
 AwaitAll(already_AddRefed<nsIEventTarget> aPool,
          nsTArray<RefPtr<MozPromise<ResolveValueType, RejectValueType, true>>>&
            aPromises,
          ResolveFunction&& aResolveFunction,
          RejectFunction&& aRejectFunction)
 {
   typedef MozPromise<ResolveValueType, RejectValueType, true> Promise;
   RefPtr<nsIEventTarget> pool = aPool;
-  RefPtr<AutoTaskQueue> taskQueue =
-    new AutoTaskQueue(do_AddRef(pool), "MozPromiseAwaitAll");
-  RefPtr<typename Promise::AllPromiseType> p = Promise::All(taskQueue, aPromises);
-  Await(pool.forget(), p, std::move(aResolveFunction), std::move(aRejectFunction));
+  RefPtr<TaskQueue> taskQueue =
+    new TaskQueue(do_AddRef(pool), "MozPromiseAwaitAll");
+  RefPtr<typename Promise::AllPromiseType> p =
+    Promise::All(taskQueue, aPromises);
+  Await(
+    pool.forget(), p, std::move(aResolveFunction), std::move(aRejectFunction));
 }
 
 // Note: only works with exclusive MozPromise, as Promise::All would attempt
 // to perform copy of nsTArrays which are disallowed.
 template<typename ResolveValueType, typename RejectValueType>
 typename MozPromise<ResolveValueType,
                     RejectValueType,
                     true>::AllPromiseType::ResolveOrRejectValue
 AwaitAll(already_AddRefed<nsIEventTarget> aPool,
          nsTArray<RefPtr<MozPromise<ResolveValueType, RejectValueType, true>>>&
            aPromises)
 {
   typedef MozPromise<ResolveValueType, RejectValueType, true> Promise;
   RefPtr<nsIEventTarget> pool = aPool;
-  RefPtr<AutoTaskQueue> taskQueue =
-    new AutoTaskQueue(do_AddRef(pool), "MozPromiseAwaitAll");
+  RefPtr<TaskQueue> taskQueue =
+    new TaskQueue(do_AddRef(pool), "MozPromiseAwaitAll");
   RefPtr<typename Promise::AllPromiseType> p =
     Promise::All(taskQueue, aPromises);
   return Await(pool.forget(), p);
 }
 
 } // namespace media
 } // namespace mozilla
 
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -7,17 +7,16 @@
 
 #include "MediaPipeline.h"
 
 #include <inttypes.h>
 #include <math.h>
 
 #include "AudioSegment.h"
 #include "AudioConverter.h"
-#include "AutoTaskQueue.h"
 #include "CSFLog.h"
 #include "DOMMediaStream.h"
 #include "ImageContainer.h"
 #include "ImageTypes.h"
 #include "Layers.h"
 #include "LayersLogging.h"
 #include "MediaEngine.h"
 #include "MediaPipelineFilter.h"
@@ -30,16 +29,17 @@
 #include "VideoSegment.h"
 #include "VideoStreamTrack.h"
 #include "VideoUtils.h"
 #include "libyuv/convert.h"
 #include "mozilla/PeerIdentity.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/SharedThreadPool.h"
 #include "mozilla/Sprintf.h"
+#include "mozilla/TaskQueue.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "mozilla/dom/RTCStatsReportBinding.h"
 #include "mozilla/gfx/Point.h"
 #include "mozilla/gfx/Types.h"
 #include "nsError.h"
 #include "nsThreadUtils.h"
 #include "nspr.h"
@@ -111,18 +111,18 @@ protected:
 class VideoFrameConverter
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoFrameConverter)
 
   VideoFrameConverter()
     : mLength(0)
     , mTaskQueue(
-        new AutoTaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
-                          "VideoFrameConverter"))
+        new TaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
+                      "VideoFrameConverter"))
     , mBufferPool(false, CONVERTER_BUFFER_POOL_SIZE)
     , mLastImage(-1) // -1 is not a guaranteed invalid serial. See bug 1262134.
 #ifdef DEBUG
     , mThrottleCount(0)
     , mThrottleRecord(0)
 #endif
     , mMutex("VideoFrameConverter")
   {
@@ -453,17 +453,17 @@ protected:
                 Stringify(surf->GetFormat()).c_str());
     webrtc::VideoFrame frame(buffer,
                              0, 0, // not setting timestamps
                              webrtc::kVideoRotation_0);
     VideoFrameConverted(frame);
   }
 
   Atomic<int32_t, Relaxed> mLength;
-  const RefPtr<AutoTaskQueue> mTaskQueue;
+  const RefPtr<TaskQueue> mTaskQueue;
   webrtc::I420BufferPool mBufferPool;
 
   // Written and read from the queueing thread (normally MSG).
   int32_t mLastImage;       // serial number of last Image
   TimeStamp mLastFrameSent; // The time we sent the last frame.
 #ifdef DEBUG
   uint32_t mThrottleCount;
   uint32_t mThrottleRecord;
@@ -481,18 +481,18 @@ protected:
 class AudioProxyThread
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioProxyThread)
 
   explicit AudioProxyThread(AudioSessionConduit* aConduit)
     : mConduit(aConduit)
     , mTaskQueue(
-        new AutoTaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
-                          "AudioProxy"))
+        new TaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
+                      "AudioProxy"))
     , mAudioConverter(nullptr)
   {
     MOZ_ASSERT(mConduit);
     MOZ_COUNT_CTOR(AudioProxyThread);
   }
 
   // This function is the identity if aInputRate is supported.
   // Else, it returns a rate that is supported, that ensure no loss in audio
@@ -659,17 +659,17 @@ protected:
     // reference We don't need to worry about runnables still trying to access
     // the conduit, since the runnables hold a ref to AudioProxyThread.
     NS_ReleaseOnMainThreadSystemGroup("AudioProxyThread::mConduit",
                                       mConduit.forget());
     MOZ_COUNT_DTOR(AudioProxyThread);
   }
 
   RefPtr<AudioSessionConduit> mConduit;
-  const RefPtr<AutoTaskQueue> mTaskQueue;
+  const RefPtr<TaskQueue> mTaskQueue;
   // Only accessed on mTaskQueue
   UniquePtr<AudioPacketizer<int16_t, int16_t>> mPacketizer;
   // A buffer to hold a single packet of audio.
   UniquePtr<int16_t[]> mPacket;
   nsTArray<int16_t> mInterleavedAudio;
   AlignedShortBuffer mOutputAudio;
   UniquePtr<AudioConverter> mAudioConverter;
 };
@@ -1973,18 +1973,18 @@ public:
     // This is an artificial limitation, it would however require more changes
     // to support any rates.
     // If the sampling rate is not-supported, we will use 48kHz instead.
     , mRate(static_cast<AudioSessionConduit*>(mConduit.get())
                 ->IsSamplingFreqSupported(mSource->GraphRate())
               ? mSource->GraphRate()
               : WEBRTC_MAX_SAMPLE_RATE)
     , mTaskQueue(
-        new AutoTaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
-                          "AudioPipelineListener"))
+        new TaskQueue(GetMediaThreadPool(MediaThreadType::WEBRTC_DECODER),
+                      "AudioPipelineListener"))
     , mLastLog(0)
   {
     AddTrackToSource(mRate);
   }
 
   // Implement MediaStreamListener
   void NotifyPull(MediaStreamGraph* aGraph,
                   StreamTime aDesiredTime) override
@@ -2096,17 +2096,17 @@ private:
         // buffer - but don't i-loop!
         break;
       }
     }
   }
 
   RefPtr<MediaSessionConduit> mConduit;
   const TrackRate mRate;
-  const RefPtr<AutoTaskQueue> mTaskQueue;
+  const RefPtr<TaskQueue> mTaskQueue;
   // Graph's current sampling rate
   TrackTicks mLastLog = 0; // mPlayedTicks when we last logged
 };
 
 MediaPipelineReceiveAudio::MediaPipelineReceiveAudio(
   const std::string& aPc,
   nsCOMPtr<nsIEventTarget> aMainThread,
   nsCOMPtr<nsIEventTarget> aStsThread,