GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: cleanup_queue-inl.h Lines: 26 26 100.0 %
Date: 2022-11-08 04:21:23 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
50
inline void CleanupQueue::MemoryInfo(MemoryTracker* tracker) const {
14
50
  ForEachBaseObject([&](BaseObject* obj) {
15
650
    if (obj->IsDoneInitializing()) tracker->Track(obj);
16
650
  });
17
50
}
18
19
50
inline size_t CleanupQueue::SelfSize() const {
20
  return sizeof(CleanupQueue) +
21
50
         cleanup_hooks_.size() * sizeof(CleanupHookCallback);
22
}
23
24
17760
bool CleanupQueue::empty() const {
25
17760
  return cleanup_hooks_.empty();
26
}
27
28
1519274
void CleanupQueue::Add(Callback cb, void* arg) {
29
  auto insertion_info = cleanup_hooks_.emplace(
30
1519274
      CleanupHookCallback{cb, arg, cleanup_hook_counter_++});
31
  // Make sure there was no existing element with these values.
32
1519274
  CHECK_EQ(insertion_info.second, true);
33
1519274
}
34
35
1483159
void CleanupQueue::Remove(Callback cb, void* arg) {
36
1483159
  CleanupHookCallback search{cb, arg, 0};
37
1483159
  cleanup_hooks_.erase(search);
38
1483159
}
39
40
template <typename T>
41
107
void CleanupQueue::ForEachBaseObject(T&& iterator) const {
42
2113
  for (const auto& hook : cleanup_hooks_) {
43
2006
    BaseObject* obj = GetBaseObject(hook);
44
2006
    if (obj != nullptr) iterator(obj);
45
  }
46
107
}
47
48
1356
BaseObject* CleanupQueue::GetBaseObject(
49
    const CleanupHookCallback& callback) const {
50
1356
  if (callback.fn_ == BaseObject::DeleteMe)
51
1328
    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_