libplatform.h 3.57 KB
Newer Older
1 2 3 4 5 6 7
// 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_

8
#include "libplatform/libplatform-export.h"
mattloring's avatar
mattloring committed
9
#include "libplatform/v8-tracing.h"
10
#include "v8-platform.h"  // NOLINT(build/include)
11
#include "v8config.h"     // NOLINT(build/include)
12

13
namespace v8 {
14 15
namespace platform {

16
enum class IdleTaskSupport { kDisabled, kEnabled };
17
enum class InProcessStackDumping { kDisabled, kEnabled };
18

19 20 21 22 23
enum class MessageLoopBehavior : bool {
  kDoNotWait = false,
  kWaitForWork = true
};

24 25 26 27 28 29 30
/**
 * 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.
31 32 33
 * 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.
34 35
 * If |tracing_controller| is nullptr, the default platform will create a
 * v8::platform::TracingController instance and use it.
36
 */
37
V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
38
    int thread_pool_size = 0,
39 40
    IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
    InProcessStackDumping in_process_stack_dumping =
41
        InProcessStackDumping::kEnabled,
42 43 44 45 46 47 48 49 50 51
    std::unique_ptr<v8::TracingController> tracing_controller = {});

V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
    "Use NewDefaultPlatform instead",
    v8::Platform* CreateDefaultPlatform(
        int thread_pool_size = 0,
        IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
        InProcessStackDumping in_process_stack_dumping =
            InProcessStackDumping::kEnabled,
        v8::TracingController* tracing_controller = nullptr));
52

53 54 55 56
/**
 * Pumps the message loop for the given isolate.
 *
 * The caller has to make sure that this is called from the right thread.
57 58
 * Returns true if a task was executed, and false otherwise. Unless requested
 * through the |behavior| parameter, this call does not block if no task is
59
 * pending. The |platform| has to be created using |NewDefaultPlatform|.
60
 */
61 62 63 64 65 66
V8_PLATFORM_EXPORT bool PumpMessageLoop(
    v8::Platform* platform, v8::Isolate* isolate,
    MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);

V8_PLATFORM_EXPORT void EnsureEventLoopInitialized(v8::Platform* platform,
                                                   v8::Isolate* isolate);
67

68 69 70 71 72
/**
 * 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
73
 * created using |NewDefaultPlatform|.
74 75 76 77 78
 */
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
                                     v8::Isolate* isolate,
                                     double idle_time_in_seconds);

79 80 81
/**
 * Attempts to set the tracing controller for the given platform.
 *
82
 * The |platform| has to be created using |NewDefaultPlatform|.
83
 *
84
 */
85 86 87 88 89
V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
    "Access the DefaultPlatform directly",
    void SetTracingController(
        v8::Platform* platform,
        v8::platform::tracing::TracingController* tracing_controller));
90

91 92 93 94
}  // namespace platform
}  // namespace v8

#endif  // V8_LIBPLATFORM_LIBPLATFORM_H_