GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: callback_queue-inl.h Lines: 41 42 97.6 %
Date: 2022-02-16 04:15:12 Branches: 7 8 87.5 %

Line Branch Exec Source
1
#ifndef SRC_CALLBACK_QUEUE_INL_H_
2
#define SRC_CALLBACK_QUEUE_INL_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "callback_queue.h"
7
8
namespace node {
9
10
template <typename R, typename... Args>
11
template <typename Fn>
12
std::unique_ptr<typename CallbackQueue<R, Args...>::Callback>
13
128155
CallbackQueue<R, Args...>::CreateCallback(Fn&& fn, CallbackFlags::Flags flags) {
14
128155
  return std::make_unique<CallbackImpl<Fn>>(std::move(fn), flags);
15
}
16
17
template <typename R, typename... Args>
18
std::unique_ptr<typename CallbackQueue<R, Args...>::Callback>
19
464015
CallbackQueue<R, Args...>::Shift() {
20
464015
  std::unique_ptr<Callback> ret = std::move(head_);
21
464015
  if (ret) {
22
69457
    head_ = ret->get_next();
23
69457
    if (!head_)
24
61871
      tail_ = nullptr;  // The queue is now empty.
25
69457
    size_--;
26
  }
27
464015
  return ret;
28
}
29
30
template <typename R, typename... Args>
31
69542
void CallbackQueue<R, Args...>::Push(std::unique_ptr<Callback> cb) {
32
69542
  Callback* prev_tail = tail_;
33
34
69542
  size_++;
35
69542
  tail_ = cb.get();
36
69542
  if (prev_tail != nullptr)
37
7604
    prev_tail->set_next(std::move(cb));
38
  else
39
61938
    head_ = std::move(cb);
40
69542
}
41
42
template <typename R, typename... Args>
43
10306
void CallbackQueue<R, Args...>::ConcatMove(CallbackQueue<R, Args...>&& other) {
44
10306
  size_ += other.size_;
45
10306
  if (tail_ != nullptr)
46
    tail_->set_next(std::move(other.head_));
47
  else
48
10306
    head_ = std::move(other.head_);
49
10306
  tail_ = other.tail_;
50
10306
  other.tail_ = nullptr;
51
10306
  other.size_ = 0;
52
10306
}
53
54
template <typename R, typename... Args>
55
429989
size_t CallbackQueue<R, Args...>::size() const {
56
859978
  return size_.load();
57
}
58
59
template <typename R, typename... Args>
60
69542
CallbackQueue<R, Args...>::Callback::Callback(CallbackFlags::Flags flags)
61
69542
  : flags_(flags) {}
62
63
template <typename R, typename... Args>
64
60043
CallbackFlags::Flags CallbackQueue<R, Args...>::Callback::flags() const {
65
60043
  return flags_;
66
}
67
68
template <typename R, typename... Args>
69
std::unique_ptr<typename CallbackQueue<R, Args...>::Callback>
70
69457
CallbackQueue<R, Args...>::Callback::get_next() {
71
69457
  return std::move(next_);
72
}
73
74
template <typename R, typename... Args>
75
7604
void CallbackQueue<R, Args...>::Callback::set_next(
76
    std::unique_ptr<Callback> next) {
77
7604
  next_ = std::move(next);
78
7604
}
79
80
template <typename R, typename... Args>
81
template <typename Fn>
82
128155
CallbackQueue<R, Args...>::CallbackImpl<Fn>::CallbackImpl(
83
    Fn&& callback, CallbackFlags::Flags flags)
84
  : Callback(flags),
85
128155
    callback_(std::move(callback)) {}
86
87
template <typename R, typename... Args>
88
template <typename Fn>
89
69272
R CallbackQueue<R, Args...>::CallbackImpl<Fn>::Call(Args... args) {
90
69272
  return callback_(std::forward<Args>(args)...);
91
}
92
93
}  // namespace node
94
95
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
96
97
#endif  // SRC_CALLBACK_QUEUE_INL_H_