Closed Bug 1055925 Opened 10 years ago Closed 10 years ago

Refactor promise to make it simpler to run async task on main and worker thread

Categories

(Core :: DOM: Core & HTML, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: xyuan, Assigned: xyuan)

References

Details

Attachments

(1 file, 1 obsolete file)

The promise should be resolved asynchronously and a few async tasks are created. 
With current implementation, each task needs two different classes, one for the promise running on the main thread and the other for that on the work thread.

For example, we have the pair of PromiseTask[1] and WorkerPromiseTask[2], and the pair of PromiseResolverTask[3] and WorkerPromiseResolverTask[4].

Each task pair classes do the same work except for thread specific code.

I want to strip out thread specific code from each task pair and merge each pair into one. So that we only need to create one class for each task and don't need to handle thread specific code individually for each task.

This change will faciliate bug 1035060, where we need to create new async task for abort callback.

[1] https://github.com/mozilla/gecko-dev/blob/28a6cdcb51ae87d94c054fa9d8414b919ac93afa/dom/promise/Promise.cpp#L1021
[2] https://github.com/mozilla/gecko-dev/blob/28a6cdcb51ae87d94c054fa9d8414b919ac93afa/dom/promise/Promise.cpp#L1026
[3] https://github.com/mozilla/gecko-dev/blob/28a6cdcb51ae87d94c054fa9d8414b919ac93afa/dom/promise/Promise.cpp#L1218
[4] https://github.com/mozilla/gecko-dev/blob/28a6cdcb51ae87d94c054fa9d8414b919ac93afa/dom/promise/Promise.cpp#L1224
Attached patch refactor task (obsolete) — Splinter Review
DispatchToMainOrWorkerThread is added to enable the task runnable of the main thread to run on the worker thread. So we don't need the worker runnable any more. 

This patch removes the worker task runnables, such as WorkerPromiseTask and WorkerPromiseResolverTask, and keeps only one runnable for each task.
Attachment #8475697 - Flags: review?(nsm.nikhil)
Comment on attachment 8475697 [details] [diff] [review]
refactor task

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

Nice patch!

::: dom/promise/Promise.cpp
@@ +939,5 @@
> +/* static */ void
> +Promise::DispatchToMainOrWorkerThread(nsIRunnable* aRunnable)
> +{
> +  MOZ_ASSERT(aRunnable);
> +  if (MOZ_LIKELY(NS_IsMainThread())) {

Could you remove MOZ_LIKELY unless there is a proven performance advantage?
Attachment #8475697 - Flags: review?(nsm.nikhil) → review+
https://hg.mozilla.org/mozilla-central/rev/7edb1ae2588f
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: