Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-02 08:54:42

0001 // Copyright 2020 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
0004 
0005 #ifndef INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
0006 #define INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
0007 
0008 #include <memory>
0009 
0010 #include "cppgc/platform.h"
0011 #include "libplatform/libplatform.h"
0012 #include "v8config.h"  // NOLINT(build/include_directory)
0013 
0014 namespace cppgc {
0015 
0016 /**
0017  * Platform provided by cppgc. Uses V8's DefaultPlatform provided by
0018  * libplatform internally. Exception: `GetForegroundTaskRunner()`, see below.
0019  */
0020 class V8_EXPORT DefaultPlatform : public Platform {
0021  public:
0022   using IdleTaskSupport = v8::platform::IdleTaskSupport;
0023   explicit DefaultPlatform(
0024       int thread_pool_size = 0,
0025       IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
0026       std::unique_ptr<TracingController> tracing_controller = {})
0027       : v8_platform_(v8::platform::NewDefaultPlatform(
0028             thread_pool_size, idle_task_support,
0029             v8::platform::InProcessStackDumping::kDisabled,
0030             std::move(tracing_controller))) {}
0031 
0032   cppgc::PageAllocator* GetPageAllocator() override {
0033     return v8_platform_->GetPageAllocator();
0034   }
0035 
0036   double MonotonicallyIncreasingTime() override {
0037     return v8_platform_->MonotonicallyIncreasingTime();
0038   }
0039 
0040   std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() override {
0041     // V8's default platform creates a new task runner when passed the
0042     // `v8::Isolate` pointer the first time. For non-default platforms this will
0043     // require getting the appropriate task runner.
0044     return v8_platform_->GetForegroundTaskRunner(kNoIsolate);
0045   }
0046 
0047   std::unique_ptr<cppgc::JobHandle> PostJob(
0048       cppgc::TaskPriority priority,
0049       std::unique_ptr<cppgc::JobTask> job_task) override {
0050     return v8_platform_->PostJob(priority, std::move(job_task));
0051   }
0052 
0053   TracingController* GetTracingController() override {
0054     return v8_platform_->GetTracingController();
0055   }
0056 
0057   v8::Platform* GetV8Platform() const { return v8_platform_.get(); }
0058 
0059  protected:
0060   static constexpr v8::Isolate* kNoIsolate = nullptr;
0061 
0062   std::unique_ptr<v8::Platform> v8_platform_;
0063 };
0064 
0065 }  // namespace cppgc
0066 
0067 #endif  // INCLUDE_CPPGC_DEFAULT_PLATFORM_H_