112b93ac6SEd Maste //===-- Queue.cpp -----------------------------------------------*- C++ -*-===//
212b93ac6SEd Maste //
312b93ac6SEd Maste // The LLVM Compiler Infrastructure
412b93ac6SEd Maste //
512b93ac6SEd Maste // This file is distributed under the University of Illinois Open Source
612b93ac6SEd Maste // License. See LICENSE.TXT for details.
712b93ac6SEd Maste //
812b93ac6SEd Maste //===----------------------------------------------------------------------===//
912b93ac6SEd Maste
1012b93ac6SEd Maste #include "lldb/Target/Queue.h"
11435933ddSDimitry Andric #include "lldb/Target/Process.h"
1212b93ac6SEd Maste #include "lldb/Target/QueueList.h"
1312b93ac6SEd Maste #include "lldb/Target/SystemRuntime.h"
14435933ddSDimitry Andric #include "lldb/Target/Thread.h"
1512b93ac6SEd Maste
1612b93ac6SEd Maste using namespace lldb;
1712b93ac6SEd Maste using namespace lldb_private;
1812b93ac6SEd Maste
Queue(ProcessSP process_sp,lldb::queue_id_t queue_id,const char * queue_name)19435933ddSDimitry Andric Queue::Queue(ProcessSP process_sp, lldb::queue_id_t queue_id,
20435933ddSDimitry Andric const char *queue_name)
21435933ddSDimitry Andric : m_process_wp(), m_queue_id(queue_id), m_queue_name(),
22435933ddSDimitry Andric m_running_work_items_count(0), m_pending_work_items_count(0),
23435933ddSDimitry Andric m_pending_items(), m_dispatch_queue_t_addr(LLDB_INVALID_ADDRESS),
24435933ddSDimitry Andric m_kind(eQueueKindUnknown) {
2512b93ac6SEd Maste if (queue_name)
2612b93ac6SEd Maste m_queue_name = queue_name;
2712b93ac6SEd Maste
2812b93ac6SEd Maste m_process_wp = process_sp;
2912b93ac6SEd Maste }
3012b93ac6SEd Maste
314bb0738eSEd Maste Queue::~Queue() = default;
3212b93ac6SEd Maste
GetID()33435933ddSDimitry Andric queue_id_t Queue::GetID() { return m_queue_id; }
3412b93ac6SEd Maste
GetName()35435933ddSDimitry Andric const char *Queue::GetName() {
364bb0738eSEd Maste return (m_queue_name.empty() ? nullptr : m_queue_name.c_str());
3712b93ac6SEd Maste }
3812b93ac6SEd Maste
GetIndexID()39435933ddSDimitry Andric uint32_t Queue::GetIndexID() { return m_queue_id; }
4012b93ac6SEd Maste
GetThreads()41435933ddSDimitry Andric std::vector<lldb::ThreadSP> Queue::GetThreads() {
4212b93ac6SEd Maste std::vector<ThreadSP> result;
4312b93ac6SEd Maste ProcessSP process_sp = m_process_wp.lock();
44435933ddSDimitry Andric if (process_sp) {
45435933ddSDimitry Andric for (ThreadSP thread_sp : process_sp->Threads()) {
46435933ddSDimitry Andric if (thread_sp->GetQueueID() == m_queue_id) {
4712b93ac6SEd Maste result.push_back(thread_sp);
4812b93ac6SEd Maste }
4912b93ac6SEd Maste }
5012b93ac6SEd Maste }
5112b93ac6SEd Maste return result;
5212b93ac6SEd Maste }
5312b93ac6SEd Maste
SetNumRunningWorkItems(uint32_t count)54435933ddSDimitry Andric void Queue::SetNumRunningWorkItems(uint32_t count) {
5512b93ac6SEd Maste m_running_work_items_count = count;
5612b93ac6SEd Maste }
5712b93ac6SEd Maste
GetNumRunningWorkItems() const58435933ddSDimitry Andric uint32_t Queue::GetNumRunningWorkItems() const {
5912b93ac6SEd Maste return m_running_work_items_count;
6012b93ac6SEd Maste }
6112b93ac6SEd Maste
SetNumPendingWorkItems(uint32_t count)62435933ddSDimitry Andric void Queue::SetNumPendingWorkItems(uint32_t count) {
6312b93ac6SEd Maste m_pending_work_items_count = count;
6412b93ac6SEd Maste }
6512b93ac6SEd Maste
GetNumPendingWorkItems() const66435933ddSDimitry Andric uint32_t Queue::GetNumPendingWorkItems() const {
6712b93ac6SEd Maste return m_pending_work_items_count;
6812b93ac6SEd Maste }
6912b93ac6SEd Maste
SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr)70435933ddSDimitry Andric void Queue::SetLibdispatchQueueAddress(addr_t dispatch_queue_t_addr) {
7112b93ac6SEd Maste m_dispatch_queue_t_addr = dispatch_queue_t_addr;
7212b93ac6SEd Maste }
7312b93ac6SEd Maste
GetLibdispatchQueueAddress() const74435933ddSDimitry Andric addr_t Queue::GetLibdispatchQueueAddress() const {
7512b93ac6SEd Maste return m_dispatch_queue_t_addr;
7612b93ac6SEd Maste }
7712b93ac6SEd Maste
GetPendingItems()78435933ddSDimitry Andric const std::vector<lldb::QueueItemSP> &Queue::GetPendingItems() {
79435933ddSDimitry Andric if (m_pending_items.empty()) {
8012b93ac6SEd Maste ProcessSP process_sp = m_process_wp.lock();
81435933ddSDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
8212b93ac6SEd Maste process_sp->GetSystemRuntime()->PopulatePendingItemsForQueue(this);
8312b93ac6SEd Maste }
8412b93ac6SEd Maste }
8512b93ac6SEd Maste return m_pending_items;
8612b93ac6SEd Maste }
870127ef0fSEd Maste
GetKind()88435933ddSDimitry Andric lldb::QueueKind Queue::GetKind() { return m_kind; }
890127ef0fSEd Maste
SetKind(lldb::QueueKind kind)90435933ddSDimitry Andric void Queue::SetKind(lldb::QueueKind kind) { m_kind = kind; }
91