1 /* Thread map type for GDB, the GNU debugger.
2 Copyright (C) 2019 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include <unordered_map>
30 size_t operator() (const ptid_t
&ptid
) const
32 std::hash
<long> long_hash
;
33 return long_hash(ptid
.pid()) + long_hash(ptid
.lwp()) + long_hash(ptid
.tid());
37 using ptid_thread_map
= std::unordered_map
<ptid_t
, thread_info
*, hash_ptid
>;
39 struct all_thread_map_range_iterator
41 all_thread_map_range_iterator (ptid_thread_map::const_iterator iter
)
45 bool operator!= (const all_thread_map_range_iterator
&other
)
46 { return this->m_iter
!= other
.m_iter
; }
51 thread_info
*operator* ()
52 { return this->m_iter
->second
; }
55 typename
ptid_thread_map::const_iterator m_iter
;
58 struct all_thread_map_range
60 all_thread_map_range (const ptid_thread_map
&map
)
64 all_thread_map_range_iterator
begin ()
66 return all_thread_map_range_iterator (this->m_map
.begin ());
69 all_thread_map_range_iterator
end ()
71 return all_thread_map_range_iterator (this->m_map
.end ());
75 const ptid_thread_map
&m_map
;
78 struct non_exited_thread_map_range_iterator
80 non_exited_thread_map_range_iterator (typename
ptid_thread_map::const_iterator iter
,
81 typename
ptid_thread_map::const_iterator end
)
82 : m_iter (iter
), m_end (end
)
84 advante_to_next_matching ();
87 bool operator!= (const non_exited_thread_map_range_iterator
&other
)
88 { return this->m_iter
!= other
.m_iter
; }
93 advante_to_next_matching ();
96 thread_info
*operator* ()
97 { return this->m_iter
->second
; }
100 typename
ptid_thread_map::const_iterator m_iter
;
101 typename
ptid_thread_map::const_iterator m_end
;
103 void advante_to_next_matching ()
105 while (this->m_iter
!= this->m_end
106 && this->m_iter
->second
->state
== THREAD_EXITED
)
113 struct non_exited_thread_map_range
115 non_exited_thread_map_range (const ptid_thread_map
&map
)
119 non_exited_thread_map_range_iterator
begin()
121 return non_exited_thread_map_range_iterator (this->m_map
.begin (), this->m_map
.end ());
124 non_exited_thread_map_range_iterator
end()
126 return non_exited_thread_map_range_iterator (this->m_map
.end (), this->m_map
.end ());
130 const ptid_thread_map
&m_map
;