1//===-- Queue.cpp ---------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Target/Queue.h"
10#include "lldb/Target/Process.h"
11#include "lldb/Target/QueueList.h"
12#include "lldb/Target/SystemRuntime.h"
13#include "lldb/Target/Thread.h"
14
15using namespace lldb;
16using namespace lldb_private;
17
18Queue::Queue(ProcessSP process_sp, lldb::queue_id_t queue_id,
19 const char *queue_name)
20 : m_process_wp(), m_queue_id(queue_id), m_queue_name(),
21 m_running_work_items_count(0), m_pending_work_items_count(0),
22 m_pending_items(), m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS),
23 m_kind(eQueueKindUnknown) {
24 if (queue_name)
25 m_queue_name = queue_name;
26
27 m_process_wp = process_sp;
28}
29
30Queue::~Queue() = default;
31
32queue_id_t Queue::GetID() { return m_queue_id; }
33
34const char *Queue::GetName() {
35 return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
36}
37
38uint32_t Queue::GetIndexID() { return m_queue_id; }
39
40std::vector<lldb::ThreadSP> Queue::GetThreads() {
41 std::vector<ThreadSP> result;
42 ProcessSP process_sp = m_process_wp.lock();
43 if (process_sp) {
44 for (ThreadSP thread_sp : process_sp->Threads()) {
45 if (thread_sp->GetQueueID() == m_queue_id) {
46 result.push_back(x: thread_sp);
47 }
48 }
49 }
50 return result;
51}
52
53void Queue::SetNumRunningWorkItems(uint32_t count) {
54 m_running_work_items_count = count;
55}
56
57uint32_t Queue::GetNumRunningWorkItems() const {
58 return m_running_work_items_count;
59}
60
61void Queue::SetNumPendingWorkItems(uint32_t count) {
62 m_pending_work_items_count = count;
63}
64
65uint32_t Queue::GetNumPendingWorkItems() const {
66 return m_pending_work_items_count;
67}
68
69void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
70 m_dispatch_queue_t_addr = dispatch_queue_t_addr;
71}
72
73addr_t Queue::GetLibdispatchQueueAddress() const {
74 return m_dispatch_queue_t_addr;
75}
76
77const std::vector<lldb::QueueItemSP> &Queue::GetPendingItems() {
78 if (m_pending_items.empty()) {
79 ProcessSP process_sp = m_process_wp.lock();
80 if (process_sp && process_sp->GetSystemRuntime()) {
81 process_sp->GetSystemRuntime()->PopulatePendingItemsForQueue(queue: this);
82 }
83 }
84 return m_pending_items;
85}
86
87lldb::QueueKind Queue::GetKind() { return m_kind; }
88
89void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }
90

source code of lldb/source/Target/Queue.cpp