GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/callback_queue-inl.h Lines: 41 42 97.6 %
Date: 2021-04-23 04:11:39 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
65736
CallbackQueue<R, Args...>::CreateCallback(Fn&& fn, CallbackFlags::Flags flags) {
14
65736
  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
1080714
CallbackQueue<R, Args...>::Shift() {
20
1080714
  std::unique_ptr<Callback> ret = std::move(head_);
21
1080714
  if (ret) {
22
65681
    head_ = ret->get_next();
23
65682
    if (!head_)
24
59145
      tail_ = nullptr;  // The queue is now empty.
25
65682
    size_--;
26
  }
27
1080714
  return ret;
28
}
29
30
template <typename R, typename... Args>
31
65739
void CallbackQueue<R, Args...>::Push(std::unique_ptr<Callback> cb) {
32
65739
  Callback* prev_tail = tail_;
33
34
65739
  size_++;
35
65739
  tail_ = cb.get();
36
65739
  if (prev_tail != nullptr)
37
6555
    prev_tail->set_next(std::move(cb));
38
  else
39
59184
    head_ = std::move(cb);
40
65739
}
41
42
template <typename R, typename... Args>
43
9194
void CallbackQueue<R, Args...>::ConcatMove(CallbackQueue<R, Args...>&& other) {
44
9194
  size_ += other.size_;
45
9194
  if (tail_ != nullptr)
46
    tail_->set_next(std::move(other.head_));
47
  else
48
9194
    head_ = std::move(other.head_);
49
9194
  tail_ = other.tail_;
50
9194
  other.tail_ = nullptr;
51
9194
  other.size_ = 0;
52
9194
}
53
54
template <typename R, typename... Args>
55
1047763
size_t CallbackQueue<R, Args...>::size() const {
56
2095529
  return size_.load();
57
}
58
59
template <typename R, typename... Args>
60
65738
CallbackQueue<R, Args...>::Callback::Callback(CallbackFlags::Flags flags)
61
65738
  : flags_(flags) {}
62
63
template <typename R, typename... Args>
64
57146
CallbackFlags::Flags CallbackQueue<R, Args...>::Callback::flags() const {
65
57146
  return flags_;
66
}
67
68
template <typename R, typename... Args>
69
std::unique_ptr<typename CallbackQueue<R, Args...>::Callback>
70
65682
CallbackQueue<R, Args...>::Callback::get_next() {
71
65682
  return std::move(next_);
72
}
73
74
template <typename R, typename... Args>
75
6555
void CallbackQueue<R, Args...>::Callback::set_next(
76
    std::unique_ptr<Callback> next) {
77
6555
  next_ = std::move(next);
78
6555
}
79
80
template <typename R, typename... Args>
81
template <typename Fn>
82
65739
CallbackQueue<R, Args...>::CallbackImpl<Fn>::CallbackImpl(
83
    Fn&& callback, CallbackFlags::Flags flags)
84
  : Callback(flags),
85
65739
    callback_(std::move(callback)) {}
86
87
template <typename R, typename... Args>
88
template <typename Fn>
89
65500
R CallbackQueue<R, Args...>::CallbackImpl<Fn>::Call(Args... args) {
90
65500
  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_