]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Target/Queue.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Target / Queue.cpp
1 //===-- Queue.cpp -----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // C Includes
11 // C++ Includes
12 // Other libraries and framework includes
13 // Project 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"
19
20 using namespace lldb;
21 using namespace lldb_private;
22
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) {
29   if (queue_name)
30     m_queue_name = queue_name;
31
32   m_process_wp = process_sp;
33 }
34
35 Queue::~Queue() = default;
36
37 queue_id_t Queue::GetID() { return m_queue_id; }
38
39 const char *Queue::GetName() {
40   return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
41 }
42
43 uint32_t Queue::GetIndexID() { return m_queue_id; }
44
45 std::vector<lldb::ThreadSP> Queue::GetThreads() {
46   std::vector<ThreadSP> result;
47   ProcessSP process_sp = m_process_wp.lock();
48   if (process_sp) {
49     for (ThreadSP thread_sp : process_sp->Threads()) {
50       if (thread_sp->GetQueueID() == m_queue_id) {
51         result.push_back(thread_sp);
52       }
53     }
54   }
55   return result;
56 }
57
58 void Queue::SetNumRunningWorkItems(uint32_t count) {
59   m_running_work_items_count = count;
60 }
61
62 uint32_t Queue::GetNumRunningWorkItems() const {
63   return m_running_work_items_count;
64 }
65
66 void Queue::SetNumPendingWorkItems(uint32_t count) {
67   m_pending_work_items_count = count;
68 }
69
70 uint32_t Queue::GetNumPendingWorkItems() const {
71   return m_pending_work_items_count;
72 }
73
74 void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
75   m_dispatch_queue_t_addr = dispatch_queue_t_addr;
76 }
77
78 addr_t Queue::GetLibdispatchQueueAddress() const {
79   return m_dispatch_queue_t_addr;
80 }
81
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);
87     }
88   }
89   return m_pending_items;
90 }
91
92 lldb::QueueKind Queue::GetKind() { return m_kind; }
93
94 void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }