1 //===-- QueueList.cpp -------------------------------------------*- C++ -*-===//
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"
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 
16 QueueList::QueueList(Process *process)
17     : m_process(process), m_stop_id(0), m_queues(), m_mutex() {}
18 
19 QueueList::~QueueList() { Clear(); }
20 
21 uint32_t QueueList::GetSize() {
22   std::lock_guard<std::mutex> guard(m_mutex);
23   return m_queues.size();
24 }
25 
26 lldb::QueueSP QueueList::GetQueueAtIndex(uint32_t idx) {
27   std::lock_guard<std::mutex> guard(m_mutex);
28   if (idx < m_queues.size()) {
29     return m_queues[idx];
30   } else {
31     return QueueSP();
32   }
33 }
34 
35 void QueueList::Clear() {
36   std::lock_guard<std::mutex> guard(m_mutex);
37   m_queues.clear();
38 }
39 
40 void QueueList::AddQueue(QueueSP queue_sp) {
41   std::lock_guard<std::mutex> guard(m_mutex);
42   if (queue_sp.get()) {
43     m_queues.push_back(queue_sp);
44   }
45 }
46 
47 lldb::QueueSP QueueList::FindQueueByID(lldb::queue_id_t qid) {
48   QueueSP ret;
49   for (QueueSP queue_sp : Queues()) {
50     if (queue_sp->GetID() == qid) {
51       ret = queue_sp;
52       break;
53     }
54   }
55   return ret;
56 }
57 
58 lldb::QueueSP QueueList::FindQueueByIndexID(uint32_t index_id) {
59   QueueSP ret;
60   for (QueueSP queue_sp : Queues()) {
61     if (queue_sp->GetIndexID() == index_id) {
62       ret = queue_sp;
63       break;
64     }
65   }
66   return ret;
67 }
68 
69 std::mutex &QueueList::GetMutex() { return m_mutex; }
70