1 //===-- Queue.cpp -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // Other libraries and framework includes
14 #include "lldb/Target/Queue.h"
15 #include "lldb/Target/Process.h"
16 #include "lldb/Target/QueueList.h"
17 #include "lldb/Target/SystemRuntime.h"
18 #include "lldb/Target/Thread.h"
21 using namespace lldb_private;
23 Queue::Queue(ProcessSP process_sp, lldb::queue_id_t queue_id,
24 const char *queue_name)
25 : m_process_wp(), m_queue_id(queue_id), m_queue_name(),
26 m_running_work_items_count(0), m_pending_work_items_count(0),
27 m_pending_items(), m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS),
28 m_kind(eQueueKindUnknown) {
30 m_queue_name = queue_name;
32 m_process_wp = process_sp;
35 Queue::~Queue() = default;
37 queue_id_t Queue::GetID() { return m_queue_id; }
39 const char *Queue::GetName() {
40 return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
43 uint32_t Queue::GetIndexID() { return m_queue_id; }
45 std::vector<lldb::ThreadSP> Queue::GetThreads() {
46 std::vector<ThreadSP> result;
47 ProcessSP process_sp = m_process_wp.lock();
49 for (ThreadSP thread_sp : process_sp->Threads()) {
50 if (thread_sp->GetQueueID() == m_queue_id) {
51 result.push_back(thread_sp);
58 void Queue::SetNumRunningWorkItems(uint32_t count) {
59 m_running_work_items_count = count;
62 uint32_t Queue::GetNumRunningWorkItems() const {
63 return m_running_work_items_count;
66 void Queue::SetNumPendingWorkItems(uint32_t count) {
67 m_pending_work_items_count = count;
70 uint32_t Queue::GetNumPendingWorkItems() const {
71 return m_pending_work_items_count;
74 void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
75 m_dispatch_queue_t_addr = dispatch_queue_t_addr;
78 addr_t Queue::GetLibdispatchQueueAddress() const {
79 return m_dispatch_queue_t_addr;
82 const std::vector<lldb::QueueItemSP> &Queue::GetPendingItems() {
83 if (m_pending_items.empty()) {
84 ProcessSP process_sp = m_process_wp.lock();
85 if (process_sp && process_sp->GetSystemRuntime()) {
86 process_sp->GetSystemRuntime()->PopulatePendingItemsForQueue(this);
89 return m_pending_items;
92 lldb::QueueKind Queue::GetKind() { return m_kind; }
94 void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }