0
Files
src/gin/cppgc.cc
Daniel Hosseinian 554068b7a9 [gin] Introduce gin::MaybeShutdownCppgc()
crrev.com/875699 introduced gin::InitializeCppgcFromV8Platform(), which
centralized initialization of cppgc in Gin for the case of multiple
cppgc users in the same process.

Introduce gin::MaybeShutdownCppgc(), which centralizes the shutdown of
cppgc in Gin. This will help in guaranteeing that cppgc is shutdown only
after all users in the same process are done using it.

Bug: 1056170, 1111024
Change-Id: I15aebd3bea78a7033cf00743dbd4e286b1a30711
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3011899
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#899637}
2021-07-08 18:35:10 +00:00

36 lines
701 B
C++

// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gin/public/cppgc.h"
#include "base/check_op.h"
#include "gin/public/v8_platform.h"
#include "v8/include/cppgc/platform.h"
namespace gin {
namespace {
int g_init_count = 0;
} // namespace
void InitializeCppgcFromV8Platform() {
DCHECK_GE(g_init_count, 0);
if (g_init_count++ > 0)
return;
cppgc::InitializeProcess(gin::V8Platform::Get()->GetPageAllocator());
}
void MaybeShutdownCppgc() {
DCHECK_GT(g_init_count, 0);
if (--g_init_count > 0)
return;
cppgc::ShutdownProcess();
}
} // namespace gin