1a5ea1e2bSKuba Brecka //===-- SBThreadCollection.cpp ----------------------------------*- C++ -*-===//
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"
10*baf5664fSJonas Devlieghere #include "SBReproducerPrivate.h"
11a5ea1e2bSKuba Brecka #include "lldb/API/SBThread.h"
12a5ea1e2bSKuba Brecka #include "lldb/Target/ThreadList.h"
13a5ea1e2bSKuba Brecka 
14a5ea1e2bSKuba Brecka using namespace lldb;
15a5ea1e2bSKuba Brecka using namespace lldb_private;
16a5ea1e2bSKuba Brecka 
17*baf5664fSJonas Devlieghere SBThreadCollection::SBThreadCollection() : m_opaque_sp() {
18*baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBThreadCollection);
19*baf5664fSJonas Devlieghere }
20a5ea1e2bSKuba Brecka 
21b9c1b51eSKate Stone SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs)
22*baf5664fSJonas Devlieghere     : m_opaque_sp(rhs.m_opaque_sp) {
23*baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBThreadCollection,
24*baf5664fSJonas Devlieghere                           (const lldb::SBThreadCollection &), rhs);
25*baf5664fSJonas Devlieghere }
26a5ea1e2bSKuba Brecka 
27b9c1b51eSKate Stone const SBThreadCollection &SBThreadCollection::
28b9c1b51eSKate Stone operator=(const SBThreadCollection &rhs) {
29*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(
30*baf5664fSJonas Devlieghere       const lldb::SBThreadCollection &,
31*baf5664fSJonas Devlieghere       SBThreadCollection, operator=,(const lldb::SBThreadCollection &), rhs);
32*baf5664fSJonas Devlieghere 
33a5ea1e2bSKuba Brecka   if (this != &rhs)
34a5ea1e2bSKuba Brecka     m_opaque_sp = rhs.m_opaque_sp;
35a5ea1e2bSKuba Brecka   return *this;
36a5ea1e2bSKuba Brecka }
37a5ea1e2bSKuba Brecka 
38b9c1b51eSKate Stone SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads)
39b9c1b51eSKate Stone     : m_opaque_sp(threads) {}
40a5ea1e2bSKuba Brecka 
41b9c1b51eSKate Stone SBThreadCollection::~SBThreadCollection() {}
42a5ea1e2bSKuba Brecka 
43b9c1b51eSKate Stone void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) {
44a5ea1e2bSKuba Brecka   m_opaque_sp = threads;
45a5ea1e2bSKuba Brecka }
46a5ea1e2bSKuba Brecka 
47b9c1b51eSKate Stone lldb_private::ThreadCollection *SBThreadCollection::get() const {
48a5ea1e2bSKuba Brecka   return m_opaque_sp.get();
49a5ea1e2bSKuba Brecka }
50a5ea1e2bSKuba Brecka 
51b9c1b51eSKate Stone lldb_private::ThreadCollection *SBThreadCollection::operator->() const {
52a5ea1e2bSKuba Brecka   return m_opaque_sp.operator->();
53a5ea1e2bSKuba Brecka }
54a5ea1e2bSKuba Brecka 
55b9c1b51eSKate Stone lldb::ThreadCollectionSP &SBThreadCollection::operator*() {
56a5ea1e2bSKuba Brecka   return m_opaque_sp;
57a5ea1e2bSKuba Brecka }
58a5ea1e2bSKuba Brecka 
59b9c1b51eSKate Stone const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const {
60a5ea1e2bSKuba Brecka   return m_opaque_sp;
61a5ea1e2bSKuba Brecka }
62a5ea1e2bSKuba Brecka 
63*baf5664fSJonas Devlieghere bool SBThreadCollection::IsValid() const {
64*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBThreadCollection, IsValid);
65*baf5664fSJonas Devlieghere 
66*baf5664fSJonas Devlieghere   return m_opaque_sp.get() != NULL;
67*baf5664fSJonas Devlieghere }
68a5ea1e2bSKuba Brecka 
69b9c1b51eSKate Stone size_t SBThreadCollection::GetSize() {
70*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(size_t, SBThreadCollection, GetSize);
71*baf5664fSJonas Devlieghere 
72a5ea1e2bSKuba Brecka   if (m_opaque_sp)
73a5ea1e2bSKuba Brecka     return m_opaque_sp->GetSize();
74a5ea1e2bSKuba Brecka   return 0;
75a5ea1e2bSKuba Brecka }
76a5ea1e2bSKuba Brecka 
77b9c1b51eSKate Stone SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
78*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(lldb::SBThread, SBThreadCollection, GetThreadAtIndex,
79*baf5664fSJonas Devlieghere                      (size_t), idx);
80*baf5664fSJonas Devlieghere 
81a5ea1e2bSKuba Brecka   SBThread thread;
82a5ea1e2bSKuba Brecka   if (m_opaque_sp && idx < m_opaque_sp->GetSize())
83a5ea1e2bSKuba Brecka     thread = m_opaque_sp->GetThreadAtIndex(idx);
84*baf5664fSJonas Devlieghere   return LLDB_RECORD_RESULT(thread);
85a5ea1e2bSKuba Brecka }
86