180814287SRaphael Isemann //===-- SBThreadCollection.cpp --------------------------------------------===//
2a5ea1e2bSKuba Brecka //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a5ea1e2bSKuba Brecka //
7a5ea1e2bSKuba Brecka //===----------------------------------------------------------------------===//
8a5ea1e2bSKuba Brecka 
9a5ea1e2bSKuba Brecka #include "lldb/API/SBThreadCollection.h"
10a5ea1e2bSKuba Brecka #include "lldb/API/SBThread.h"
11a5ea1e2bSKuba Brecka #include "lldb/Target/ThreadList.h"
12*1755f5b1SJonas Devlieghere #include "lldb/Utility/Instrumentation.h"
13a5ea1e2bSKuba Brecka 
14a5ea1e2bSKuba Brecka using namespace lldb;
15a5ea1e2bSKuba Brecka using namespace lldb_private;
16a5ea1e2bSKuba Brecka 
SBThreadCollection()17*1755f5b1SJonas Devlieghere SBThreadCollection::SBThreadCollection() { LLDB_INSTRUMENT_VA(this); }
18a5ea1e2bSKuba Brecka 
SBThreadCollection(const SBThreadCollection & rhs)19b9c1b51eSKate Stone SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs)
20baf5664fSJonas Devlieghere     : m_opaque_sp(rhs.m_opaque_sp) {
21*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, rhs);
22baf5664fSJonas Devlieghere }
23a5ea1e2bSKuba Brecka 
24b9c1b51eSKate Stone const SBThreadCollection &SBThreadCollection::
operator =(const SBThreadCollection & rhs)25b9c1b51eSKate Stone operator=(const SBThreadCollection &rhs) {
26*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, rhs);
27baf5664fSJonas Devlieghere 
28a5ea1e2bSKuba Brecka   if (this != &rhs)
29a5ea1e2bSKuba Brecka     m_opaque_sp = rhs.m_opaque_sp;
30d232abc3SJonas Devlieghere   return *this;
31a5ea1e2bSKuba Brecka }
32a5ea1e2bSKuba Brecka 
SBThreadCollection(const ThreadCollectionSP & threads)33b9c1b51eSKate Stone SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads)
34b9c1b51eSKate Stone     : m_opaque_sp(threads) {}
35a5ea1e2bSKuba Brecka 
36866b7a65SJonas Devlieghere SBThreadCollection::~SBThreadCollection() = default;
37a5ea1e2bSKuba Brecka 
SetOpaque(const lldb::ThreadCollectionSP & threads)38b9c1b51eSKate Stone void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) {
39a5ea1e2bSKuba Brecka   m_opaque_sp = threads;
40a5ea1e2bSKuba Brecka }
41a5ea1e2bSKuba Brecka 
get() const42b9c1b51eSKate Stone lldb_private::ThreadCollection *SBThreadCollection::get() const {
43a5ea1e2bSKuba Brecka   return m_opaque_sp.get();
44a5ea1e2bSKuba Brecka }
45a5ea1e2bSKuba Brecka 
operator ->() const46b9c1b51eSKate Stone lldb_private::ThreadCollection *SBThreadCollection::operator->() const {
47a5ea1e2bSKuba Brecka   return m_opaque_sp.operator->();
48a5ea1e2bSKuba Brecka }
49a5ea1e2bSKuba Brecka 
operator *()50b9c1b51eSKate Stone lldb::ThreadCollectionSP &SBThreadCollection::operator*() {
51a5ea1e2bSKuba Brecka   return m_opaque_sp;
52a5ea1e2bSKuba Brecka }
53a5ea1e2bSKuba Brecka 
operator *() const54b9c1b51eSKate Stone const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const {
55a5ea1e2bSKuba Brecka   return m_opaque_sp;
56a5ea1e2bSKuba Brecka }
57a5ea1e2bSKuba Brecka 
IsValid() const58baf5664fSJonas Devlieghere bool SBThreadCollection::IsValid() const {
59*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
607f5237bcSPavel Labath   return this->operator bool();
617f5237bcSPavel Labath }
operator bool() const627f5237bcSPavel Labath SBThreadCollection::operator bool() const {
63*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
64baf5664fSJonas Devlieghere 
65248a1305SKonrad Kleine   return m_opaque_sp.get() != nullptr;
66baf5664fSJonas Devlieghere }
67a5ea1e2bSKuba Brecka 
GetSize()68b9c1b51eSKate Stone size_t SBThreadCollection::GetSize() {
69*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this);
70baf5664fSJonas Devlieghere 
71a5ea1e2bSKuba Brecka   if (m_opaque_sp)
72a5ea1e2bSKuba Brecka     return m_opaque_sp->GetSize();
73a5ea1e2bSKuba Brecka   return 0;
74a5ea1e2bSKuba Brecka }
75a5ea1e2bSKuba Brecka 
GetThreadAtIndex(size_t idx)76b9c1b51eSKate Stone SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
77*1755f5b1SJonas Devlieghere   LLDB_INSTRUMENT_VA(this, idx);
78baf5664fSJonas Devlieghere 
79a5ea1e2bSKuba Brecka   SBThread thread;
80a5ea1e2bSKuba Brecka   if (m_opaque_sp && idx < m_opaque_sp->GetSize())
81a5ea1e2bSKuba Brecka     thread = m_opaque_sp->GetThreadAtIndex(idx);
82d232abc3SJonas Devlieghere   return thread;
83a5ea1e2bSKuba Brecka }
84