v8
8.6.395 (node 15.0.1)
V8 is Google's open source JavaScript engine
|
#include <platform.h>
Public Member Functions | |
virtual | ~Platform ()=default |
virtual PageAllocator * | GetPageAllocator ()=0 |
virtual double | MonotonicallyIncreasingTime ()=0 |
virtual std::shared_ptr< TaskRunner > | GetForegroundTaskRunner () |
virtual std::unique_ptr< JobHandle > | PostJob (TaskPriority priority, std::unique_ptr< JobTask > job_task) |
Platform interface used by Heap. Contains allocators and executors.
Definition at line 27 of file platform.h.
|
virtualdefault |
|
inlinevirtual |
Foreground task runner that should be used by a Heap.
Reimplemented in DefaultPlatform.
Definition at line 49 of file platform.h.
|
pure virtual |
Returns the allocator used by cppgc to allocate its heap and various support structures.
Implemented in DefaultPlatform.
|
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 DefaultPlatform.
|
inlinevirtual |
Posts |job_task| to run in parallel. Returns a JobHandle associated with the Job, which can be joined or canceled. This avoids degenerate cases:
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: 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();
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)); }
Definition at line 106 of file platform.h.