]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Target/Queue.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Target / Queue.cpp
1 //===-- Queue.cpp -----------------------------------------------*- C++ -*-===//
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
15 using namespace lldb;
16 using namespace lldb_private;
17
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) {
24   if (queue_name)
25     m_queue_name = queue_name;
26
27   m_process_wp = process_sp;
28 }
29
30 Queue::~Queue() = default;
31
32 queue_id_t Queue::GetID() { return m_queue_id; }
33
34 const char *Queue::GetName() {
35   return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
36 }
37
38 uint32_t Queue::GetIndexID() { return m_queue_id; }
39
40 std::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(thread_sp);
47       }
48     }
49   }
50   return result;
51 }
52
53 void Queue::SetNumRunningWorkItems(uint32_t count) {
54   m_running_work_items_count = count;
55 }
56
57 uint32_t Queue::GetNumRunningWorkItems() const {
58   return m_running_work_items_count;
59 }
60
61 void Queue::SetNumPendingWorkItems(uint32_t count) {
62   m_pending_work_items_count = count;
63 }
64
65 uint32_t Queue::GetNumPendingWorkItems() const {
66   return m_pending_work_items_count;
67 }
68
69 void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
70   m_dispatch_queue_t_addr = dispatch_queue_t_addr;
71 }
72
73 addr_t Queue::GetLibdispatchQueueAddress() const {
74   return m_dispatch_queue_t_addr;
75 }
76
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);
82     }
83   }
84   return m_pending_items;
85 }
86
87 lldb::QueueKind Queue::GetKind() { return m_kind; }
88
89 void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }