Closed Bug 1154782 Opened 9 years ago Closed 9 years ago

Clean up AbstractThread dispatch semantics

Categories

(Core :: Audio/Video, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla40
Tracking Status
firefox40 --- fixed

People

(Reporter: bholley, Assigned: bholley)

References

Details

Attachments

(5 files)

My branch for bug 1144486 is getting pretty long, so I'm separating out pieces that can land on their own. The main goals of this bug are to automate the assertion of dispatch success and streamline the API entry points on MediaTaskQueue.
Blocks: 1154805
This is nicer than scattering the failure handling to each callsite. Moreover,
this is a necessary step on the road to automatic tail dispatch.
Attachment #8593031 - Flags: review?(jwwang)
I added this several months ago to make MediaPromise dispatch reliable in the
presence of the god-awful Flush() feature of MediaTaskQueue. That feature has
now been restricted to a special subclass (which we should eventually eliminate),
so we can just assert that MediaPromises are never used on those task queues
and simplify the rest of the code.
Attachment #8593032 - Flags: review?(jwwang)
We've been meaning to do this for a while, just haven't gotten around to it.
Attachment #8593033 - Flags: review?(jwwang)
Most of the callers ignore the return values. The MOZ_DIAGNOSTIC_ASSERTS will
tell us if any of these actually fail in practice.
Attachment #8593034 - Flags: review?(jwwang)
Comment on attachment 8593034 [details] [diff] [review]
Part 5 - Align the failure handling of the TemporaryRef Dispatch overload with its companion. v1

Review of attachment 8593034 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/media/fmp4/eme/EMEDecoderModule.cpp
@@ +35,5 @@
>    }
>  
>    virtual nsresult Init() override {
>      MOZ_ASSERT(!mIsShutdown);
> +    mTaskQueue->SyncDispatch(NS_NewRunnableMethod(mDecoder, &MediaDataDecoder::Init));

FYI, I removed the use of SyncDispatch() from EMEDecoderModule.cpp in bug 1154133, and alfredo is removing it from the Gonk PDM in bug 1154512. So soon we can remove MediaTaskQueue::SyncDispatch(). :)
Attachment #8593030 - Flags: review?(jwwang) → review+
Attachment #8593031 - Flags: review?(jwwang) → review+
Comment on attachment 8593032 [details] [diff] [review]
Part 3 - Remove the concept of forced dispatch. v1

Review of attachment 8593032 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/media/MediaPromise.h
@@ +320,5 @@
>      // infrequently.
>      aDispatcher.AssertIsTailDispatcherIfRequired();
>  
>      MutexAutoLock lock(mMutex);
> +    MOZ_ASSERT(aResponseThread->IsDispatchReliable());

Does this assertion mean MediaPromise should be used with reliable dispatcher only?

::: dom/media/MediaTaskQueue.h
@@ +126,5 @@
>  
>    // Monitor that protects the queue and mIsRunning;
>    Monitor mQueueMonitor;
>  
>    struct TaskQueueEntry {

We can just get rid of this class which has a single member.
Attachment #8593032 - Flags: review?(jwwang) → review+
Comment on attachment 8593033 [details] [diff] [review]
Part 4 - Change the canonical internal smart pointer type in MediaTaskQueue to the XPCOM style. v1

Review of attachment 8593033 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/media/MediaTaskQueue.h
@@ +40,5 @@
>    static MediaTaskQueue* GetCurrentQueue() { return sCurrentQueueTLS.get(); }
>  
>    explicit MediaTaskQueue(TemporaryRef<SharedThreadPool> aPool, bool aRequireTailDispatch = false);
>  
> +  nsresult Dispatch(TemporaryRef<nsIRunnable> aRunnable)

Will this change to already_AddRefed<nsIRunnable>?
Attachment #8593033 - Flags: review?(jwwang) → review+
Comment on attachment 8593034 [details] [diff] [review]
Part 5 - Align the failure handling of the TemporaryRef Dispatch overload with its companion. v1

Review of attachment 8593034 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/media/MediaTaskQueue.cpp
@@ +112,1 @@
>    return task->WaitUntilDone();

It looks strange to me to return a void type. Does the coding guidelines talk about it?
Attachment #8593034 - Flags: review?(jwwang) → review+
(In reply to JW Wang [:jwwang] from comment #8)

> Does this assertion mean MediaPromise should be used with reliable
> dispatcher only?

Yes.

> We can just get rid of this class which has a single member.

Good catch.(In reply to JW Wang [:jwwang] from comment #9)

> > +  nsresult Dispatch(TemporaryRef<nsIRunnable> aRunnable)
> 
> Will this change to already_AddRefed<nsIRunnable>?

The point of this overload is to support all the legacy callers that pass RefPtrs rather than ns{COM,Ref}Ptrs. We should fix those at some point, but I wanted to keep this patch small-ish.

(In reply to JW Wang [:jwwang] from comment #10)
> ::: dom/media/MediaTaskQueue.cpp
> @@ +112,1 @@
> >    return task->WaitUntilDone();
> 
> It looks strange to me to return a void type. Does the coding guidelines
> talk about it?

Good catch - fixed.
See Also: → 1168778
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: