/* Intrusive double linked list for GDB, the GNU debugger.
- Copyright (C) 2021 Free Software Foundation, Inc.
+ Copyright (C) 2021-2022 Free Software Foundation, Inc.
This file is part of GDB.
/* A list node. The elements put in an intrusive_list either inherit
from this, or have a field of this type. */
template<typename T>
-struct intrusive_list_node
+class intrusive_list_node
{
+public:
bool is_linked () const
{
return next != INTRUSIVE_LIST_UNLINKED_VALUE;
}
+private:
T *next = INTRUSIVE_LIST_UNLINKED_VALUE;
T *prev = INTRUSIVE_LIST_UNLINKED_VALUE;
+
+ template<typename T2, typename AsNode>
+ friend struct intrusive_list_iterator;
+
+ template<typename T2, typename AsNode>
+ friend struct intrusive_list_reverse_iterator;
+
+ template<typename T2, typename AsNode>
+ friend struct intrusive_list;
};
/* Follows a couple types used by intrusive_list as template parameter to find
pos_node->prev = &elem;
}
+ /* Move elements from LIST at the end of the current list. */
+ void splice (intrusive_list &&other)
+ {
+ if (other.empty ())
+ return;
+
+ if (this->empty ())
+ {
+ *this = std::move (other);
+ return;
+ }
+
+ /* [A ... B] + [C ... D] */
+ T *b_elem = m_back;
+ node_type *b_node = as_node (b_elem);
+ T *c_elem = other.m_front;
+ node_type *c_node = as_node (c_elem);
+ T *d_elem = other.m_back;
+
+ b_node->next = c_elem;
+ c_node->prev = b_elem;
+ m_back = d_elem;
+
+ other.m_front = nullptr;
+ other.m_back = nullptr;
+ }
+
void pop_front ()
{
gdb_assert (!this->empty ());