Commit cb082a60 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[platform] Provide NewDefaultJobHandle function

This will allow embedders to actually instantiate the {DefaultJobHandle}
as suggested in the comment. Node currently implements {PostJob()} by
just returning a nullptr. After this change, it can use the new
{NewDefaultJobHandle} function and we can actually start using this API
in v8.

R=adamk@chromium.org

Bug: v8:10723
Change-Id: I4b31a640d0edc7e7207d1df95e683465dfaaaeff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2304812Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68934}
parent 69553fea
......@@ -43,6 +43,16 @@ V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
InProcessStackDumping::kDisabled,
std::unique_ptr<v8::TracingController> tracing_controller = {});
/**
* Returns a new instance of the default v8::JobHandle implementation.
*
* The job will be executed by spawning up to |num_worker_threads| many worker
* threads on the provided |platform| with the given |priority|.
*/
V8_PLATFORM_EXPORT std::unique_ptr<v8::JobHandle> NewDefaultJobHandle(
v8::Platform* platform, v8::TaskPriority priority,
std::unique_ptr<v8::JobTask> job_task, size_t num_worker_threads);
/**
* Pumps the message loop for the given isolate.
*
......
......@@ -535,9 +535,8 @@ class Platform {
* libplatform looks like:
* std::unique_ptr<JobHandle> PostJob(
* TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
* return std::make_unique<DefaultJobHandle>(
* std::make_shared<DefaultJobState>(
* this, std::move(job_task), kNumThreads));
* return v8::platform::NewDefaultJobHandle(
* this, priority, std::move(job_task), NumberOfWorkerThreads());
* }
*/
virtual std::unique_ptr<JobHandle> PostJob(
......
......@@ -45,6 +45,13 @@ std::unique_ptr<v8::Platform> NewDefaultPlatform(
return platform;
}
V8_PLATFORM_EXPORT std::unique_ptr<JobHandle> NewDefaultJobHandle(
Platform* platform, TaskPriority priority,
std::unique_ptr<JobTask> job_task, size_t num_worker_threads) {
return std::make_unique<DefaultJobHandle>(std::make_shared<DefaultJobState>(
platform, std::move(job_task), priority, num_worker_threads));
}
bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate,
MessageLoopBehavior behavior) {
return static_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate,
......
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