Commit | Line | Data |
---|---|---|
cd9629e1 SM |
1 | /* Thread map type for GDB, the GNU debugger. |
2 | Copyright (C) 2019 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. */ | |
18 | ||
19 | #ifndef THREAD_MAP_H | |
20 | #define THREAD_MAP_H | |
21 | ||
22 | #include "defs.h" | |
23 | ||
24 | #include <unordered_map> | |
25 | ||
26 | struct thread_info; | |
27 | ||
cd9629e1 SM |
28 | using ptid_thread_map = std::unordered_map<ptid_t, thread_info *, hash_ptid>; |
29 | ||
30 | struct all_thread_map_range_iterator | |
31 | { | |
32 | all_thread_map_range_iterator (ptid_thread_map::const_iterator iter) | |
33 | : m_iter (iter) | |
34 | {} | |
35 | ||
36 | bool operator!= (const all_thread_map_range_iterator &other) | |
37 | { return this->m_iter != other.m_iter; } | |
38 | ||
39 | void operator++ () | |
40 | { this->m_iter++; } | |
41 | ||
42 | thread_info *operator* () | |
43 | { return this->m_iter->second; } | |
44 | ||
45 | private: | |
46 | typename ptid_thread_map::const_iterator m_iter; | |
47 | }; | |
48 | ||
49 | struct all_thread_map_range | |
50 | { | |
51 | all_thread_map_range (const ptid_thread_map &map) | |
52 | : m_map (map) | |
53 | {} | |
54 | ||
55 | all_thread_map_range_iterator begin () | |
56 | { | |
57 | return all_thread_map_range_iterator (this->m_map.begin ()); | |
58 | } | |
59 | ||
60 | all_thread_map_range_iterator end () | |
61 | { | |
62 | return all_thread_map_range_iterator (this->m_map.end ()); | |
63 | } | |
64 | ||
65 | private: | |
66 | const ptid_thread_map &m_map; | |
67 | }; | |
68 | ||
69 | struct non_exited_thread_map_range_iterator | |
70 | { | |
71 | non_exited_thread_map_range_iterator (typename ptid_thread_map::const_iterator iter, | |
72 | typename ptid_thread_map::const_iterator end) | |
73 | : m_iter (iter), m_end (end) | |
74 | { | |
75 | advante_to_next_matching (); | |
76 | } | |
77 | ||
78 | bool operator!= (const non_exited_thread_map_range_iterator &other) | |
79 | { return this->m_iter != other.m_iter; } | |
80 | ||
81 | void operator++ () | |
82 | { | |
83 | this->m_iter++; | |
84 | advante_to_next_matching (); | |
85 | } | |
86 | ||
87 | thread_info *operator* () | |
88 | { return this->m_iter->second; } | |
89 | ||
90 | private: | |
91 | typename ptid_thread_map::const_iterator m_iter; | |
92 | typename ptid_thread_map::const_iterator m_end; | |
93 | ||
94 | void advante_to_next_matching () | |
95 | { | |
96 | while (this->m_iter != this->m_end | |
97 | && this->m_iter->second->state == THREAD_EXITED) | |
98 | { | |
99 | this->m_iter++; | |
100 | } | |
101 | } | |
102 | }; | |
103 | ||
104 | struct non_exited_thread_map_range | |
105 | { | |
106 | non_exited_thread_map_range (const ptid_thread_map &map) | |
107 | : m_map (map) | |
108 | {} | |
109 | ||
110 | non_exited_thread_map_range_iterator begin() | |
111 | { | |
112 | return non_exited_thread_map_range_iterator (this->m_map.begin (), this->m_map.end ()); | |
113 | } | |
114 | ||
115 | non_exited_thread_map_range_iterator end() | |
116 | { | |
117 | return non_exited_thread_map_range_iterator (this->m_map.end (), this->m_map.end ()); | |
118 | } | |
119 | ||
120 | private: | |
121 | const ptid_thread_map &m_map; | |
122 | }; | |
123 | ||
124 | #endif |