GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: cleanup_queue-inl.h Lines: 26 26 100.0 %
Date: 2022-09-11 04:22:34 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
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
11431
bool CleanupQueue::empty() const {
25
11431
  return cleanup_hooks_.empty();
26
}
27
28
1513873
void CleanupQueue::Add(Callback cb, void* arg) {
29
  auto insertion_info = cleanup_hooks_.emplace(
30
1513873
      CleanupHookCallback{cb, arg, cleanup_hook_counter_++});
31
  // Make sure there was no existing element with these values.
32
1513873
  CHECK_EQ(insertion_info.second, true);
33
1513873
}
34
35
1481101
void CleanupQueue::Remove(Callback cb, void* arg) {
36
1481101
  CleanupHookCallback search{cb, arg, 0};
37
1481101
  cleanup_hooks_.erase(search);
38
1481101
}
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_