summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/cppgc/prefinalizer-handler.h
blob: a62555347100a7d261b8179c2094a5b385259bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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 V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_
#define V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_

#include <vector>

#include "include/cppgc/prefinalizer.h"

namespace cppgc {
namespace internal {

class PreFinalizerHandler final {
 public:
  using PreFinalizer =
      cppgc::internal::PreFinalizerRegistrationDispatcher::PreFinalizer;

  PreFinalizerHandler();

  void RegisterPrefinalizer(PreFinalizer prefinalzier);

  void InvokePreFinalizers();

 private:
  // Checks that the current thread is the thread that created the heap.
  bool CurrentThreadIsCreationThread();

  // Pre-finalizers are called in the reverse order in which they are
  // registered by the constructors (including constructors of Mixin
  // objects) for an object, by processing the ordered_pre_finalizers_
  // back-to-front.
  std::vector<PreFinalizer> ordered_pre_finalizers_;

#ifdef DEBUG
  int creation_thread_id_;
#endif
};

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_