V8: cppgc::Platform Class Reference (original) (raw)
#include <[platform.h](platform%5F8h%5Fsource.html)>
| Public Member Functions | |
|---|---|
| virtual | ~Platform ()=default |
| virtual PageAllocator * | GetPageAllocator ()=0 |
| virtual double | MonotonicallyIncreasingTime ()=0 |
| virtual std::shared_ptr< TaskRunner > | GetForegroundTaskRunner () |
| virtual std::shared_ptr< TaskRunner > | GetForegroundTaskRunner (TaskPriority priority) |
| virtual std::unique_ptr< JobHandle > | PostJob (TaskPriority priority, std::unique_ptr< JobTask > job_task) |
| virtual TracingController * | GetTracingController () |
Platform interface used by Heap. Contains allocators and executors.
| 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]
| virtual std::shared_ptr< TaskRunner > cppgc::Platform::GetForegroundTaskRunner ( TaskPriority priority) | inlinevirtual |
|---|
Returns a TaskRunner with a specific |priority| which can be used to post a task on the foreground thread.
Reimplemented in cppgc::DefaultPlatform.
◆ GetPageAllocator()
| virtual PageAllocator * cppgc::Platform::GetPageAllocator ( ) | pure virtual |
|---|
◆ 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 ofjob_tasklooks like:
class MyJobTask : public JobTask {
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(...));
handle->Join();
virtual std::unique_ptr< JobHandle > PostJob(TaskPriority priority, std::unique_ptr< JobTask > job_task)
Definition: platform.h:126
Definition: v8-platform.h:205
virtual bool ShouldYield()=0
Definition: v8-platform.h:299
[PostJob()](classcppgc%5F1%5F1Platform.html#aedd1512e85f00daddd926f056de1431d) and methods of the returned JobHandle/JobDelegate, must never be called while holding a lock that could be acquired by [JobTask::Run()](classv8%5F1%5F1JobTask.html#a9b6d0cee5615420f30b0db8a4c5e8c3b) or [JobTask::GetMaxConcurrency()](classv8%5F1%5F1JobTask.html#a9f1505551639903b327baecbeb38f6f7) – that could result in a deadlock. This is because (1) [JobTask::GetMaxConcurrency()](classv8%5F1%5F1JobTask.html#a9f1505551639903b327baecbeb38f6f7) may be invoked while holding internal lock (A), hence [JobTask::GetMaxConcurrency()](classv8%5F1%5F1JobTask.html#a9f1505551639903b327baecbeb38f6f7) 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()](classv8%5F1%5F1JobTask.html#a9b6d0cee5615420f30b0db8a4c5e8c3b) or [JobTask::GetMaxConcurrency()](classv8%5F1%5F1JobTask.html#a9f1505551639903b327baecbeb38f6f7) may be invoked synchronously from JobHandle (B=>JobHandle::foo=>B deadlock).
A sufficient [PostJob()](classcppgc%5F1%5F1Platform.html#aedd1512e85f00daddd926f056de1431d) implementation that uses the default Job provided in libplatform looks like:
std::unique_ptr PostJob(
TaskPriority priority, std::unique_ptr job_task) override {
return std::make_unique(
std::make_shared(
this, std::move(job_task), kNumThreads));
}
TaskPriority
Definition: v8-platform.h:25
Reimplemented in cppgc::DefaultPlatform.
The documentation for this class was generated from the following file:
- include/cppgc/platform.h