1 //===-- ThreadCollection.cpp ------------------------------------*- 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 #include <stdlib.h> 10 11 #include <algorithm> 12 13 #include "lldb/Target/ThreadCollection.h" 14 15 using namespace lldb; 16 using namespace lldb_private; 17 18 ThreadCollection::ThreadCollection() : 19 m_threads(), 20 m_mutex() 21 { 22 } 23 24 ThreadCollection::ThreadCollection(collection threads) : 25 m_threads(threads), 26 m_mutex() 27 { 28 } 29 30 void 31 ThreadCollection::AddThread (const ThreadSP &thread_sp) 32 { 33 std::lock_guard<std::recursive_mutex> guard(GetMutex()); 34 m_threads.push_back (thread_sp); 35 } 36 37 void 38 ThreadCollection::InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx) 39 { 40 std::lock_guard<std::recursive_mutex> guard(GetMutex()); 41 if (idx < m_threads.size()) 42 m_threads.insert(m_threads.begin() + idx, thread_sp); 43 else 44 m_threads.push_back (thread_sp); 45 } 46 47 uint32_t 48 ThreadCollection::GetSize () 49 { 50 std::lock_guard<std::recursive_mutex> guard(GetMutex()); 51 return m_threads.size(); 52 } 53 54 ThreadSP 55 ThreadCollection::GetThreadAtIndex (uint32_t idx) 56 { 57 std::lock_guard<std::recursive_mutex> guard(GetMutex()); 58 ThreadSP thread_sp; 59 if (idx < m_threads.size()) 60 thread_sp = m_threads[idx]; 61 return thread_sp; 62 } 63