write-barrier.h 1.11 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2021 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_HEAP_CPPGC_WRITE_BARRIER_H_
#define V8_HEAP_CPPGC_WRITE_BARRIER_H_

#include "include/cppgc/internal/write-barrier.h"
9 10
#include "src/base/lazy-instance.h"
#include "src/base/platform/mutex.h"
11 12 13 14

namespace cppgc {
namespace internal {

15
class WriteBarrier::FlagUpdater final {
16
 public:
17 18 19 20 21 22 23 24 25 26 27
  static void Enter() { write_barrier_enabled_.Enter(); }
  static void Exit() { write_barrier_enabled_.Exit(); }

 private:
  FlagUpdater() = delete;
};

#if defined(CPPGC_YOUNG_GENERATION)
class V8_EXPORT_PRIVATE YoungGenerationEnabler final {
 public:
  static void Enable();
28
  static void Disable();
29 30 31 32

  static bool IsEnabled();

 private:
33 34
  template <typename T>
  friend class v8::base::LeakyObject;
35

36 37 38 39 40 41
  static YoungGenerationEnabler& Instance();

  YoungGenerationEnabler() = default;

  size_t is_enabled_;
  v8::base::Mutex mutex_;
42
};
43
#endif  // defined(CPPGC_YOUNG_GENERATION)
44 45 46 47 48

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_WRITE_BARRIER_H_