• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 the V8 project 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 
5 #ifndef V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_
6 #define V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_
7 
8 #include <vector>
9 
10 #include "include/cppgc/prefinalizer.h"
11 
12 namespace cppgc {
13 namespace internal {
14 
15 class PreFinalizerHandler final {
16  public:
17   using PreFinalizer =
18       cppgc::internal::PreFinalizerRegistrationDispatcher::PreFinalizer;
19 
20   PreFinalizerHandler();
21 
22   void RegisterPrefinalizer(PreFinalizer pre_finalizer);
23 
24   void InvokePreFinalizers();
25 
26  private:
27   // Checks that the current thread is the thread that created the heap.
28   bool CurrentThreadIsCreationThread();
29 
30   // Pre-finalizers are called in the reverse order in which they are
31   // registered by the constructors (including constructors of Mixin
32   // objects) for an object, by processing the ordered_pre_finalizers_
33   // back-to-front.
34   std::vector<PreFinalizer> ordered_pre_finalizers_;
35 
36 #ifdef DEBUG
37   int creation_thread_id_;
38 #endif
39 };
40 
41 }  // namespace internal
42 }  // namespace cppgc
43 
44 #endif  // V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_
45