1 /* Thread iterators and ranges for GDB, the GNU debugger.
3 Copyright (C) 2018-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdbthread.h"
24 /* See thread-iter.h. */
26 all_threads_iterator::all_threads_iterator (begin_t
)
28 /* Advance M_INF/M_THR to the first thread's position. */
29 for (m_inf
= inferior_list
; m_inf
!= NULL
; m_inf
= m_inf
->next
)
31 if (!m_inf
->thread_map
.empty())
33 this->m_thr_iter
= m_inf
->thread_map
.cbegin ();
39 /* See thread-iter.h. */
42 all_threads_iterator::advance ()
44 /* The loop below is written in the natural way as-if we'd always
45 start at the beginning of the inferior list. This fast forwards
46 the algorithm to the actual current position. */
49 for (; m_inf
!= NULL
; m_inf
= m_inf
->next
)
51 m_thr_iter
= m_inf
->thread_map
.cbegin ();
52 while (m_thr_iter
!= m_inf
->thread_map
.cend ())
61 thread_info
*all_threads_iterator::operator* () const
63 gdb_assert (m_inf
!= NULL
);
64 gdb_assert (m_thr_iter
!= m_inf
->thread_map
.cend ());
66 return m_thr_iter
->second
;
69 /* See thread-iter.h. */
72 all_matching_threads_iterator::m_inf_matches ()
74 return (m_filter_ptid
== minus_one_ptid
75 || m_filter_ptid
.pid () == m_inf
->pid
);
78 /* See thread-iter.h. */
80 all_matching_threads_iterator::all_matching_threads_iterator
82 : m_filter_ptid (filter_ptid
)
84 for (m_inf
= inferior_list
; m_inf
!= NULL
; m_inf
= m_inf
->next
)
86 if (!m_inf
->thread_map
.empty () && m_inf_matches ())
88 for (m_thr_iter
= m_inf
->thread_map
.cbegin ();
89 m_thr_iter
!= m_inf
->thread_map
.cend ();
92 if (m_thr_iter
->second
->ptid
.matches (m_filter_ptid
))
99 /* See thread-iter.h. */
102 all_matching_threads_iterator::advance ()
104 /* The loop below is written in the natural way as-if we'd always
105 start at the beginning of the inferior list. This fast forwards
106 the algorithm to the actual current position. */
109 for (; m_inf
!= NULL
; m_inf
= m_inf
->next
)
110 if (m_inf_matches ())
112 m_thr_iter
= m_inf
->thread_map
.cbegin ();
113 while (m_thr_iter
!= m_inf
->thread_map
.cend ())
115 if (m_thr_iter
->second
->ptid
.matches (m_filter_ptid
))
123 thread_info
*all_matching_threads_iterator::operator* () const
125 gdb_assert (m_inf
!= nullptr);
127 return m_thr_iter
->second
;