Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
cppgc::DefaultPlatform Class Reference

#include <default-platform.h>

Inheritance diagram for cppgc::DefaultPlatform:
[legend]
Collaboration diagram for cppgc::DefaultPlatform:
[legend]

Public Types

using IdleTaskSupport = v8::platform::IdleTaskSupport
 

Public Member Functions

 DefaultPlatform (int thread_pool_size=0, IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, std::unique_ptr< TracingController > tracing_controller={})
 
cppgc::PageAllocatorGetPageAllocator () override
 
double MonotonicallyIncreasingTime () override
 
std::shared_ptr< cppgc::TaskRunnerGetForegroundTaskRunner () override
 
std::unique_ptr< cppgc::JobHandlePostJob (cppgc::TaskPriority priority, std::unique_ptr< cppgc::JobTask > job_task) override
 
TracingControllerGetTracingController () override
 
v8::PlatformGetV8Platform () const
 
- Public Member Functions inherited from cppgc::Platform
virtual ~Platform ()=default
 
virtual PageAllocatorGetPageAllocator ()=0
 
virtual double MonotonicallyIncreasingTime ()=0
 
virtual std::shared_ptr< TaskRunnerGetForegroundTaskRunner ()
 
virtual std::unique_ptr< JobHandlePostJob (TaskPriority priority, std::unique_ptr< JobTask > job_task)
 
virtual TracingControllerGetTracingController ()
 

Protected Attributes

std::unique_ptr< v8::Platformv8_platform_
 

Static Protected Attributes

static constexpr v8::IsolatekNoIsolate = nullptr
 

Detailed Description

Platform provided by cppgc. Uses V8's DefaultPlatform provided by libplatform internally. Exception: GetForegroundTaskRunner(), see below.

Member Typedef Documentation

◆ IdleTaskSupport

Constructor & Destructor Documentation

◆ DefaultPlatform()

cppgc::DefaultPlatform::DefaultPlatform ( int  thread_pool_size = 0,
IdleTaskSupport  idle_task_support = IdleTaskSupport::kDisabled,
std::unique_ptr< TracingController tracing_controller = {} 
)
inlineexplicit

Member Function Documentation

◆ GetForegroundTaskRunner()

std::shared_ptr< cppgc::TaskRunner > cppgc::DefaultPlatform::GetForegroundTaskRunner ( )
inlineoverridevirtual

Foreground task runner that should be used by a Heap.

Reimplemented from cppgc::Platform.

◆ GetPageAllocator()

cppgc::PageAllocator * cppgc::DefaultPlatform::GetPageAllocator ( )
inlineoverridevirtual
Returns
the allocator used by cppgc to allocate its heap and various support structures. Returning nullptr results in using the PageAllocator provided by cppgc::InitializeProcess() instead.

Implements cppgc::Platform.

◆ GetTracingController()

TracingController * cppgc::DefaultPlatform::GetTracingController ( )
inlineoverridevirtual

Returns an instance of a TracingController. This must be non-nullptr. The default implementation returns an empty TracingController that consumes trace data without effect.

Reimplemented from cppgc::Platform.

◆ GetV8Platform()

v8::Platform * cppgc::DefaultPlatform::GetV8Platform ( ) const
inline

◆ MonotonicallyIncreasingTime()

double cppgc::DefaultPlatform::MonotonicallyIncreasingTime ( )
inlineoverridevirtual

Monotonically increasing time in seconds from an arbitrary fixed point in the past. This function is expected to return at least millisecond-precision values. For this reason, it is recommended that the fixed point be no further in the past than the epoch.

Implements cppgc::Platform.

◆ PostJob()

std::unique_ptr< cppgc::JobHandle > cppgc::DefaultPlatform::PostJob ( cppgc::TaskPriority  priority,
std::unique_ptr< cppgc::JobTask job_task 
)
inlineoverridevirtual

Posts job_task to run in parallel. Returns a JobHandle associated with the Job, which can be joined or canceled. This avoids degenerate cases:

  • Calling CallOnWorkerThread() for each work item, causing significant overhead.
  • Fixed number of CallOnWorkerThread() calls that split the work and might run for a long time. This is problematic when many components post "num cores" tasks and all expect to use all the cores. In these cases, the scheduler lacks context to be fair to multiple same-priority requests and/or ability to request lower priority work to yield when high priority work comes in. A canonical implementation of job_task looks like:
    class MyJobTask : public JobTask {
    public:
    MyJobTask(...) : worker_queue_(...) {}
    // JobTask implementation.
    void Run(JobDelegate* delegate) override {
    while (!delegate->ShouldYield()) {
    // Smallest unit of work.
    auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
    if (!work_item) return;
    ProcessWork(work_item);
    }
    }
    size_t GetMaxConcurrency() const override {
    return worker_queue_.GetSize(); // Thread safe.
    }
    };
    // ...
    auto handle = PostJob(TaskPriority::kUserVisible,
    std::make_unique<MyJobTask>(...));
    handle->Join();
    std::unique_ptr< cppgc::JobHandle > PostJob(cppgc::TaskPriority priority, std::unique_ptr< cppgc::JobTask > job_task) override
    Definition: default-platform.h:47
    Definition: v8-platform.h:207
    virtual bool ShouldYield()=0
    Definition: v8-platform.h:301

PostJob() and methods of the returned JobHandle/JobDelegate, must never be called while holding a lock that could be acquired by JobTask::Run() or JobTask::GetMaxConcurrency() – that could result in a deadlock. This is because (1) JobTask::GetMaxConcurrency() may be invoked while holding internal lock (A), hence JobTask::GetMaxConcurrency() can only use a lock (B) if that lock is never held while calling back into JobHandle from any thread (A=>B/B=>A deadlock) and (2) JobTask::Run() or JobTask::GetMaxConcurrency() may be invoked synchronously from JobHandle (B=>JobHandle::foo=>B deadlock).

A sufficient PostJob() implementation that uses the default Job provided in 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));
}
TaskPriority
Definition: v8-platform.h:24

Reimplemented from cppgc::Platform.

Member Data Documentation

◆ kNoIsolate

constexpr v8::Isolate* cppgc::DefaultPlatform::kNoIsolate = nullptr
staticconstexprprotected

◆ v8_platform_

std::unique_ptr<v8::Platform> cppgc::DefaultPlatform::v8_platform_
protected

The documentation for this class was generated from the following file: