X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fthread-map.h;fp=gdb%2Fthread-map.h;h=2b41b7361ce62b741fd416069b1ec50bf8882346;hb=cd9629e1df1a280c19e1daaf6c1195afbab0aca9;hp=0000000000000000000000000000000000000000;hpb=54a01e885b23df89e7e1e1585e896e0b7c53cf1d;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/thread-map.h b/gdb/thread-map.h new file mode 100644 index 0000000000..2b41b7361c --- /dev/null +++ b/gdb/thread-map.h @@ -0,0 +1,133 @@ +/* Thread map type for GDB, the GNU debugger. + Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef THREAD_MAP_H +#define THREAD_MAP_H + +#include "defs.h" + +#include + +struct thread_info; + +struct hash_ptid +{ + size_t operator() (const ptid_t &ptid) const + { + std::hash long_hash; + return long_hash(ptid.pid()) + long_hash(ptid.lwp()) + long_hash(ptid.tid()); + } +}; + +using ptid_thread_map = std::unordered_map; + +struct all_thread_map_range_iterator +{ + all_thread_map_range_iterator (ptid_thread_map::const_iterator iter) + : m_iter (iter) + {} + + bool operator!= (const all_thread_map_range_iterator &other) + { return this->m_iter != other.m_iter; } + + void operator++ () + { this->m_iter++; } + + thread_info *operator* () + { return this->m_iter->second; } + +private: + typename ptid_thread_map::const_iterator m_iter; +}; + +struct all_thread_map_range +{ + all_thread_map_range (const ptid_thread_map &map) + : m_map (map) + {} + + all_thread_map_range_iterator begin () + { + return all_thread_map_range_iterator (this->m_map.begin ()); + } + + all_thread_map_range_iterator end () + { + return all_thread_map_range_iterator (this->m_map.end ()); + } + +private: + const ptid_thread_map &m_map; +}; + +struct non_exited_thread_map_range_iterator +{ + non_exited_thread_map_range_iterator (typename ptid_thread_map::const_iterator iter, + typename ptid_thread_map::const_iterator end) + : m_iter (iter), m_end (end) + { + advante_to_next_matching (); + } + + bool operator!= (const non_exited_thread_map_range_iterator &other) + { return this->m_iter != other.m_iter; } + + void operator++ () + { + this->m_iter++; + advante_to_next_matching (); + } + + thread_info *operator* () + { return this->m_iter->second; } + +private: + typename ptid_thread_map::const_iterator m_iter; + typename ptid_thread_map::const_iterator m_end; + + void advante_to_next_matching () + { + while (this->m_iter != this->m_end + && this->m_iter->second->state == THREAD_EXITED) + { + this->m_iter++; + } + } +}; + +struct non_exited_thread_map_range +{ + non_exited_thread_map_range (const ptid_thread_map &map) + : m_map (map) + {} + + non_exited_thread_map_range_iterator begin() + { + return non_exited_thread_map_range_iterator (this->m_map.begin (), this->m_map.end ()); + } + + non_exited_thread_map_range_iterator end() + { + return non_exited_thread_map_range_iterator (this->m_map.end (), this->m_map.end ()); + } + +private: + const ptid_thread_map &m_map; +}; + +#endif