blob: dc1e38e02420e1f5f2aabe9371249cc6df5977db [file] [log] [blame]
Kuba Breckae4d48012014-09-05 19:13:15 +00001//===-- 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
15using namespace lldb;
16using namespace lldb_private;
17
18ThreadCollection::ThreadCollection() :
19 m_threads(),
20 m_mutex()
21{
22}
23
24ThreadCollection::ThreadCollection(collection threads) :
25 m_threads(threads),
26 m_mutex()
27{
28}
29
30void
31ThreadCollection::AddThread (const ThreadSP &thread_sp)
32{
33 Mutex::Locker locker(GetMutex());
34 m_threads.push_back (thread_sp);
35}
36
37void
38ThreadCollection::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
47uint32_t
48ThreadCollection::GetSize ()
49{
50 Mutex::Locker locker(GetMutex());
51 return m_threads.size();
52}
53
54ThreadSP
55ThreadCollection::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}