1 //===-- Queue.cpp ---------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
16 using namespace lldb_private
;
18 Queue::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
) {
25 m_queue_name
= queue_name
;
27 m_process_wp
= process_sp
;
30 Queue::~Queue() = default;
32 queue_id_t
Queue::GetID() { return m_queue_id
; }
34 const char *Queue::GetName() {
35 return (m_queue_name
.empty() ? nullptr : m_queue_name
.c_str());
38 uint32_t Queue::GetIndexID() { return m_queue_id
; }
40 std::vector
<lldb::ThreadSP
> Queue::GetThreads() {
41 std::vector
<ThreadSP
> result
;
42 ProcessSP process_sp
= m_process_wp
.lock();
44 for (ThreadSP thread_sp
: process_sp
->Threads()) {
45 if (thread_sp
->GetQueueID() == m_queue_id
) {
46 result
.push_back(thread_sp
);
53 void Queue::SetNumRunningWorkItems(uint32_t count
) {
54 m_running_work_items_count
= count
;
57 uint32_t Queue::GetNumRunningWorkItems() const {
58 return m_running_work_items_count
;
61 void Queue::SetNumPendingWorkItems(uint32_t count
) {
62 m_pending_work_items_count
= count
;
65 uint32_t Queue::GetNumPendingWorkItems() const {
66 return m_pending_work_items_count
;
69 void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr
) {
70 m_dispatch_queue_t_addr
= dispatch_queue_t_addr
;
73 addr_t
Queue::GetLibdispatchQueueAddress() const {
74 return m_dispatch_queue_t_addr
;
77 const 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(this);
84 return m_pending_items
;
87 lldb::QueueKind
Queue::GetKind() { return m_kind
; }
89 void Queue::SetKind(lldb::QueueKind kind
) { m_kind
= kind
; }