Change inferior thread list to be a thread map
[deliverable/binutils-gdb.git] / gdb / thread-iter.h
index 169d42a1f0641fa7ce49a043cb55d1d199976739..e2e5783f16a3bf6e9699516343c75ee681fa08ee 100644 (file)
@@ -22,6 +22,7 @@
 #include "gdbsupport/filtered-iterator.h"
 #include "gdbsupport/next-iterator.h"
 #include "gdbsupport/safe-iterator.h"
+#include "thread-map.h"
 
 /* A forward iterator that iterates over a given inferior's
    threads.  */
@@ -50,10 +51,10 @@ public:
 
   /* Create a one-past-end iterator.  */
   all_threads_iterator ()
-    : m_thr (nullptr)
+    : m_inf (nullptr)
   {}
 
-  thread_info *operator* () const { return m_thr; }
+  thread_info *operator* () const;
 
   all_threads_iterator &operator++ ()
   {
@@ -62,20 +63,34 @@ public:
   }
 
   bool operator== (const all_threads_iterator &other) const
-  { return m_thr == other.m_thr; }
+  {
+    if (m_inf != other.m_inf)
+      return false;
+
+    /* Inferiors of both iterators are equal.  */
+    if (m_inf == NULL) {
+       /* They are both ended iterators.  */
+       return true;
+    } else {
+       /* Do they both point to the same thread?  */
+       return m_thr_iter == other.m_thr_iter;
+    }
+  }
 
   bool operator!= (const all_threads_iterator &other) const
-  { return m_thr != other.m_thr; }
+  {
+    return !(*this == other);
+  }
 
 private:
   /* Advance to the next thread.  */
   void advance ();
 
 private:
-  /* The current inferior and thread.  M_THR is NULL if we reached the
+  /* The current inferior and thread.  M_INF is NULL if we reached the
      end of the threads list of the last inferior.  */
   inferior *m_inf;
-  thread_info *m_thr;
+  ptid_thread_map::const_iterator m_thr_iter;
 };
 
 /* Iterate over all threads that match a given PTID.  */
@@ -92,16 +107,17 @@ public:
 
   /* Creates an iterator that iterates over all threads that match
      FILTER_PTID.  */
-  explicit all_matching_threads_iterator (ptid_t filter_ptid);
+  all_matching_threads_iterator (process_stratum_target *filter_target,
+                                ptid_t filter_ptid);
 
   /* Create a one-past-end iterator.  */
   all_matching_threads_iterator ()
     : m_inf (nullptr),
-      m_thr (nullptr),
+      m_filter_target (nullptr),
       m_filter_ptid (minus_one_ptid)
   {}
 
-  thread_info *operator* () const { return m_thr; }
+  thread_info *operator* () const;
 
   all_matching_threads_iterator &operator++ ()
   {
@@ -110,10 +126,24 @@ public:
   }
 
   bool operator== (const all_matching_threads_iterator &other) const
-  { return m_thr == other.m_thr; }
+  {
+    if (m_inf != other.m_inf)
+      return false;
+
+    /* Inferiors of both iterators are equal.  */
+    if (m_inf == NULL) {
+       /* They are both ended iterators.  */
+       return true;
+    } else {
+       /* Do they both point to the same thread?  */
+       return m_thr_iter == other.m_thr_iter;
+    }
+  }
 
   bool operator!= (const all_matching_threads_iterator &other) const
-  { return m_thr != other.m_thr; }
+  {
+    return !(* this == other);
+  }
 
 private:
   /* Advance to next thread, skipping filtered threads.  */
@@ -128,9 +158,10 @@ private:
   inferior *m_inf;
 
   /* The current thread.  */
-  thread_info *m_thr;
+  ptid_thread_map::const_iterator m_thr_iter;
 
   /* The filter.  */
+  process_stratum_target *m_filter_target;
   ptid_t m_filter_ptid;
 };
 
@@ -211,20 +242,22 @@ struct all_threads_safe_range
 struct all_matching_threads_range
 {
 public:
-  explicit all_matching_threads_range (ptid_t filter_ptid)
-    : m_filter_ptid (filter_ptid)
+  all_matching_threads_range (process_stratum_target *filter_target,
+                             ptid_t filter_ptid)
+    : m_filter_target (filter_target), m_filter_ptid (filter_ptid)
   {}
   all_matching_threads_range ()
-    : m_filter_ptid (minus_one_ptid)
+    : m_filter_target (nullptr), m_filter_ptid (minus_one_ptid)
   {}
 
   all_matching_threads_iterator begin () const
-  { return all_matching_threads_iterator (m_filter_ptid); }
+  { return all_matching_threads_iterator (m_filter_target, m_filter_ptid); }
   all_matching_threads_iterator end () const
   { return all_matching_threads_iterator (); }
 
 private:
   /* The filter.  */
+  process_stratum_target *m_filter_target;
   ptid_t m_filter_ptid;
 };
 
@@ -236,20 +269,22 @@ private:
 class all_non_exited_threads_range
 {
 public:
-  explicit all_non_exited_threads_range (ptid_t filter_ptid)
-    : m_filter_ptid (filter_ptid)
+  all_non_exited_threads_range (process_stratum_target *filter_target,
+                               ptid_t filter_ptid)
+    : m_filter_target (filter_target), m_filter_ptid (filter_ptid)
   {}
 
   all_non_exited_threads_range ()
-    : m_filter_ptid (minus_one_ptid)
+    : m_filter_target (nullptr), m_filter_ptid (minus_one_ptid)
   {}
 
   all_non_exited_threads_iterator begin () const
-  { return all_non_exited_threads_iterator (m_filter_ptid); }
+  { return all_non_exited_threads_iterator (m_filter_target, m_filter_ptid); }
   all_non_exited_threads_iterator end () const
   { return all_non_exited_threads_iterator (); }
 
 private:
+  process_stratum_target *m_filter_target;
   ptid_t m_filter_ptid;
 };
 
This page took 0.02807 seconds and 4 git commands to generate.