diff --git a/dom/media/AbstractThread.cpp b/dom/media/AbstractThread.cpp index 2938fcbfbe8f..304e79971674 100644 --- a/dom/media/AbstractThread.cpp +++ b/dom/media/AbstractThread.cpp @@ -51,7 +51,7 @@ public: { nsCOMPtr r = aRunnable; AbstractThread* currentThread; - if (aReason != TailDispatch && (currentThread = GetCurrent()) && currentThread->RequiresTailDispatch()) { + if (aReason != TailDispatch && (currentThread = GetCurrent()) && RequiresTailDispatch(currentThread)) { currentThread->TailDispatcher().AddTask(this, r.forget(), aFailureHandling); return; } @@ -101,6 +101,14 @@ private: Maybe mTailDispatcher; }; +bool +AbstractThread::RequiresTailDispatch(AbstractThread* aThread) const +{ + // We require tail dispatch if both the source and destination + // threads support it. + return SupportsTailDispatch() && aThread->SupportsTailDispatch(); +} + AbstractThread* AbstractThread::MainThread() { diff --git a/dom/media/AbstractThread.h b/dom/media/AbstractThread.h index 04b9d7e5a70b..6ff785e55c66 100644 --- a/dom/media/AbstractThread.h +++ b/dom/media/AbstractThread.h @@ -40,7 +40,7 @@ public: // if the caller is not running in an AbstractThread. static AbstractThread* GetCurrent() { return sCurrentThreadTLS.get(); } - AbstractThread(bool aRequireTailDispatch) : mRequireTailDispatch(aRequireTailDispatch) {} + AbstractThread(bool aSupportsTailDispatch) : mSupportsTailDispatch(aSupportsTailDispatch) {} NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbstractThread); @@ -63,9 +63,12 @@ public: // threads which support it. virtual TaskDispatcher& TailDispatcher() = 0; - // Returns true if this task queue requires all dispatches performed by its - // tasks to go through the tail dispatcher. - bool RequiresTailDispatch() const { return mRequireTailDispatch; } + // Returns true if this supports the tail dispatcher. + bool SupportsTailDispatch() const { return mSupportsTailDispatch; } + + // Returns true if this thread requires all dispatches originating from + // aThread go through the tail dispatcher. + bool RequiresTailDispatch(AbstractThread* aThread) const; virtual MediaTaskQueue* AsTaskQueue() { MOZ_CRASH("Not a task queue!"); } virtual nsIThread* AsXPCOMThread() { MOZ_CRASH("Not an XPCOM thread!"); } @@ -82,7 +85,7 @@ protected: // True if we want to require that every task dispatched from tasks running in // this queue go through our queue's tail dispatcher. - const bool mRequireTailDispatch; + const bool mSupportsTailDispatch; }; } // namespace mozilla diff --git a/dom/media/MediaTaskQueue.cpp b/dom/media/MediaTaskQueue.cpp index 4d31a93adff4..15ef1c670cc8 100644 --- a/dom/media/MediaTaskQueue.cpp +++ b/dom/media/MediaTaskQueue.cpp @@ -45,7 +45,7 @@ MediaTaskQueue::DispatchLocked(already_AddRefed aRunnable, { nsCOMPtr r = aRunnable; AbstractThread* currentThread; - if (aReason != TailDispatch && (currentThread = GetCurrent()) && currentThread->RequiresTailDispatch()) { + if (aReason != TailDispatch && (currentThread = GetCurrent()) && RequiresTailDispatch(currentThread)) { currentThread->TailDispatcher().AddTask(this, r.forget(), aFailureHandling); return NS_OK; } diff --git a/dom/media/StateMirroring.h b/dom/media/StateMirroring.h index 69562b977347..1191ebc48b3d 100644 --- a/dom/media/StateMirroring.h +++ b/dom/media/StateMirroring.h @@ -130,7 +130,7 @@ private: : AbstractCanonical(aThread), WatchTarget(aName), mValue(aInitialValue) { MIRROR_LOG("%s [%p] initialized", mName, this); - MOZ_ASSERT(aThread->RequiresTailDispatch(), "Can't get coherency without tail dispatch"); + MOZ_ASSERT(aThread->SupportsTailDispatch(), "Can't get coherency without tail dispatch"); } void AddMirror(AbstractMirror* aMirror) override @@ -303,6 +303,7 @@ private: : AbstractMirror(aThread), WatchTarget(aName), mValue(aInitialValue) { MIRROR_LOG("%s [%p] initialized", mName, this); + MOZ_ASSERT(aThread->SupportsTailDispatch(), "Can't get coherency without tail dispatch"); } operator const T&() @@ -334,6 +335,7 @@ private: MIRROR_LOG("%s [%p] Connecting to %p", mName, this, aCanonical); MOZ_ASSERT(OwnerThread()->IsCurrentThreadIn()); MOZ_ASSERT(!IsConnected()); + MOZ_ASSERT(OwnerThread()->RequiresTailDispatch(aCanonical->OwnerThread()), "Can't get coherency without tail dispatch"); nsCOMPtr r = NS_NewRunnableMethodWithArg>> (aCanonical, &AbstractCanonical::AddMirror, this);