#include <platform.h>
Platform interface used by Heap. Contains allocators and executors.
◆ ~Platform()
virtual cppgc::Platform::~Platform |
( |
| ) |
|
|
virtualdefault |
◆ GetForegroundTaskRunner() [1/2]
virtual std::shared_ptr< TaskRunner > cppgc::Platform::GetForegroundTaskRunner |
( |
| ) |
|
|
inlinevirtual |
Foreground task runner that should be used by a Heap.
◆ GetForegroundTaskRunner() [2/2]
Returns a TaskRunner with a specific |priority| which can be used to post a task on the foreground thread.
Reimplemented in cppgc::DefaultPlatform.
◆ GetPageAllocator()
◆ GetTracingController()
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 in cppgc::DefaultPlatform.
◆ MonotonicallyIncreasingTime()
virtual double cppgc::Platform::MonotonicallyIncreasingTime |
( |
| ) |
|
|
pure virtual |
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.
Implemented in cppgc::DefaultPlatform.
◆ PostJob()
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:
public:
MyJobTask(...) : worker_queue_(...) {}
auto work_item = worker_queue_.TakeWorkItem();
if (!work_item) return;
ProcessWork(work_item);
}
}
size_t GetMaxConcurrency() const override {
return worker_queue_.GetSize();
}
};
auto handle =
PostJob(TaskPriority::kUserVisible,
std::make_unique<MyJobTask>(...));
handle->Join();
Definition: v8-platform.h:206
virtual bool ShouldYield()=0
Definition: v8-platform.h:300
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 in cppgc::DefaultPlatform.
The documentation for this class was generated from the following file: