include/boost/corosio/detail/intrusive.hpp

96.1% Lines (73/76) 100.0% List of functions (58/60) 42.1% Branches (171/406)
intrusive.hpp
f(x) Functions (60)
Function Calls Lines Branches Blocks
<unknown function 43> :43 boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_acceptor>::intrusive_list() :47 874x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_socket>::intrusive_list() :47 874x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_udp_socket>::intrusive_list() :47 874x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file::raf_op>::intrusive_list() :47 48x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file>::intrusive_list() :47 1358x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_resolver>::intrusive_list() :47 1358x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_signal>::intrusive_list() :47 1358x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_stream_file>::intrusive_list() :47 1358x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_acceptor>::intrusive_list() :47 484x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_socket>::intrusive_list() :47 484x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_udp_socket>::intrusive_list() :47 484x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::waiter_node>::intrusive_list() :47 1384076x 0.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::waiter_node>::empty() const :61 38x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_acceptor>::push_back(boost::corosio::detail::kqueue_tcp_acceptor*) :66 1017x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_socket>::push_back(boost::corosio::detail::kqueue_tcp_socket*) :66 16035x 100.0% 66.7% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_udp_socket>::push_back(boost::corosio::detail::kqueue_udp_socket*) :66 52x 100.0% 50.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file::raf_op>::push_back(boost::corosio::detail::posix_random_access_file::raf_op*) :66 126x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file>::push_back(boost::corosio::detail::posix_random_access_file*) :66 24x 100.0% 62.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_resolver>::push_back(boost::corosio::detail::posix_resolver*) :66 35x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_signal>::push_back(boost::corosio::detail::posix_signal*) :66 94x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_stream_file>::push_back(boost::corosio::detail::posix_stream_file*) :66 26x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_acceptor>::push_back(boost::corosio::detail::select_tcp_acceptor*) :66 71x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_socket>::push_back(boost::corosio::detail::select_tcp_socket*) :66 5247x 0.0% 0.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_udp_socket>::push_back(boost::corosio::detail::select_udp_socket*) :66 52x 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::waiter_node>::push_back(boost::corosio::detail::waiter_node*) :66 14352x 100.0% 100.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_acceptor>::pop_front() :97 437x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_socket>::pop_front() :97 437x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_udp_socket>::pop_front() :97 437x 100.0% 13.5% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file>::pop_front() :97 679x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_resolver>::pop_front() :97 679x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_signal>::pop_front() :97 679x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_stream_file>::pop_front() :97 679x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_acceptor>::pop_front() :97 242x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_socket>::pop_front() :97 242x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_udp_socket>::pop_front() :97 242x 100.0% 23.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::waiter_node>::pop_front() :97 713205x 0.0% 0.0% 100.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_acceptor>::remove(boost::corosio::detail::kqueue_tcp_acceptor*) :115 1017x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_tcp_socket>::remove(boost::corosio::detail::kqueue_tcp_socket*) :115 16035x 100.0% 89.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::kqueue_udp_socket>::remove(boost::corosio::detail::kqueue_udp_socket*) :115 52x 92.3% 48.6% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file::raf_op>::remove(boost::corosio::detail::posix_random_access_file::raf_op*) :115 126x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file>::remove(boost::corosio::detail::posix_random_access_file*) :115 24x 100.0% 57.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_resolver>::remove(boost::corosio::detail::posix_resolver*) :115 35x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_signal>::remove(boost::corosio::detail::posix_signal*) :115 94x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_stream_file>::remove(boost::corosio::detail::posix_stream_file*) :115 26x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_acceptor>::remove(boost::corosio::detail::select_tcp_acceptor*) :115 71x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_tcp_socket>::remove(boost::corosio::detail::select_tcp_socket*) :115 5247x 100.0% 89.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::select_udp_socket>::remove(boost::corosio::detail::select_udp_socket*) :115 52x 100.0% 73.0% boost::corosio::detail::intrusive_list<boost::corosio::detail::waiter_node>::remove(boost::corosio::detail::waiter_node*) :115 36x 84.6% 58.3% 76.0% void boost::corosio::detail::intrusive_list<boost::corosio::detail::posix_random_access_file::raf_op>::for_each<boost::corosio::detail::posix_random_access_file::cancel()::'lambda'(boost::corosio::detail::posix_random_access_file::raf_op*)>(boost::corosio::detail::posix_random_access_file::cancel()::'lambda'(boost::corosio::detail::posix_random_access_file::raf_op*)) :135 67x 50.0% 25.0% 42.0% <unknown function 173> :173 boost::corosio::detail::intrusive_queue<boost::corosio::detail::pool_work_item>::intrusive_queue() :177 1362x 100.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::scheduler_op>::intrusive_queue() :177 2956468x 100.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::pool_work_item>::empty() const :191 819x 100.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::scheduler_op>::empty() const :191 6031070x 100.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::pool_work_item>::push(boost::corosio::detail::pool_work_item*) :196 181x 100.0% 50.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::scheduler_op>::push(boost::corosio::detail::scheduler_op*) :196 1928964x 100.0% 100.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::scheduler_op>::splice(boost::corosio::detail::intrusive_queue<boost::corosio::detail::scheduler_op>&) :206 976033x 90.0% 75.0% 85.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::pool_work_item>::pop() :219 1548x 100.0% 100.0% 100.0% boost::corosio::detail::intrusive_queue<boost::corosio::detail::scheduler_op>::pop() :219 2588638x 100.0% 50.0% 100.0%
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco ([email protected])
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/corosio
8 //
9
10 #ifndef BOOST_COROSIO_DETAIL_INTRUSIVE_HPP
11 #define BOOST_COROSIO_DETAIL_INTRUSIVE_HPP
12
13 namespace boost::corosio::detail {
14
15 /** An intrusive doubly linked list.
16
17 This container provides O(1) push and pop operations for
18 elements that derive from @ref node. Elements are not
19 copied or moved; they are linked directly into the list.
20
21 @tparam T The element type. Must derive from `intrusive_list<T>::node`.
22 */
23 template<class T>
24 class intrusive_list
25 {
26 public:
27 /** Base class for list elements.
28
29 Derive from this class to make a type usable with
30 @ref intrusive_list. The `next_` and `prev_` pointers
31 are private and accessible only to the list.
32 */
33 class node
34 {
35 friend class intrusive_list;
36
37 private:
38 T* next_;
39 T* prev_;
40 };
41
42 private:
43 696815x T* head_ = nullptr;
44 696815x T* tail_ = nullptr;
45
46 public:
47 2090445x intrusive_list() = default;
48
49 intrusive_list(intrusive_list&& other) noexcept
50 : head_(other.head_)
51 , tail_(other.tail_)
52 {
53 other.head_ = nullptr;
54 other.tail_ = nullptr;
55 }
56
57 intrusive_list(intrusive_list const&) = delete;
58 intrusive_list& operator=(intrusive_list const&) = delete;
59 intrusive_list& operator=(intrusive_list&&) = delete;
60
61 38x bool empty() const noexcept
62 {
63 38x return head_ == nullptr;
64 }
65
66 37131x void push_back(T* w) noexcept
67 {
68
9/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5282 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16129 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 24 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 126 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 71 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 52 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1017 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 52 times.
37131x auto* n = static_cast<node*>(w);
69 37131x n->next_ = nullptr;
70 37131x n->prev_ = tail_;
71
19/24
✓ Branch 0 taken 5214 times.
✓ Branch 1 taken 14385 times.
✓ Branch 2 taken 15016 times.
✓ Branch 3 taken 1054 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 84 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 24 times.
✓ Branch 10 taken 106 times.
✓ Branch 11 taken 20 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 69 times.
✓ Branch 16 taken 16 times.
✓ Branch 17 taken 36 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✓ Branch 21 taken 1014 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 36 times.
37131x if (tail_)
72
10/26
✗ Branch 0 not taken.
✗ Branch 0 not taken.
✓ Branch 1 taken 5169 times.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15015 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 106 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 16 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
20384x static_cast<node*>(tail_)->next_ = w;
73 else
74 16747x head_ = w;
75 37131x tail_ = w;
76 37131x }
77
78 void splice_back(intrusive_list& other) noexcept
79 {
80 if (other.empty())
81 return;
82 if (tail_)
83 {
84 static_cast<node*>(tail_)->next_ = other.head_;
85 static_cast<node*>(other.head_)->prev_ = tail_;
86 tail_ = other.tail_;
87 }
88 else
89 {
90 head_ = other.head_;
91 tail_ = other.tail_;
92 }
93 other.head_ = nullptr;
94 other.tail_ = nullptr;
95 }
96
97 717958x T* pop_front() noexcept
98 {
99
12/22
✓ Branch 0 taken 14316 times.
✓ Branch 1 taken 698889 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 679 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 679 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 679 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 679 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 242 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 242 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 242 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 437 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 437 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 437 times.
717958x if (!head_)
100 703642x return nullptr;
101 14316x T* w = head_;
102
0/20
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
14316x head_ = static_cast<node*>(head_)->next_;
103
2/22
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 14273 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
14316x if (head_)
104
0/20
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
43x static_cast<node*>(head_)->prev_ = nullptr;
105 else
106 14273x tail_ = nullptr;
107 // Defensive: clear stale linkage so remove() on a
108 // popped node cannot corrupt the list.
109
0/20
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
14316x auto* n = static_cast<node*>(w);
110 14316x n->next_ = nullptr;
111 14316x n->prev_ = nullptr;
112 14316x return w;
113 717958x }
114
115 22815x void remove(T* w) noexcept
116 {
117
11/22
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 94 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 26 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 126 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 24 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 5247 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 71 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 52 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 16035 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1017 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 52 times.
22815x auto* n = static_cast<node*>(w);
118 // Already detached — nothing to do.
119
49/96
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 34 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 35 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 34 times.
✓ Branch 11 taken 1 time.
✗ Branch 12 not taken.
✓ Branch 13 taken 34 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 94 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 84 times.
✓ Branch 19 taken 10 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 84 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 26 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 25 times.
✓ Branch 27 taken 1 time.
✗ Branch 28 not taken.
✓ Branch 29 taken 25 times.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 20 times.
✓ Branch 33 taken 106 times.
✓ Branch 34 taken 20 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 20 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 24 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 24 times.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 24 times.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 1777 times.
✓ Branch 49 taken 3470 times.
✓ Branch 50 taken 78 times.
✓ Branch 51 taken 1699 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 78 times.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 71 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 69 times.
✓ Branch 59 taken 2 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 69 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 52 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 36 times.
✓ Branch 67 taken 16 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 36 times.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 5380 times.
✓ Branch 73 taken 10655 times.
✓ Branch 74 taken 1020 times.
✓ Branch 75 taken 4360 times.
✗ Branch 76 not taken.
✓ Branch 77 taken 1020 times.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✓ Branch 80 taken 1017 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 1014 times.
✓ Branch 83 taken 3 times.
✗ Branch 84 not taken.
✓ Branch 85 taken 1014 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✓ Branch 88 taken 52 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 36 times.
✓ Branch 91 taken 16 times.
✗ Branch 92 not taken.
✓ Branch 93 taken 36 times.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
22815x if (!n->next_ && !n->prev_ && head_ != w && tail_ != w)
120 return;
121
21/24
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 84 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 25 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 126 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 24 times.
✓ Branch 12 taken 1710 times.
✓ Branch 13 taken 3537 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 69 times.
✓ Branch 16 taken 16 times.
✓ Branch 17 taken 36 times.
✓ Branch 18 taken 4424 times.
✓ Branch 19 taken 11611 times.
✓ Branch 20 taken 3 times.
✓ Branch 21 taken 1014 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 36 times.
22815x if (n->prev_)
122
9/22
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1710 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 16 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 4424 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
6183x static_cast<node*>(n->prev_)->next_ = n->next_;
123 else
124 16632x head_ = n->next_;
125
16/24
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 94 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 26 times.
✓ Branch 8 taken 106 times.
✓ Branch 9 taken 20 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 24 times.
✓ Branch 12 taken 3470 times.
✓ Branch 13 taken 1777 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 71 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 52 times.
✓ Branch 18 taken 10655 times.
✓ Branch 19 taken 5380 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1017 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 52 times.
22815x if (n->next_)
126
3/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 106 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 3470 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 10655 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
14233x static_cast<node*>(n->next_)->prev_ = n->prev_;
127 else
128 8582x tail_ = n->prev_;
129 22815x n->next_ = nullptr;
130 22815x n->prev_ = nullptr;
131 22815x }
132
133 /// Invoke @p f for each element in the list.
134 template<class F>
135 67x void for_each(F f)
136 {
137
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
67x for (T* p = head_; p; p = static_cast<node*>(p)->next_)
138 f(p);
139 67x }
140 };
141
142 /** An intrusive singly linked FIFO queue.
143
144 This container provides O(1) push and pop operations for
145 elements that derive from @ref node. Elements are not
146 copied or moved; they are linked directly into the queue.
147
148 Unlike @ref intrusive_list, this uses only a single `next_`
149 pointer per node, saving memory at the cost of not supporting
150 O(1) removal of arbitrary elements.
151
152 @tparam T The element type. Must derive from `intrusive_queue<T>::node`.
153 */
154 template<class T>
155 class intrusive_queue
156 {
157 public:
158 /** Base class for queue elements.
159
160 Derive from this class to make a type usable with
161 @ref intrusive_queue. The `next_` pointer is private
162 and accessible only to the queue.
163 */
164 class node
165 {
166 friend class intrusive_queue;
167
168 private:
169 T* next_;
170 };
171
172 private:
173 1478915x T* head_ = nullptr;
174 1478915x T* tail_ = nullptr;
175
176 public:
177 4436745x intrusive_queue() = default;
178
179 intrusive_queue(intrusive_queue&& other) noexcept
180 : head_(other.head_)
181 , tail_(other.tail_)
182 {
183 other.head_ = nullptr;
184 other.tail_ = nullptr;
185 }
186
187 intrusive_queue(intrusive_queue const&) = delete;
188 intrusive_queue& operator=(intrusive_queue const&) = delete;
189 intrusive_queue& operator=(intrusive_queue&&) = delete;
190
191 6031889x bool empty() const noexcept
192 {
193 6031889x return head_ == nullptr;
194 }
195
196 1929145x void push(T* w) noexcept
197 {
198 1929145x w->next_ = nullptr;
199
2/4
✓ Branch 0 taken 819853 times.
✓ Branch 1 taken 1109292 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1929145x if (tail_)
200 819853x tail_->next_ = w;
201 else
202 1109292x head_ = w;
203 1929145x tail_ = w;
204 1929145x }
205
206 976033x void splice(intrusive_queue& other) noexcept
207 {
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 976033 times.
976033x if (other.empty())
209 return;
210
2/2
✓ Branch 0 taken 354235 times.
✓ Branch 1 taken 621798 times.
976033x if (tail_)
211 354235x tail_->next_ = other.head_;
212 else
213 621798x head_ = other.head_;
214 976033x tail_ = other.tail_;
215 976033x other.head_ = nullptr;
216 976033x other.tail_ = nullptr;
217 976033x }
218
219 2590186x T* pop() noexcept
220 {
221
2/4
✓ Branch 0 taken 1929145 times.
✓ Branch 1 taken 661041 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2590186x if (!head_)
222 661041x return nullptr;
223 1929145x T* w = head_;
224 1929145x head_ = head_->next_;
225
2/4
✓ Branch 0 taken 1174088 times.
✓ Branch 1 taken 755057 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1929145x if (!head_)
226 755057x tail_ = nullptr;
227 // Defensive: clear stale linkage on popped node.
228 1929145x w->next_ = nullptr;
229 1929145x return w;
230 2590186x }
231 };
232
233 } // namespace boost::corosio::detail
234
235 #endif
236