Merge probe and ordinary tracepoints
[binutils-gdb.git] / gdbsupport / intrusive_list.h
index 8d49ce4551729264ffd28195edccec785ecf8ab8..6812266159a3c275199958d13eb141b582f6a862 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -350,6 +361,33 @@ public:
     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 ());