5 template<
class _Node,
class _Nodeptr = _Node*,
class _Sty = u
int32_t>
6 struct intrusive_link_queue
8 using node_type = _Node;
9 using node_ptr_type = _Nodeptr;
10 using size_type = _Sty;
12 intrusive_link_queue();
14 intrusive_link_queue(
const intrusive_link_queue&) =
delete;
15 intrusive_link_queue(intrusive_link_queue&&) =
default;
16 intrusive_link_queue& operator =(
const intrusive_link_queue&) =
delete;
17 intrusive_link_queue& operator =(intrusive_link_queue&&) =
default;
19 auto size() const noexcept->size_type;
20 bool empty() const noexcept;
21 void push_back(node_ptr_type node) noexcept;
22 auto try_pop() noexcept->node_ptr_type;
27 #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE
28 std::atomic<size_type> m_count;
32 template<
class _Node,
class _Nodeptr,
class _Sty>
33 intrusive_link_queue<_Node, _Nodeptr, _Sty>::intrusive_link_queue()
36 #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE
42 template<
class _Node,
class _Nodeptr,
class _Sty>
43 auto intrusive_link_queue<_Node, _Nodeptr, _Sty>::size() const noexcept->size_type
45 #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE
46 return m_count.load(std::memory_order_acquire);
49 for (node_type* node = _head; node !=
nullptr; node = node->next)
52 #endif // _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE
55 template<
class _Node,
class _Nodeptr,
class _Sty>
56 bool intrusive_link_queue<_Node, _Nodeptr, _Sty>::empty() const noexcept
58 return _head ==
nullptr;
61 template<
class _Node,
class _Nodeptr,
class _Sty>
62 void intrusive_link_queue<_Node, _Nodeptr, _Sty>::push_back(node_ptr_type node) noexcept
64 assert(node !=
nullptr);
66 node->_next =
nullptr;
77 #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE
78 m_count.fetch_add(1, std::memory_order_acq_rel);
82 template<
class _Node,
class _Nodeptr,
class _Sty>
83 auto intrusive_link_queue<_Node, _Nodeptr, _Sty>::try_pop() noexcept->node_ptr_type
88 node_ptr_type node = _head;
90 node->_next =
nullptr;
94 assert(node->_next ==
nullptr);
98 #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE
99 m_count.fetch_sub(1, std::memory_order_acq_rel);