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