[V8 Platform] Introduce CallDelayedOnWorkerThread()
GetWorkerThreadsTaskRunner() was about to be phased out [1] but v8 r52818 landed ahead of it. Add CallDelayedOnWorkerThread() to the new worker thread API to support this use case before phasing out GetWorkerThreadsTaskRunner() [1] https://chromium-review.googlesource.com/c/v8/v8/+/978443 Implemented it in d8+cctest+default-platform right away to avoid requiring a non-null Isolate* (and yet another transitional API). R=ahaas@chromium.org, kozyatinskiy@chromium.org Bug: chromium:817421 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel Change-Id: I2bee08fee08cf15a664d31cc6817e21cebe1d140 Reviewed-on: https://chromium-review.googlesource.com/1033584 Commit-Queue: Gabriel Charette <gab@chromium.org> Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Cr-Commit-Position: refs/heads/master@{#52892}
This commit is contained in:
parent
9286358071
commit
4b13a22ff4
@ -395,6 +395,18 @@ class Platform {
|
||||
CallOnWorkerThread(std::move(task));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a task to be invoked on a worker thread after |delay_in_seconds|
|
||||
* expires.
|
||||
* TODO(gab): Make pure virtual when all embedders override this instead of
|
||||
* GetBackgroundTaskRunner().
|
||||
*/
|
||||
virtual void CallDelayedOnWorkerThread(std::unique_ptr<Task> task,
|
||||
double delay_in_seconds) {
|
||||
GetBackgroundTaskRunner(nullptr)->PostDelayedTask(std::move(task),
|
||||
delay_in_seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a task to be invoked on a foreground thread wrt a specific
|
||||
* |isolate|. Tasks posted for the same isolate should be execute in order of
|
||||
|
@ -194,6 +194,11 @@ class PredictablePlatform : public Platform {
|
||||
task->Run();
|
||||
}
|
||||
|
||||
void CallDelayedOnWorkerThread(std::unique_ptr<Task> task,
|
||||
double delay_in_seconds) override {
|
||||
platform_->CallDelayedOnWorkerThread(std::move(task), delay_in_seconds);
|
||||
}
|
||||
|
||||
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
|
||||
platform_->CallOnForegroundThread(isolate, task);
|
||||
}
|
||||
|
@ -417,13 +417,8 @@ protocol::Response V8InspectorImpl::EvaluateScope::setTimeout(double timeout) {
|
||||
if (m_isolate->IsExecutionTerminating()) {
|
||||
return protocol::Response::Error("Execution was terminated");
|
||||
}
|
||||
std::shared_ptr<v8::TaskRunner> taskRunner =
|
||||
v8::debug::GetCurrentPlatform()->GetWorkerThreadsTaskRunner(m_isolate);
|
||||
if (!taskRunner) {
|
||||
return protocol::Response::Error("Timeout is not supported by embedder");
|
||||
}
|
||||
m_cancelToken.reset(new CancelToken());
|
||||
taskRunner->PostDelayedTask(
|
||||
v8::debug::GetCurrentPlatform()->CallDelayedOnWorkerThread(
|
||||
v8::base::make_unique<TerminateTask>(m_isolate, m_cancelToken), timeout);
|
||||
return protocol::Response::OK();
|
||||
}
|
||||
|
@ -203,11 +203,16 @@ void DefaultPlatform::CallOnWorkerThread(std::unique_ptr<Task> task) {
|
||||
GetWorkerThreadsTaskRunner(nullptr)->PostTask(std::move(task));
|
||||
}
|
||||
|
||||
void DefaultPlatform::CallDelayedOnWorkerThread(std::unique_ptr<Task> task,
|
||||
double delay_in_seconds) {
|
||||
GetWorkerThreadsTaskRunner(nullptr)->PostDelayedTask(std::move(task),
|
||||
delay_in_seconds);
|
||||
}
|
||||
|
||||
void DefaultPlatform::CallOnForegroundThread(v8::Isolate* isolate, Task* task) {
|
||||
GetForegroundTaskRunner(isolate)->PostTask(std::unique_ptr<Task>(task));
|
||||
}
|
||||
|
||||
|
||||
void DefaultPlatform::CallDelayedOnForegroundThread(Isolate* isolate,
|
||||
Task* task,
|
||||
double delay_in_seconds) {
|
||||
|
@ -61,6 +61,8 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
|
||||
std::shared_ptr<TaskRunner> GetWorkerThreadsTaskRunner(
|
||||
v8::Isolate* isolate) override;
|
||||
void CallOnWorkerThread(std::unique_ptr<Task> task) override;
|
||||
void CallDelayedOnWorkerThread(std::unique_ptr<Task> task,
|
||||
double delay_in_seconds) override;
|
||||
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override;
|
||||
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
|
||||
double delay_in_seconds) override;
|
||||
|
@ -694,6 +694,11 @@ class TestPlatform : public v8::Platform {
|
||||
old_platform_->CallOnWorkerThread(std::move(task));
|
||||
}
|
||||
|
||||
void CallDelayedOnWorkerThread(std::unique_ptr<v8::Task> task,
|
||||
double delay_in_seconds) override {
|
||||
old_platform_->CallDelayedOnWorkerThread(std::move(task), delay_in_seconds);
|
||||
}
|
||||
|
||||
void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) override {
|
||||
old_platform_->CallOnForegroundThread(isolate, task);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user