GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: cleanup_queue-inl.h Lines: 26 26 100.0 %
Date: 2022-12-07 04:23:16 Branches: 9 10 90.0 %

Line Branch Exec Source
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
74
inline void CleanupQueue::MemoryInfo(MemoryTracker* tracker) const {
14
74
  ForEachBaseObject([&](BaseObject* obj) {
15
977
    if (obj->IsDoneInitializing()) tracker->Track(obj);
16
977
  });
17
74
}
18
19
74
inline size_t CleanupQueue::SelfSize() const {
20
  return sizeof(CleanupQueue) +
21
74
         cleanup_hooks_.size() * sizeof(CleanupHookCallback);
22
}
23
24
17921
bool CleanupQueue::empty() const {
25
17921
  return cleanup_hooks_.empty();
26
}
27
28
1524748
void CleanupQueue::Add(Callback cb, void* arg) {
29
  auto insertion_info = cleanup_hooks_.emplace(
30
1524748
      CleanupHookCallback{cb, arg, cleanup_hook_counter_++});
31
  // Make sure there was no existing element with these values.
32
1524748
  CHECK_EQ(insertion_info.second, true);
33
1524748
}
34
35
1487349
void CleanupQueue::Remove(Callback cb, void* arg) {
36
1487349
  CleanupHookCallback search{cb, arg, 0};
37
1487349
  cleanup_hooks_.erase(search);
38
1487349
}
39
40
template <typename T>
41
155
void CleanupQueue::ForEachBaseObject(T&& iterator) const {
42
3152
  for (const auto& hook : cleanup_hooks_) {
43
2997
    BaseObject* obj = GetBaseObject(hook);
44
2997
    if (obj != nullptr) iterator(obj);
45
  }
46
155
}
47
48
2020
BaseObject* CleanupQueue::GetBaseObject(
49
    const CleanupHookCallback& callback) const {
50
2020
  if (callback.fn_ == BaseObject::DeleteMe)
51
1982
    return static_cast<BaseObject*>(callback.arg_);
52
  else
53
38
    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_