2020-07-22 21:24:25 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
|
|
|
|
#define INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "cppgc/platform.h"
|
2020-10-08 11:16:20 +00:00
|
|
|
#include "libplatform/libplatform.h"
|
2020-07-22 21:24:25 +00:00
|
|
|
#include "v8config.h" // NOLINT(build/include_directory)
|
|
|
|
|
|
|
|
namespace cppgc {
|
|
|
|
|
|
|
|
/**
|
2020-10-08 11:16:20 +00:00
|
|
|
* Platform provided by cppgc. Uses V8's DefaultPlatform provided by
|
2020-10-19 08:12:55 +00:00
|
|
|
* libplatform internally. Exception: `GetForegroundTaskRunner()`, see below.
|
2020-07-22 21:24:25 +00:00
|
|
|
*/
|
2020-10-08 11:16:20 +00:00
|
|
|
class V8_EXPORT DefaultPlatform : public Platform {
|
2020-07-22 21:24:25 +00:00
|
|
|
public:
|
2020-10-08 11:16:20 +00:00
|
|
|
using IdleTaskSupport = v8::platform::IdleTaskSupport;
|
|
|
|
explicit DefaultPlatform(
|
|
|
|
int thread_pool_size = 0,
|
2020-11-19 12:27:35 +00:00
|
|
|
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
|
|
|
|
std::unique_ptr<TracingController> tracing_controller = {})
|
|
|
|
: v8_platform_(v8::platform::NewDefaultPlatform(
|
|
|
|
thread_pool_size, idle_task_support,
|
|
|
|
v8::platform::InProcessStackDumping::kDisabled,
|
|
|
|
std::move(tracing_controller))) {}
|
2020-10-08 11:16:20 +00:00
|
|
|
|
|
|
|
cppgc::PageAllocator* GetPageAllocator() override {
|
|
|
|
return v8_platform_->GetPageAllocator();
|
|
|
|
}
|
|
|
|
|
|
|
|
double MonotonicallyIncreasingTime() override {
|
|
|
|
return v8_platform_->MonotonicallyIncreasingTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() override {
|
|
|
|
// V8's default platform creates a new task runner when passed the
|
2020-10-19 08:12:55 +00:00
|
|
|
// `v8::Isolate` pointer the first time. For non-default platforms this will
|
2020-10-08 11:16:20 +00:00
|
|
|
// require getting the appropriate task runner.
|
|
|
|
return v8_platform_->GetForegroundTaskRunner(kNoIsolate);
|
|
|
|
}
|
2020-07-22 21:24:25 +00:00
|
|
|
|
|
|
|
std::unique_ptr<cppgc::JobHandle> PostJob(
|
|
|
|
cppgc::TaskPriority priority,
|
2020-10-08 11:16:20 +00:00
|
|
|
std::unique_ptr<cppgc::JobTask> job_task) override {
|
|
|
|
return v8_platform_->PostJob(priority, std::move(job_task));
|
|
|
|
}
|
2020-07-22 21:24:25 +00:00
|
|
|
|
2020-11-19 12:27:35 +00:00
|
|
|
TracingController* GetTracingController() override {
|
|
|
|
return v8_platform_->GetTracingController();
|
|
|
|
}
|
|
|
|
|
2020-10-08 11:16:20 +00:00
|
|
|
protected:
|
|
|
|
static constexpr v8::Isolate* kNoIsolate = nullptr;
|
2020-07-22 21:24:25 +00:00
|
|
|
|
2020-10-08 11:16:20 +00:00
|
|
|
std::unique_ptr<v8::Platform> v8_platform_;
|
2020-07-22 21:24:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cppgc
|
|
|
|
|
|
|
|
#endif // INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
|