]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Target/Queue.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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 #include "lldb/Target/Queue.h"
11 #include "lldb/Target/Process.h"
12 #include "lldb/Target/QueueList.h"
13 #include "lldb/Target/SystemRuntime.h"
14 #include "lldb/Target/Thread.h"
15
16 using namespace lldb;
17 using namespace lldb_private;
18
19 Queue::Queue(ProcessSP process_sp, lldb::queue_id_t queue_id,
20              const char *queue_name)
21     : m_process_wp(), m_queue_id(queue_id), m_queue_name(),
22       m_running_work_items_count(0), m_pending_work_items_count(0),
23       m_pending_items(), m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS),
24       m_kind(eQueueKindUnknown) {
25   if (queue_name)
26     m_queue_name = queue_name;
27
28   m_process_wp = process_sp;
29 }
30
31 Queue::~Queue() = default;
32
33 queue_id_t Queue::GetID() { return m_queue_id; }
34
35 const char *Queue::GetName() {
36   return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
37 }
38
39 uint32_t Queue::GetIndexID() { return m_queue_id; }
40
41 std::vector<lldb::ThreadSP> Queue::GetThreads() {
42   std::vector<ThreadSP> result;
43   ProcessSP process_sp = m_process_wp.lock();
44   if (process_sp) {
45     for (ThreadSP thread_sp : process_sp->Threads()) {
46       if (thread_sp->GetQueueID() == m_queue_id) {
47         result.push_back(thread_sp);
48       }
49     }
50   }
51   return result;
52 }
53
54 void Queue::SetNumRunningWorkItems(uint32_t count) {
55   m_running_work_items_count = count;
56 }
57
58 uint32_t Queue::GetNumRunningWorkItems() const {
59   return m_running_work_items_count;
60 }
61
62 void Queue::SetNumPendingWorkItems(uint32_t count) {
63   m_pending_work_items_count = count;
64 }
65
66 uint32_t Queue::GetNumPendingWorkItems() const {
67   return m_pending_work_items_count;
68 }
69
70 void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
71   m_dispatch_queue_t_addr = dispatch_queue_t_addr;
72 }
73
74 addr_t Queue::GetLibdispatchQueueAddress() const {
75   return m_dispatch_queue_t_addr;
76 }
77
78 const std::vector<lldb::QueueItemSP> &Queue::GetPendingItems() {
79   if (m_pending_items.empty()) {
80     ProcessSP process_sp = m_process_wp.lock();
81     if (process_sp && process_sp->GetSystemRuntime()) {
82       process_sp->GetSystemRuntime()->PopulatePendingItemsForQueue(this);
83     }
84   }
85   return m_pending_items;
86 }
87
88 lldb::QueueKind Queue::GetKind() { return m_kind; }
89
90 void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }