xref: /freebsd-src/contrib/llvm-project/lldb/source/API/SBThreadCollection.cpp (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
15ffd83dbSDimitry Andric //===-- SBThreadCollection.cpp --------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/API/SBThreadCollection.h"
100b57cec5SDimitry Andric #include "lldb/API/SBThread.h"
110b57cec5SDimitry Andric #include "lldb/Target/ThreadList.h"
12*04eeddc0SDimitry Andric #include "lldb/Utility/Instrumentation.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric using namespace lldb;
150b57cec5SDimitry Andric using namespace lldb_private;
160b57cec5SDimitry Andric 
SBThreadCollection()17*04eeddc0SDimitry Andric SBThreadCollection::SBThreadCollection() { LLDB_INSTRUMENT_VA(this); }
180b57cec5SDimitry Andric 
SBThreadCollection(const SBThreadCollection & rhs)190b57cec5SDimitry Andric SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs)
200b57cec5SDimitry Andric     : m_opaque_sp(rhs.m_opaque_sp) {
21*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
220b57cec5SDimitry Andric }
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric const SBThreadCollection &SBThreadCollection::
operator =(const SBThreadCollection & rhs)250b57cec5SDimitry Andric operator=(const SBThreadCollection &rhs) {
26*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric   if (this != &rhs)
290b57cec5SDimitry Andric     m_opaque_sp = rhs.m_opaque_sp;
30*04eeddc0SDimitry Andric   return *this;
310b57cec5SDimitry Andric }
320b57cec5SDimitry Andric 
SBThreadCollection(const ThreadCollectionSP & threads)330b57cec5SDimitry Andric SBThreadCollection::SBThreadCollection(const ThreadCollectionSP &threads)
340b57cec5SDimitry Andric     : m_opaque_sp(threads) {}
350b57cec5SDimitry Andric 
365ffd83dbSDimitry Andric SBThreadCollection::~SBThreadCollection() = default;
370b57cec5SDimitry Andric 
SetOpaque(const lldb::ThreadCollectionSP & threads)380b57cec5SDimitry Andric void SBThreadCollection::SetOpaque(const lldb::ThreadCollectionSP &threads) {
390b57cec5SDimitry Andric   m_opaque_sp = threads;
400b57cec5SDimitry Andric }
410b57cec5SDimitry Andric 
get() const420b57cec5SDimitry Andric lldb_private::ThreadCollection *SBThreadCollection::get() const {
430b57cec5SDimitry Andric   return m_opaque_sp.get();
440b57cec5SDimitry Andric }
450b57cec5SDimitry Andric 
operator ->() const460b57cec5SDimitry Andric lldb_private::ThreadCollection *SBThreadCollection::operator->() const {
470b57cec5SDimitry Andric   return m_opaque_sp.operator->();
480b57cec5SDimitry Andric }
490b57cec5SDimitry Andric 
operator *()500b57cec5SDimitry Andric lldb::ThreadCollectionSP &SBThreadCollection::operator*() {
510b57cec5SDimitry Andric   return m_opaque_sp;
520b57cec5SDimitry Andric }
530b57cec5SDimitry Andric 
operator *() const540b57cec5SDimitry Andric const lldb::ThreadCollectionSP &SBThreadCollection::operator*() const {
550b57cec5SDimitry Andric   return m_opaque_sp;
560b57cec5SDimitry Andric }
570b57cec5SDimitry Andric 
IsValid() const580b57cec5SDimitry Andric bool SBThreadCollection::IsValid() const {
59*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
600b57cec5SDimitry Andric   return this->operator bool();
610b57cec5SDimitry Andric }
operator bool() const620b57cec5SDimitry Andric SBThreadCollection::operator bool() const {
63*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   return m_opaque_sp.get() != nullptr;
660b57cec5SDimitry Andric }
670b57cec5SDimitry Andric 
GetSize()680b57cec5SDimitry Andric size_t SBThreadCollection::GetSize() {
69*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this);
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   if (m_opaque_sp)
720b57cec5SDimitry Andric     return m_opaque_sp->GetSize();
730b57cec5SDimitry Andric   return 0;
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric 
GetThreadAtIndex(size_t idx)760b57cec5SDimitry Andric SBThread SBThreadCollection::GetThreadAtIndex(size_t idx) {
77*04eeddc0SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx);
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   SBThread thread;
800b57cec5SDimitry Andric   if (m_opaque_sp && idx < m_opaque_sp->GetSize())
810b57cec5SDimitry Andric     thread = m_opaque_sp->GetThreadAtIndex(idx);
82*04eeddc0SDimitry Andric   return thread;
830b57cec5SDimitry Andric }
84