1 //===-- ThreadCollection.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_TARGET_THREADCOLLECTION_H 10 #define LLDB_TARGET_THREADCOLLECTION_H 11 12 #include <mutex> 13 #include <vector> 14 15 #include "lldb/Utility/Iterable.h" 16 #include "lldb/lldb-private.h" 17 18 namespace lldb_private { 19 20 class ThreadCollection { 21 public: 22 typedef std::vector<lldb::ThreadSP> collection; 23 typedef LockingAdaptedIterable<std::recursive_mutex, collection> 24 ThreadIterable; 25 26 ThreadCollection(); 27 28 ThreadCollection(collection threads); 29 30 virtual ~ThreadCollection() = default; 31 32 uint32_t GetSize(); 33 34 void AddThread(const lldb::ThreadSP &thread_sp); 35 36 void AddThreadSortedByIndexID(const lldb::ThreadSP &thread_sp); 37 38 void InsertThread(const lldb::ThreadSP &thread_sp, uint32_t idx); 39 40 // Note that "idx" is not the same as the "thread_index". It is a zero based 41 // index to accessing the current threads, whereas "thread_index" is a unique 42 // index assigned 43 lldb::ThreadSP GetThreadAtIndex(uint32_t idx); 44 Threads()45 virtual ThreadIterable Threads() { 46 return ThreadIterable(m_threads, GetMutex()); 47 } 48 GetMutex()49 virtual std::recursive_mutex &GetMutex() const { return m_mutex; } 50 51 protected: 52 collection m_threads; 53 mutable std::recursive_mutex m_mutex; 54 }; 55 56 } // namespace lldb_private 57 58 #endif // LLDB_TARGET_THREADCOLLECTION_H 59