forked from v8/v8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefinalizer-handler.h
More file actions
59 lines (42 loc) · 1.62 KB
/
prefinalizer-handler.h
File metadata and controls
59 lines (42 loc) · 1.62 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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 HeapBase;
class PreFinalizerHandler final {
public:
using PreFinalizer =
cppgc::internal::PreFinalizerRegistrationDispatcher::PreFinalizer;
explicit PreFinalizerHandler(HeapBase& heap);
void RegisterPrefinalizer(PreFinalizer pre_finalizer);
void InvokePreFinalizers();
bool IsInvokingPreFinalizers() const { return is_invoking_; }
void NotifyAllocationInPrefinalizer(size_t);
size_t ExtractBytesAllocatedInPrefinalizers() {
return std::exchange(bytes_allocated_in_prefinalizers, 0);
}
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_;
std::vector<PreFinalizer>* current_ordered_pre_finalizers_;
HeapBase& heap_;
bool is_invoking_ = false;
#ifdef DEBUG
int creation_thread_id_;
#endif
// Counter of bytes allocated during prefinalizers.
size_t bytes_allocated_in_prefinalizers = 0u;
};
} // namespace internal
} // namespace cppgc
#endif // V8_HEAP_CPPGC_PREFINALIZER_HANDLER_H_