chromium/v8/include/cppgc/platform.h

// Copyright 2020 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 INCLUDE_CPPGC_PLATFORM_H_
#define INCLUDE_CPPGC_PLATFORM_H_

#include <memory>

#include "cppgc/source-location.h"
#include "v8-platform.h"  // NOLINT(build/include_directory)
#include "v8config.h"     // NOLINT(build/include_directory)

namespace cppgc {

// TODO(v8:10346): Create separate includes for concepts that are not
// V8-specific.
IdleTask;
JobHandle;
JobDelegate;
JobTask;
PageAllocator;
Task;
TaskPriority;
TaskRunner;
TracingController;

/**
 * Platform interface used by Heap. Contains allocators and executors.
 */
class V8_EXPORT Platform {};

/**
 * Process-global initialization of the garbage collector. Must be called before
 * creating a Heap.
 *
 * Can be called multiple times when paired with `ShutdownProcess()`.
 *
 * \param page_allocator The allocator used for maintaining meta data. Must stay
 *   always alive and not change between multiple calls to InitializeProcess. If
 *   no allocator is provided, a default internal version will be used.
 * \param desired_heap_size Desired amount of virtual address space to reserve
 *   for the heap, in bytes. Actual size will be clamped to minimum and maximum
 *   values based on compile-time settings and may be rounded up. If this
 *   parameter is zero, a default value will be used.
 */
V8_EXPORT void InitializeProcess(PageAllocator* page_allocator = nullptr,
                                 size_t desired_heap_size = 0);

/**
 * Must be called after destroying the last used heap. Some process-global
 * metadata may not be returned and reused upon a subsequent
 * `InitializeProcess()` call.
 */
V8_EXPORT void ShutdownProcess();

namespace internal {

V8_EXPORT void Fatal(const std::string& reason = std::string(),
                     const SourceLocation& = SourceLocation::Current());

}  // namespace internal

}  // namespace cppgc

#endif  // INCLUDE_CPPGC_PLATFORM_H_