v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
libplatform.h
Go to the documentation of this file.
1// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
6#define V8_LIBPLATFORM_LIBPLATFORM_H_
7
8#include <memory>
9
10#include "libplatform/libplatform-export.h"
11#include "libplatform/v8-tracing.h"
12#include "v8-platform.h" // NOLINT(build/include_directory)
13#include "v8config.h" // NOLINT(build/include_directory)
14
15namespace v8 {
16namespace platform {
17
20
21enum class MessageLoopBehavior : bool {
22 kDoNotWait = false,
23 kWaitForWork = true
24};
25
26enum class PriorityMode : bool { kDontApply, kApply };
27
28/**
29 * Returns a new instance of the default v8::Platform implementation.
30 *
31 * The caller will take ownership of the returned pointer. |thread_pool_size|
32 * is the number of worker threads to allocate for background jobs. If a value
33 * of zero is passed, a suitable default based on the current number of
34 * processors online will be chosen.
35 * If |idle_task_support| is enabled then the platform will accept idle
36 * tasks (IdleTasksEnabled will return true) and will rely on the embedder
37 * calling v8::platform::RunIdleTasks to process the idle tasks.
38 * If |tracing_controller| is nullptr, the default platform will create a
39 * v8::platform::TracingController instance and use it.
40 * If |priority_mode| is PriorityMode::kApply, the default platform will use
41 * multiple task queues executed by threads different system-level priorities
42 * (where available) to schedule tasks.
43 */
45 int thread_pool_size = 0,
47 InProcessStackDumping in_process_stack_dumping =
49 std::unique_ptr<v8::TracingController> tracing_controller = {},
51
52/**
53 * The same as NewDefaultPlatform but disables the worker thread pool.
54 * It must be used with the --single-threaded V8 flag.
55 */
59 InProcessStackDumping in_process_stack_dumping =
61 std::unique_ptr<v8::TracingController> tracing_controller = {});
62
63/**
64 * Returns a new instance of the default v8::JobHandle implementation.
65 *
66 * The job will be executed by spawning up to |num_worker_threads| many worker
67 * threads on the provided |platform| with the given |priority|.
68 */
70 v8::Platform* platform, v8::TaskPriority priority,
71 std::unique_ptr<v8::JobTask> job_task, size_t num_worker_threads);
72
73/**
74 * Pumps the message loop for the given isolate.
75 *
76 * The caller has to make sure that this is called from the right thread.
77 * Returns true if a task was executed, and false otherwise. If the call to
78 * PumpMessageLoop is nested within another call to PumpMessageLoop, only
79 * nestable tasks may run. Otherwise, any task may run. Unless requested through
80 * the |behavior| parameter, this call does not block if no task is pending. The
81 * |platform| has to be created using |NewDefaultPlatform|.
82 */
84 v8::Platform* platform, v8::Isolate* isolate,
86
87/**
88 * Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
89 *
90 * The caller has to make sure that this is called from the right thread.
91 * This call does not block if no task is pending. The |platform| has to be
92 * created using |NewDefaultPlatform|.
93 */
95 v8::Isolate* isolate,
96 double idle_time_in_seconds);
97
98/**
99 * Notifies the given platform about the Isolate getting deleted soon. Has to be
100 * called for all Isolates which are deleted - unless we're shutting down the
101 * platform.
102 *
103 * The |platform| has to be created using |NewDefaultPlatform|.
104 *
105 */
107 Isolate* isolate);
108
109} // namespace platform
110} // namespace v8
111
112#endif // V8_LIBPLATFORM_LIBPLATFORM_H_
#define V8_PLATFORM_EXPORT
V8_PLATFORM_EXPORT void NotifyIsolateShutdown(v8::Platform *platform, Isolate *isolate)
V8_PLATFORM_EXPORT std::unique_ptr< v8::Platform > NewDefaultPlatform(int thread_pool_size=0, IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, InProcessStackDumping in_process_stack_dumping=InProcessStackDumping::kDisabled, std::unique_ptr< v8::TracingController > tracing_controller={}, PriorityMode priority_mode=PriorityMode::kDontApply)
V8_PLATFORM_EXPORT std::unique_ptr< v8::JobHandle > NewDefaultJobHandle(v8::Platform *platform, v8::TaskPriority priority, std::unique_ptr< v8::JobTask > job_task, size_t num_worker_threads)
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform *platform, v8::Isolate *isolate, double idle_time_in_seconds)
V8_PLATFORM_EXPORT bool PumpMessageLoop(v8::Platform *platform, v8::Isolate *isolate, MessageLoopBehavior behavior=MessageLoopBehavior::kDoNotWait)
V8_PLATFORM_EXPORT std::unique_ptr< v8::Platform > NewSingleThreadedDefaultPlatform(IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, InProcessStackDumping in_process_stack_dumping=InProcessStackDumping::kDisabled, std::unique_ptr< v8::TracingController > tracing_controller={})
TaskPriority
Definition v8-platform.h:25