Change inferior thread list to be a thread map
[deliverable/binutils-gdb.git] / gdb / thread-map.h
CommitLineData
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
26struct thread_info;
27
28struct hash_ptid
29{
30 size_t operator() (const ptid_t &ptid) const
31 {
32 std::hash<long> long_hash;
33 return long_hash(ptid.pid()) + long_hash(ptid.lwp()) + long_hash(ptid.tid());
34 }
35};
36
37using ptid_thread_map = std::unordered_map<ptid_t, thread_info *, hash_ptid>;
38
39struct all_thread_map_range_iterator
40{
41 all_thread_map_range_iterator (ptid_thread_map::const_iterator iter)
42 : m_iter (iter)
43 {}
44
45 bool operator!= (const all_thread_map_range_iterator &other)
46 { return this->m_iter != other.m_iter; }
47
48 void operator++ ()
49 { this->m_iter++; }
50
51 thread_info *operator* ()
52 { return this->m_iter->second; }
53
54private:
55 typename ptid_thread_map::const_iterator m_iter;
56};
57
58struct all_thread_map_range
59{
60 all_thread_map_range (const ptid_thread_map &map)
61 : m_map (map)
62 {}
63
64 all_thread_map_range_iterator begin ()
65 {
66 return all_thread_map_range_iterator (this->m_map.begin ());
67 }
68
69 all_thread_map_range_iterator end ()
70 {
71 return all_thread_map_range_iterator (this->m_map.end ());
72 }
73
74private:
75 const ptid_thread_map &m_map;
76};
77
78struct non_exited_thread_map_range_iterator
79{
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)
83 {
84 advante_to_next_matching ();
85 }
86
87 bool operator!= (const non_exited_thread_map_range_iterator &other)
88 { return this->m_iter != other.m_iter; }
89
90 void operator++ ()
91 {
92 this->m_iter++;
93 advante_to_next_matching ();
94 }
95
96 thread_info *operator* ()
97 { return this->m_iter->second; }
98
99private:
100 typename ptid_thread_map::const_iterator m_iter;
101 typename ptid_thread_map::const_iterator m_end;
102
103 void advante_to_next_matching ()
104 {
105 while (this->m_iter != this->m_end
106 && this->m_iter->second->state == THREAD_EXITED)
107 {
108 this->m_iter++;
109 }
110 }
111};
112
113struct non_exited_thread_map_range
114{
115 non_exited_thread_map_range (const ptid_thread_map &map)
116 : m_map (map)
117 {}
118
119 non_exited_thread_map_range_iterator begin()
120 {
121 return non_exited_thread_map_range_iterator (this->m_map.begin (), this->m_map.end ());
122 }
123
124 non_exited_thread_map_range_iterator end()
125 {
126 return non_exited_thread_map_range_iterator (this->m_map.end (), this->m_map.end ());
127 }
128
129private:
130 const ptid_thread_map &m_map;
131};
132
133#endif
This page took 0.029513 seconds and 4 git commands to generate.