cppgc.cc 701 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2021 The Chromium 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. #include "gin/public/cppgc.h"
  5. #include "base/check_op.h"
  6. #include "gin/public/v8_platform.h"
  7. #include "v8/include/cppgc/platform.h"
  8. namespace gin {
  9. namespace {
  10. int g_init_count = 0;
  11. } // namespace
  12. void InitializeCppgcFromV8Platform() {
  13. DCHECK_GE(g_init_count, 0);
  14. if (g_init_count++ > 0)
  15. return;
  16. cppgc::InitializeProcess(gin::V8Platform::Get()->GetPageAllocator());
  17. }
  18. void MaybeShutdownCppgc() {
  19. DCHECK_GT(g_init_count, 0);
  20. if (--g_init_count > 0)
  21. return;
  22. cppgc::ShutdownProcess();
  23. }
  24. } // namespace gin