LLDB  mainline
Queue.cpp
Go to the documentation of this file.
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"
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 
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 
55 }
56 
59 }
60 
63 }
64 
67 }
68 
69 void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
70  m_dispatch_queue_t_addr = dispatch_queue_t_addr;
71 }
72 
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 
88 
89 void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }
lldb_private::Queue::GetNumPendingWorkItems
uint32_t GetNumPendingWorkItems() const
Get the number of work items enqueued on this queue.
Definition: Queue.cpp:65
lldb_private::Queue::m_pending_work_items_count
uint32_t m_pending_work_items_count
Definition: Queue.h:141
lldb_private::Queue::m_queue_name
std::string m_queue_name
Definition: Queue.h:139
lldb_private::Queue::GetName
const char * GetName()
Get the name of this Queue.
Definition: Queue.cpp:34
lldb_private::Queue::m_pending_items
std::vector< lldb::QueueItemSP > m_pending_items
Definition: Queue.h:142
lldb_private::Queue::SetKind
void SetKind(lldb::QueueKind kind)
Definition: Queue.cpp:89
lldb_private::Queue::SetNumRunningWorkItems
void SetNumRunningWorkItems(uint32_t count)
Definition: Queue.cpp:53
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::Queue::GetIndexID
uint32_t GetIndexID()
Get the IndexID for this Queue.
Definition: Queue.cpp:38
Process.h
lldb::queue_id_t
uint64_t queue_id_t
Definition: lldb-types.h:91
lldb_private::Queue::GetPendingItems
const std::vector< lldb::QueueItemSP > & GetPendingItems()
Return the items that are currently enqueued.
Definition: Queue.cpp:77
lldb_private::Queue::m_dispatch_queue_t_addr
lldb::addr_t m_dispatch_queue_t_addr
Definition: Queue.h:143
lldb::eQueueKindUnknown
@ eQueueKindUnknown
Definition: lldb-enumerations.h:945
Thread.h
Queue.h
lldb_private::Queue::m_process_wp
lldb::ProcessWP m_process_wp
Definition: Queue.h:137
lldb_private::Queue::SetLibdispatchQueueAddress
void SetLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t_addr)
Definition: Queue.cpp:69
uint32_t
lldb_private::Queue::m_queue_id
lldb::queue_id_t m_queue_id
Definition: Queue.h:138
SystemRuntime.h
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::Queue::m_kind
lldb::QueueKind m_kind
Definition: Queue.h:145
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Queue::GetKind
lldb::QueueKind GetKind()
Return the kind (serial, concurrent) of this queue.
Definition: Queue.cpp:87
lldb_private::Queue::GetLibdispatchQueueAddress
lldb::addr_t GetLibdispatchQueueAddress() const
Get the dispatch_queue_t structure address for this Queue.
Definition: Queue.cpp:73
lldb_private::Queue::SetNumPendingWorkItems
void SetNumPendingWorkItems(uint32_t count)
Definition: Queue.cpp:61
lldb_private::Queue::m_running_work_items_count
uint32_t m_running_work_items_count
Definition: Queue.h:140
lldb_private::Queue::GetNumRunningWorkItems
uint32_t GetNumRunningWorkItems() const
Get the number of work items that this queue is currently running.
Definition: Queue.cpp:57
lldb
Definition: SBAddress.h:15
QueueList.h
lldb::QueueKind
QueueKind
Queue type.
Definition: lldb-enumerations.h:944
lldb_private::Queue::GetThreads
std::vector< lldb::ThreadSP > GetThreads()
Return the threads currently associated with this queue.
Definition: Queue.cpp:40