xref: /src/contrib/llvm-project/lldb/source/Target/Queue.cpp (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
1cfca06d7SDimitry Andric //===-- Queue.cpp ---------------------------------------------------------===//
2866dcdacSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6866dcdacSEd Maste //
7866dcdacSEd Maste //===----------------------------------------------------------------------===//
8866dcdacSEd Maste 
9866dcdacSEd Maste #include "lldb/Target/Queue.h"
1014f1b3e8SDimitry Andric #include "lldb/Target/Process.h"
11866dcdacSEd Maste #include "lldb/Target/QueueList.h"
12866dcdacSEd Maste #include "lldb/Target/SystemRuntime.h"
1314f1b3e8SDimitry Andric #include "lldb/Target/Thread.h"
14866dcdacSEd Maste 
15866dcdacSEd Maste using namespace lldb;
16866dcdacSEd Maste using namespace lldb_private;
17866dcdacSEd Maste 
Queue(ProcessSP process_sp,lldb::queue_id_t queue_id,const char * queue_name)1814f1b3e8SDimitry Andric Queue::Queue(ProcessSP process_sp, lldb::queue_id_t queue_id,
1914f1b3e8SDimitry Andric              const char *queue_name)
2014f1b3e8SDimitry Andric     : m_process_wp(), m_queue_id(queue_id), m_queue_name(),
2114f1b3e8SDimitry Andric       m_running_work_items_count(0), m_pending_work_items_count(0),
2214f1b3e8SDimitry Andric       m_pending_items(), m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS),
2314f1b3e8SDimitry Andric       m_kind(eQueueKindUnknown) {
24866dcdacSEd Maste   if (queue_name)
25866dcdacSEd Maste     m_queue_name = queue_name;
26866dcdacSEd Maste 
27866dcdacSEd Maste   m_process_wp = process_sp;
28866dcdacSEd Maste }
29866dcdacSEd Maste 
30f3fbd1c0SDimitry Andric Queue::~Queue() = default;
31866dcdacSEd Maste 
GetID()3214f1b3e8SDimitry Andric queue_id_t Queue::GetID() { return m_queue_id; }
33866dcdacSEd Maste 
GetName()3414f1b3e8SDimitry Andric const char *Queue::GetName() {
35f3fbd1c0SDimitry Andric   return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
36866dcdacSEd Maste }
37866dcdacSEd Maste 
GetIndexID()3814f1b3e8SDimitry Andric uint32_t Queue::GetIndexID() { return m_queue_id; }
39866dcdacSEd Maste 
GetThreads()4014f1b3e8SDimitry Andric std::vector<lldb::ThreadSP> Queue::GetThreads() {
41866dcdacSEd Maste   std::vector<ThreadSP> result;
42866dcdacSEd Maste   ProcessSP process_sp = m_process_wp.lock();
4314f1b3e8SDimitry Andric   if (process_sp) {
4414f1b3e8SDimitry Andric     for (ThreadSP thread_sp : process_sp->Threads()) {
4514f1b3e8SDimitry Andric       if (thread_sp->GetQueueID() == m_queue_id) {
46866dcdacSEd Maste         result.push_back(thread_sp);
47866dcdacSEd Maste       }
48866dcdacSEd Maste     }
49866dcdacSEd Maste   }
50866dcdacSEd Maste   return result;
51866dcdacSEd Maste }
52866dcdacSEd Maste 
SetNumRunningWorkItems(uint32_t count)5314f1b3e8SDimitry Andric void Queue::SetNumRunningWorkItems(uint32_t count) {
54866dcdacSEd Maste   m_running_work_items_count = count;
55866dcdacSEd Maste }
56866dcdacSEd Maste 
GetNumRunningWorkItems() const5714f1b3e8SDimitry Andric uint32_t Queue::GetNumRunningWorkItems() const {
58866dcdacSEd Maste   return m_running_work_items_count;
59866dcdacSEd Maste }
60866dcdacSEd Maste 
SetNumPendingWorkItems(uint32_t count)6114f1b3e8SDimitry Andric void Queue::SetNumPendingWorkItems(uint32_t count) {
62866dcdacSEd Maste   m_pending_work_items_count = count;
63866dcdacSEd Maste }
64866dcdacSEd Maste 
GetNumPendingWorkItems() const6514f1b3e8SDimitry Andric uint32_t Queue::GetNumPendingWorkItems() const {
66866dcdacSEd Maste   return m_pending_work_items_count;
67866dcdacSEd Maste }
68866dcdacSEd Maste 
SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr)6914f1b3e8SDimitry Andric void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
70866dcdacSEd Maste   m_dispatch_queue_t_addr = dispatch_queue_t_addr;
71866dcdacSEd Maste }
72866dcdacSEd Maste 
GetLibdispatchQueueAddress() const7314f1b3e8SDimitry Andric addr_t Queue::GetLibdispatchQueueAddress() const {
74866dcdacSEd Maste   return m_dispatch_queue_t_addr;
75866dcdacSEd Maste }
76866dcdacSEd Maste 
GetPendingItems()7714f1b3e8SDimitry Andric const std::vector<lldb::QueueItemSP> &Queue::GetPendingItems() {
7814f1b3e8SDimitry Andric   if (m_pending_items.empty()) {
79866dcdacSEd Maste     ProcessSP process_sp = m_process_wp.lock();
8014f1b3e8SDimitry Andric     if (process_sp && process_sp->GetSystemRuntime()) {
81866dcdacSEd Maste       process_sp->GetSystemRuntime()->PopulatePendingItemsForQueue(this);
82866dcdacSEd Maste     }
83866dcdacSEd Maste   }
84866dcdacSEd Maste   return m_pending_items;
85866dcdacSEd Maste }
860cac4ca3SEd Maste 
GetKind()8714f1b3e8SDimitry Andric lldb::QueueKind Queue::GetKind() { return m_kind; }
880cac4ca3SEd Maste 
SetKind(lldb::QueueKind kind)8914f1b3e8SDimitry Andric void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }
90