2014-07-03 07:37:27 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef V8_LIBPLATFORM_LIBPLATFORM_H_
|
|
|
|
#define V8_LIBPLATFORM_LIBPLATFORM_H_
|
|
|
|
|
2019-09-13 16:11:40 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-10-10 08:51:48 +00:00
|
|
|
#include "libplatform/libplatform-export.h"
|
2016-08-01 16:17:37 +00:00
|
|
|
#include "libplatform/v8-tracing.h"
|
2020-04-27 16:29:03 +00:00
|
|
|
#include "v8-platform.h" // NOLINT(build/include_directory)
|
|
|
|
#include "v8config.h" // NOLINT(build/include_directory)
|
2014-11-18 20:29:23 +00:00
|
|
|
|
2014-11-19 07:27:48 +00:00
|
|
|
namespace v8 {
|
2014-07-03 07:37:27 +00:00
|
|
|
namespace platform {
|
|
|
|
|
2017-03-07 13:37:41 +00:00
|
|
|
enum class IdleTaskSupport { kDisabled, kEnabled };
|
2017-05-05 16:00:27 +00:00
|
|
|
enum class InProcessStackDumping { kDisabled, kEnabled };
|
2017-03-07 13:37:41 +00:00
|
|
|
|
2017-05-10 16:18:55 +00:00
|
|
|
enum class MessageLoopBehavior : bool {
|
|
|
|
kDoNotWait = false,
|
|
|
|
kWaitForWork = true
|
|
|
|
};
|
|
|
|
|
2014-07-03 07:37:27 +00:00
|
|
|
/**
|
|
|
|
* Returns a new instance of the default v8::Platform implementation.
|
|
|
|
*
|
|
|
|
* The caller will take ownership of the returned pointer. |thread_pool_size|
|
|
|
|
* is the number of worker threads to allocate for background jobs. If a value
|
|
|
|
* of zero is passed, a suitable default based on the current number of
|
|
|
|
* processors online will be chosen.
|
2017-03-07 13:37:41 +00:00
|
|
|
* If |idle_task_support| is enabled then the platform will accept idle
|
|
|
|
* tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
|
|
|
* calling v8::platform::RunIdleTasks to process the idle tasks.
|
2017-06-26 15:49:09 +00:00
|
|
|
* If |tracing_controller| is nullptr, the default platform will create a
|
|
|
|
* v8::platform::TracingController instance and use it.
|
2014-07-03 07:37:27 +00:00
|
|
|
*/
|
2017-11-13 13:16:49 +00:00
|
|
|
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
|
2017-03-07 13:37:41 +00:00
|
|
|
int thread_pool_size = 0,
|
2017-05-05 16:00:27 +00:00
|
|
|
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
|
|
|
|
InProcessStackDumping in_process_stack_dumping =
|
2018-03-23 10:21:03 +00:00
|
|
|
InProcessStackDumping::kDisabled,
|
2017-11-13 13:16:49 +00:00
|
|
|
std::unique_ptr<v8::TracingController> tracing_controller = {});
|
|
|
|
|
2020-11-13 16:10:56 +00:00
|
|
|
/**
|
|
|
|
* The same as NewDefaultPlatform but disables the worker thread pool.
|
|
|
|
* It must be used with the --single-threaded V8 flag.
|
|
|
|
*/
|
|
|
|
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 = {});
|
|
|
|
|
2020-07-17 16:41:53 +00:00
|
|
|
/**
|
|
|
|
* Returns a new instance of the default v8::JobHandle implementation.
|
|
|
|
*
|
|
|
|
* The job will be executed by spawning up to |num_worker_threads| many worker
|
|
|
|
* threads on the provided |platform| with the given |priority|.
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
2014-07-03 09:33:36 +00:00
|
|
|
/**
|
|
|
|
* Pumps the message loop for the given isolate.
|
|
|
|
*
|
|
|
|
* The caller has to make sure that this is called from the right thread.
|
2020-01-24 00:03:09 +00:00
|
|
|
* Returns true if a task was executed, and false otherwise. If the call to
|
|
|
|
* PumpMessageLoop is nested within another call to PumpMessageLoop, only
|
|
|
|
* nestable tasks may run. Otherwise, any task may run. Unless requested through
|
|
|
|
* the |behavior| parameter, this call does not block if no task is pending. The
|
|
|
|
* |platform| has to be created using |NewDefaultPlatform|.
|
2014-07-03 09:33:36 +00:00
|
|
|
*/
|
2017-05-10 16:18:55 +00:00
|
|
|
V8_PLATFORM_EXPORT bool PumpMessageLoop(
|
|
|
|
v8::Platform* platform, v8::Isolate* isolate,
|
|
|
|
MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);
|
|
|
|
|
2017-01-03 08:41:40 +00:00
|
|
|
/**
|
|
|
|
* Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
|
|
|
|
*
|
|
|
|
* The caller has to make sure that this is called from the right thread.
|
|
|
|
* This call does not block if no task is pending. The |platform| has to be
|
2017-11-13 13:16:49 +00:00
|
|
|
* created using |NewDefaultPlatform|.
|
2017-01-03 08:41:40 +00:00
|
|
|
*/
|
|
|
|
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
double idle_time_in_seconds);
|
|
|
|
|
2016-07-27 16:21:09 +00:00
|
|
|
/**
|
|
|
|
* Attempts to set the tracing controller for the given platform.
|
|
|
|
*
|
2017-11-13 13:16:49 +00:00
|
|
|
* The |platform| has to be created using |NewDefaultPlatform|.
|
2017-07-03 08:23:26 +00:00
|
|
|
*
|
2016-07-27 16:21:09 +00:00
|
|
|
*/
|
2021-10-26 12:10:55 +00:00
|
|
|
V8_DEPRECATED("Access the DefaultPlatform directly")
|
2019-10-08 16:30:08 +00:00
|
|
|
V8_PLATFORM_EXPORT void SetTracingController(
|
|
|
|
v8::Platform* platform,
|
|
|
|
v8::platform::tracing::TracingController* tracing_controller);
|
2014-07-03 09:33:36 +00:00
|
|
|
|
2020-06-25 13:12:00 +00:00
|
|
|
/**
|
|
|
|
* Notifies the given platform about the Isolate getting deleted soon. Has to be
|
|
|
|
* called for all Isolates which are deleted - unless we're shutting down the
|
|
|
|
* platform.
|
|
|
|
*
|
|
|
|
* The |platform| has to be created using |NewDefaultPlatform|.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
V8_PLATFORM_EXPORT void NotifyIsolateShutdown(v8::Platform* platform,
|
|
|
|
Isolate* isolate);
|
|
|
|
|
2014-07-03 07:37:27 +00:00
|
|
|
} // namespace platform
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_LIBPLATFORM_LIBPLATFORM_H_
|