Commit a439e7d8 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Use the new TaskRunner API in the module compiler to post tasks

With this CL both the AsyncCompileJob and the ModuleCompiler use the new
TaskRunner API to post tasks. With the TaskRunner API it is also valid
to post foreground tasks from background tasks.

R=titzer@chromium.org

Change-Id: Ie3a1b0026f834c25540407eb79abdf67071915fb
Reviewed-on: https://chromium-review.googlesource.com/741590Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49419}
parent 68efcd66
......@@ -1004,11 +1004,13 @@ size_t ModuleCompiler::InitializeCompilationUnits(
}
void ModuleCompiler::RestartCompilationTasks() {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
std::shared_ptr<v8::TaskRunner> task_runner =
V8::GetCurrentPlatform()->GetBackgroundTaskRunner(v8_isolate);
base::LockGuard<base::Mutex> guard(&tasks_mutex_);
for (; stopped_compilation_tasks_ > 0; --stopped_compilation_tasks_) {
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new CompilationTask(this),
v8::Platform::ExpectedRuntime::kShortRunningTask);
task_runner->PostTask(base::make_unique<CompilationTask>(this));
}
}
......@@ -2833,6 +2835,10 @@ AsyncCompileJob::AsyncCompileJob(Isolate* isolate,
async_counters_(isolate->async_counters()),
bytes_copy_(std::move(bytes_copy)),
wire_bytes_(bytes_copy_.get(), bytes_copy_.get() + length) {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
v8::Platform* platform = V8::GetCurrentPlatform();
foreground_task_runner_ = platform->GetForegroundTaskRunner(v8_isolate);
background_task_runner_ = platform->GetBackgroundTaskRunner(v8_isolate);
// The handles for the context and promise must be deferred.
DeferredHandleScope deferred(isolate);
context_ = Handle<Context>(*context);
......@@ -2974,11 +2980,7 @@ void AsyncCompileJob::StartForegroundTask() {
++num_pending_foreground_tasks_;
DCHECK_EQ(1, num_pending_foreground_tasks_);
v8::Platform* platform = V8::GetCurrentPlatform();
// TODO(ahaas): This is a CHECK to debug issue 764313.
CHECK(platform);
platform->CallOnForegroundThread(reinterpret_cast<v8::Isolate*>(isolate_),
new CompileTask(this, true));
foreground_task_runner_->PostTask(base::make_unique<CompileTask>(this, true));
}
template <typename Step, typename... Args>
......@@ -2988,8 +2990,8 @@ void AsyncCompileJob::DoSync(Args&&... args) {
}
void AsyncCompileJob::StartBackgroundTask() {
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new CompileTask(this, false), v8::Platform::kShortRunningTask);
background_task_runner_->PostTask(
base::make_unique<CompileTask>(this, false));
}
void AsyncCompileJob::RestartBackgroundTasks() {
......
......@@ -168,6 +168,9 @@ class AsyncCompileJob {
size_t outstanding_units_ = 0;
std::unique_ptr<CompileStep> step_;
CancelableTaskManager background_task_manager_;
std::shared_ptr<v8::TaskRunner> foreground_task_runner_;
std::shared_ptr<v8::TaskRunner> background_task_runner_;
// The number of background tasks which stopped executing within a step.
base::AtomicNumber<size_t> stopped_tasks_{0};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment