1 |
|
|
#ifndef SRC_CLEANUP_QUEUE_INL_H_ |
2 |
|
|
#define SRC_CLEANUP_QUEUE_INL_H_ |
3 |
|
|
|
4 |
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
5 |
|
|
|
6 |
|
|
#include "base_object.h" |
7 |
|
|
#include "cleanup_queue.h" |
8 |
|
|
#include "memory_tracker-inl.h" |
9 |
|
|
#include "util.h" |
10 |
|
|
|
11 |
|
|
namespace node { |
12 |
|
|
|
13 |
|
25 |
inline void CleanupQueue::MemoryInfo(MemoryTracker* tracker) const { |
14 |
|
25 |
ForEachBaseObject([&](BaseObject* obj) { |
15 |
✓✓ |
650 |
if (obj->IsDoneInitializing()) tracker->Track(obj); |
16 |
|
650 |
}); |
17 |
|
25 |
} |
18 |
|
|
|
19 |
|
25 |
inline size_t CleanupQueue::SelfSize() const { |
20 |
|
|
return sizeof(CleanupQueue) + |
21 |
|
25 |
cleanup_hooks_.size() * sizeof(CleanupHookCallback); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
11268 |
bool CleanupQueue::empty() const { |
25 |
|
11268 |
return cleanup_hooks_.empty(); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
1512348 |
void CleanupQueue::Add(Callback cb, void* arg) { |
29 |
|
|
auto insertion_info = cleanup_hooks_.emplace( |
30 |
|
1512348 |
CleanupHookCallback{cb, arg, cleanup_hook_counter_++}); |
31 |
|
|
// Make sure there was no existing element with these values. |
32 |
✗✓ |
1512348 |
CHECK_EQ(insertion_info.second, true); |
33 |
|
1512348 |
} |
34 |
|
|
|
35 |
|
1477538 |
void CleanupQueue::Remove(Callback cb, void* arg) { |
36 |
|
1477538 |
CleanupHookCallback search{cb, arg, 0}; |
37 |
|
1477538 |
cleanup_hooks_.erase(search); |
38 |
|
1477538 |
} |
39 |
|
|
|
40 |
|
|
template <typename T> |
41 |
|
56 |
void CleanupQueue::ForEachBaseObject(T&& iterator) const { |
42 |
✓✓ |
1436 |
for (const auto& hook : cleanup_hooks_) { |
43 |
|
1380 |
BaseObject* obj = GetBaseObject(hook); |
44 |
✓✓ |
1380 |
if (obj != nullptr) iterator(obj); |
45 |
|
|
} |
46 |
|
56 |
} |
47 |
|
|
|
48 |
|
702 |
BaseObject* CleanupQueue::GetBaseObject( |
49 |
|
|
const CleanupHookCallback& callback) const { |
50 |
✓✓ |
702 |
if (callback.fn_ == BaseObject::DeleteMe) |
51 |
|
674 |
return static_cast<BaseObject*>(callback.arg_); |
52 |
|
|
else |
53 |
|
28 |
return nullptr; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
} // namespace node |
57 |
|
|
|
58 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
59 |
|
|
|
60 |
|
|
#endif // SRC_CLEANUP_QUEUE_INL_H_ |