Kuba Brecka | e4d4801 | 2014-09-05 19:13:15 +0000 | [diff] [blame^] | 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 | Mutex::Locker locker(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 | Mutex::Locker locker(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 | Mutex::Locker locker(GetMutex()); |
| 51 | return m_threads.size(); |
| 52 | } |
| 53 | |
| 54 | ThreadSP |
| 55 | ThreadCollection::GetThreadAtIndex (uint32_t idx) |
| 56 | { |
| 57 | Mutex::Locker locker(GetMutex()); |
| 58 | ThreadSP thread_sp; |
| 59 | if (idx < m_threads.size()) |
| 60 | thread_sp = m_threads[idx]; |
| 61 | return thread_sp; |
| 62 | } |