Worker: Introduce per-global-scope task scheduler

Desktop / Chromium - nhiroki [chromium.org] - 19 April 2017 21:05 EDT

This CL introduces WorkerGlobalScopeScheduler to make it simpler and saner to manage tasks on worker threads.

Before this CL, tasks on worker threads were always pushed into the thread's default task queue, they should be handled in different ways based on their task types though. For example, worker tasks shouldn't run after the global scope is closed, while thread control tasks should run even after that. To achieve it, worker tasks were always wrapped with WorkerThread's method to check the current thread state. This was so tricky.

After this CL, each global scope has its own task queues like per-frame task scheduler. Worker tasks are pushed into the task queues, control tasks are still pushed into the thread's default task queue though. Thanks to this separation, we can abort only worker tasks by simply unregistering the queues when a global scope is closed.

In addition, this CL unifies postTask interfaces into TaskRunnerHelper (issue 694914), and enables any threads to post a task to worker threads because of thread-safe refcounted WebTaskRunner.

BUG=670534, 694914, 710364

Review-Url: https://codereview.chromium.org/2806623004 Cr-Commit-Position: refs/heads/master@{#465841}

d56a35f Worker: Introduce per-global-scope task scheduler
.../WebKit/Source/core/dom/TaskRunnerHelper.cpp | 60 ++++++++-
.../WebKit/Source/core/dom/TaskRunnerHelper.h | 10 ++
.../Source/core/loader/ThreadableLoaderTest.cpp | 4 +-
.../Source/core/workers/DedicatedWorkerTest.cpp | 21 ++--
.../core/workers/InProcessWorkerMessagingProxy.cpp | 7 +-
.../core/workers/InProcessWorkerObjectProxy.cpp | 7 +-
.../core/workers/ThreadedMessagingProxyBase.cpp | 4 +-
.../Source/core/workers/ThreadedWorkletTest.cpp | 19 +--
.../Source/core/workers/WorkerEventQueue.cpp | 15 ++-
.../Source/core/workers/WorkerGlobalScope.cpp | 3 +-
.../core/workers/WorkerOrWorkletGlobalScope.cpp | 14 ++-
.../WebKit/Source/core/workers/WorkerThread.cpp | 87 +++++--------
.../WebKit/Source/core/workers/WorkerThread.h | 22 ++--
.../time_zone_monitor/TimeZoneMonitorClient.cpp | 8 +-
.../webaudio/AudioWorkletGlobalScopeTest.cpp | 40 +++---
third_party/WebKit/Source/platform/BUILD.gn | 3 +
.../scheduler/child/compositor_worker_scheduler.cc | 136 +++------------------
.../scheduler/child/compositor_worker_scheduler.h | 6 +-
.../scheduler/child/web_task_runner_impl.h | 2 +
.../platform/scheduler/child/webthread_base.cc | 4 +-
.../child/webthread_impl_for_worker_scheduler.cc | 4 +-
.../child/webthread_impl_for_worker_scheduler.h | 7 ++
.../child/worker_global_scope_scheduler.cc | 34 ++++++
.../child/worker_global_scope_scheduler.h | 49 ++++++++
.../worker_global_scope_scheduler_unittest.cc | 91 ++++++++++++++
.../platform/scheduler/child/worker_scheduler.cc | 13 +-
.../platform/scheduler/child/worker_scheduler.h | 10 +-
.../scheduler/child/worker_scheduler_impl.cc | 43 ++++---
.../scheduler/child/worker_scheduler_impl.h | 2 -
.../WebKit/Source/web/WebEmbeddedWorkerImpl.cpp | 4 +-
.../WebKit/Source/web/WebSharedWorkerImpl.cpp | 15 ++-
31 files changed, 467 insertions(+), 277 deletions(-)

Upstream: git.chromium.org


  • Share