Bug 1190495 - Separate FlushableTaskQueue into its own file. r=cpearce
authorBobby Holley <bobbyholley@gmail.com>
Fri, 07 Aug 2015 16:58:43 -0700
changeset 257198 446acb1f222c8c3172d5656c43b877bcc750b750
parent 257197 390bedd839297e15113624aea5e9516250d92a4b
child 257199 9f162f396c26b23cf09b88ccdbc2a21bc5ae0200
push id63564
push userbobbyholley@gmail.com
push dateTue, 11 Aug 2015 12:55:53 +0000
treeherdermozilla-inbound@f78347b683ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1190495
milestone43.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 1190495 - Separate FlushableTaskQueue into its own file. r=cpearce This thing is garbage, and I don't want to hoist it into XPCOM.
dom/media/FlushableTaskQueue.cpp
dom/media/FlushableTaskQueue.h
dom/media/TaskQueue.cpp
dom/media/TaskQueue.h
dom/media/moz.build
dom/media/platforms/PlatformDecoderModule.h
dom/media/webm/WebMReader.h
new file mode 100644
--- /dev/null
+++ b/dom/media/FlushableTaskQueue.cpp
@@ -0,0 +1,51 @@
+/* -*- 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/. */
+
+#include "FlushableTaskQueue.h"
+
+namespace mozilla {
+
+void
+FlushableTaskQueue::Flush()
+{
+  MonitorAutoLock mon(mQueueMonitor);
+  AutoSetFlushing autoFlush(this);
+  FlushLocked();
+  AwaitIdleLocked();
+}
+
+nsresult
+FlushableTaskQueue::FlushAndDispatch(already_AddRefed<nsIRunnable> aRunnable)
+{
+  MonitorAutoLock mon(mQueueMonitor);
+  AutoSetFlushing autoFlush(this);
+  FlushLocked();
+  nsCOMPtr<nsIRunnable> r = dont_AddRef(aRunnable.take());
+  nsresult rv = DispatchLocked(r.forget(), IgnoreFlushing, AssertDispatchSuccess);
+  NS_ENSURE_SUCCESS(rv, rv);
+  AwaitIdleLocked();
+  return NS_OK;
+}
+
+void
+FlushableTaskQueue::FlushLocked()
+{
+  // Make sure there are no tasks for this queue waiting in the caller's tail
+  // dispatcher.
+  MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
+                !AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
+
+  mQueueMonitor.AssertCurrentThreadOwns();
+  MOZ_ASSERT(mIsFlushing);
+
+  // Clear the tasks. If this strikes you as awful, stop using a
+  // FlushableTaskQueue.
+  while (!mTasks.empty()) {
+    mTasks.pop();
+  }
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/FlushableTaskQueue.h
@@ -0,0 +1,53 @@
+/* -*- 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 FlushableTaskQueue_h_
+#define FlushableTaskQueue_h_
+
+#include "mozilla/TaskQueue.h"
+
+//
+// WARNING: THIS CLASS IS DEPRECATED AND GOING AWAY. DO NOT USE IT!
+//
+
+namespace mozilla {
+
+class FlushableTaskQueue : public TaskQueue
+{
+public:
+  explicit FlushableTaskQueue(already_AddRefed<SharedThreadPool> aPool) : TaskQueue(Move(aPool)) {}
+  nsresult FlushAndDispatch(already_AddRefed<nsIRunnable> aRunnable);
+  void Flush();
+
+  bool IsDispatchReliable() override { return false; }
+
+private:
+
+  class MOZ_STACK_CLASS AutoSetFlushing
+  {
+  public:
+    explicit AutoSetFlushing(FlushableTaskQueue* aTaskQueue) : mTaskQueue(aTaskQueue)
+    {
+      mTaskQueue->mQueueMonitor.AssertCurrentThreadOwns();
+      mTaskQueue->mIsFlushing = true;
+    }
+    ~AutoSetFlushing()
+    {
+      mTaskQueue->mQueueMonitor.AssertCurrentThreadOwns();
+      mTaskQueue->mIsFlushing = false;
+    }
+
+  private:
+    FlushableTaskQueue* mTaskQueue;
+  };
+
+  void FlushLocked();
+
+};
+
+}  // namespace mozilla
+
+#endif // FlushableTaskQueue_h_
--- a/dom/media/TaskQueue.cpp
+++ b/dom/media/TaskQueue.cpp
@@ -169,56 +169,16 @@ TaskQueue::BeginShutdown()
   MonitorAutoLock mon(mQueueMonitor);
   mIsShutdown = true;
   nsRefPtr<ShutdownPromise> p = mShutdownPromise.Ensure(__func__);
   MaybeResolveShutdown();
   mon.NotifyAll();
   return p;
 }
 
-void
-FlushableTaskQueue::Flush()
-{
-  MonitorAutoLock mon(mQueueMonitor);
-  AutoSetFlushing autoFlush(this);
-  FlushLocked();
-  AwaitIdleLocked();
-}
-
-nsresult
-FlushableTaskQueue::FlushAndDispatch(already_AddRefed<nsIRunnable> aRunnable)
-{
-  MonitorAutoLock mon(mQueueMonitor);
-  AutoSetFlushing autoFlush(this);
-  FlushLocked();
-  nsCOMPtr<nsIRunnable> r = dont_AddRef(aRunnable.take());
-  nsresult rv = DispatchLocked(r.forget(), IgnoreFlushing, AssertDispatchSuccess);
-  NS_ENSURE_SUCCESS(rv, rv);
-  AwaitIdleLocked();
-  return NS_OK;
-}
-
-void
-FlushableTaskQueue::FlushLocked()
-{
-  // Make sure there are no tasks for this queue waiting in the caller's tail
-  // dispatcher.
-  MOZ_ASSERT_IF(AbstractThread::GetCurrent(),
-                !AbstractThread::GetCurrent()->TailDispatcher().HasTasksFor(this));
-
-  mQueueMonitor.AssertCurrentThreadOwns();
-  MOZ_ASSERT(mIsFlushing);
-
-  // Clear the tasks. If this strikes you as awful, stop using a
-  // FlushableTaskQueue.
-  while (!mTasks.empty()) {
-    mTasks.pop();
-  }
-}
-
 bool
 TaskQueue::IsEmpty()
 {
   MonitorAutoLock mon(mQueueMonitor);
   return mTasks.empty();
 }
 
 bool
--- a/dom/media/TaskQueue.h
+++ b/dom/media/TaskQueue.h
@@ -170,44 +170,11 @@ protected:
     {
     }
     NS_METHOD Run() override;
   private:
     RefPtr<TaskQueue> mQueue;
   };
 };
 
-class FlushableTaskQueue : public TaskQueue
-{
-public:
-  explicit FlushableTaskQueue(already_AddRefed<SharedThreadPool> aPool) : TaskQueue(Move(aPool)) {}
-  nsresult FlushAndDispatch(already_AddRefed<nsIRunnable> aRunnable);
-  void Flush();
-
-  bool IsDispatchReliable() override { return false; }
-
-private:
-
-  class MOZ_STACK_CLASS AutoSetFlushing
-  {
-  public:
-    explicit AutoSetFlushing(FlushableTaskQueue* aTaskQueue) : mTaskQueue(aTaskQueue)
-    {
-      mTaskQueue->mQueueMonitor.AssertCurrentThreadOwns();
-      mTaskQueue->mIsFlushing = true;
-    }
-    ~AutoSetFlushing()
-    {
-      mTaskQueue->mQueueMonitor.AssertCurrentThreadOwns();
-      mTaskQueue->mIsFlushing = false;
-    }
-
-  private:
-    FlushableTaskQueue* mTaskQueue;
-  };
-
-  void FlushLocked();
-
-};
-
 } // namespace mozilla
 
 #endif // TaskQueue_h_
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -105,16 +105,17 @@ EXPORTS += [
     'AudioStream.h',
     'BufferMediaResource.h',
     'CubebUtils.h',
     'DecodedStream.h',
     'DecoderTraits.h',
     'DOMMediaStream.h',
     'EncodedBufferCache.h',
     'FileBlockCache.h',
+    'FlushableTaskQueue.h',
     'Intervals.h',
     'Latency.h',
     'MediaCache.h',
     'MediaData.h',
     'MediaDataDemuxer.h',
     'MediaDecoder.h',
     'MediaDecoderOwner.h',
     'MediaDecoderReader.h',
@@ -202,16 +203,17 @@ UNIFIED_SOURCES += [
     'AudioTrack.cpp',
     'AudioTrackList.cpp',
     'CanvasCaptureMediaStream.cpp',
     'CubebUtils.cpp',
     'DecodedStream.cpp',
     'DOMMediaStream.cpp',
     'EncodedBufferCache.cpp',
     'FileBlockCache.cpp',
+    'FlushableTaskQueue.cpp',
     'GetUserMediaRequest.cpp',
     'GraphDriver.cpp',
     'Latency.cpp',
     'MediaCache.cpp',
     'MediaData.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderStateMachine.cpp',
--- a/dom/media/platforms/PlatformDecoderModule.h
+++ b/dom/media/platforms/PlatformDecoderModule.h
@@ -2,16 +2,17 @@
 /* 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(PlatformDecoderModule_h_)
 #define PlatformDecoderModule_h_
 
+#include "FlushableTaskQueue.h"
 #include "MediaDecoderReader.h"
 #include "mozilla/MozPromise.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "nsTArray.h"
 #include "mozilla/RefPtr.h"
 #include <queue>
 
 namespace mozilla {
--- a/dom/media/webm/WebMReader.h
+++ b/dom/media/webm/WebMReader.h
@@ -3,16 +3,17 @@
 /* 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(WebMReader_h_)
 #define WebMReader_h_
 
 #include <stdint.h>
 
+#include "FlushableTaskQueue.h"
 #include "MediaDecoderReader.h"
 #include "PlatformDecoderModule.h"
 #include "nsAutoRef.h"
 #include "nestegg/nestegg.h"
 
 #define VPX_DONT_DEFINE_STDINT_TYPES
 #include "vpx/vpx_codec.h"