xref: /src/contrib/llvm-project/lldb/source/Target/QueueList.cpp (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
1cfca06d7SDimitry Andric //===-- QueueList.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 
13866dcdacSEd Maste using namespace lldb;
14866dcdacSEd Maste using namespace lldb_private;
15866dcdacSEd Maste 
QueueList(Process * process)1614f1b3e8SDimitry Andric QueueList::QueueList(Process *process)
1714f1b3e8SDimitry Andric     : m_process(process), m_stop_id(0), m_queues(), m_mutex() {}
18866dcdacSEd Maste 
~QueueList()1914f1b3e8SDimitry Andric QueueList::~QueueList() { Clear(); }
20866dcdacSEd Maste 
GetSize()2114f1b3e8SDimitry Andric uint32_t QueueList::GetSize() {
22f3fbd1c0SDimitry Andric   std::lock_guard<std::mutex> guard(m_mutex);
23866dcdacSEd Maste   return m_queues.size();
24866dcdacSEd Maste }
25866dcdacSEd Maste 
GetQueueAtIndex(uint32_t idx)2614f1b3e8SDimitry Andric lldb::QueueSP QueueList::GetQueueAtIndex(uint32_t idx) {
27f3fbd1c0SDimitry Andric   std::lock_guard<std::mutex> guard(m_mutex);
2814f1b3e8SDimitry Andric   if (idx < m_queues.size()) {
29866dcdacSEd Maste     return m_queues[idx];
3014f1b3e8SDimitry Andric   } else {
31866dcdacSEd Maste     return QueueSP();
32866dcdacSEd Maste   }
33866dcdacSEd Maste }
34866dcdacSEd Maste 
Clear()3514f1b3e8SDimitry Andric void QueueList::Clear() {
36f3fbd1c0SDimitry Andric   std::lock_guard<std::mutex> guard(m_mutex);
37866dcdacSEd Maste   m_queues.clear();
38866dcdacSEd Maste }
39866dcdacSEd Maste 
AddQueue(QueueSP queue_sp)4014f1b3e8SDimitry Andric void QueueList::AddQueue(QueueSP queue_sp) {
41f3fbd1c0SDimitry Andric   std::lock_guard<std::mutex> guard(m_mutex);
4214f1b3e8SDimitry Andric   if (queue_sp.get()) {
43866dcdacSEd Maste     m_queues.push_back(queue_sp);
44866dcdacSEd Maste   }
45866dcdacSEd Maste }
46866dcdacSEd Maste 
FindQueueByID(lldb::queue_id_t qid)4714f1b3e8SDimitry Andric lldb::QueueSP QueueList::FindQueueByID(lldb::queue_id_t qid) {
48866dcdacSEd Maste   QueueSP ret;
4914f1b3e8SDimitry Andric   for (QueueSP queue_sp : Queues()) {
5014f1b3e8SDimitry Andric     if (queue_sp->GetID() == qid) {
51866dcdacSEd Maste       ret = queue_sp;
52866dcdacSEd Maste       break;
53866dcdacSEd Maste     }
54866dcdacSEd Maste   }
55866dcdacSEd Maste   return ret;
56866dcdacSEd Maste }
57866dcdacSEd Maste 
FindQueueByIndexID(uint32_t index_id)5814f1b3e8SDimitry Andric lldb::QueueSP QueueList::FindQueueByIndexID(uint32_t index_id) {
59866dcdacSEd Maste   QueueSP ret;
6014f1b3e8SDimitry Andric   for (QueueSP queue_sp : Queues()) {
6114f1b3e8SDimitry Andric     if (queue_sp->GetIndexID() == index_id) {
62866dcdacSEd Maste       ret = queue_sp;
63866dcdacSEd Maste       break;
64866dcdacSEd Maste     }
65866dcdacSEd Maste   }
66866dcdacSEd Maste   return ret;
67866dcdacSEd Maste }
68866dcdacSEd Maste 
GetMutex()6914f1b3e8SDimitry Andric std::mutex &QueueList::GetMutex() { return m_mutex; }
70