blob: 796825135187b0a7b1865230b143cc65772a46d2 [file] [log] [blame]
Jason Molenda5e8dce42013-12-13 00:29:16 +00001//===-- QueueList.cpp -------------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jason Molenda5e8dce42013-12-13 00:29:16 +00006//
7//===----------------------------------------------------------------------===//
8
Jason Molenda5e8dce42013-12-13 00:29:16 +00009#include "lldb/Target/Queue.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000010#include "lldb/Target/Process.h"
Jason Molenda5e8dce42013-12-13 00:29:16 +000011#include "lldb/Target/QueueList.h"
12
13using namespace lldb;
14using namespace lldb_private;
15
Kate Stoneb9c1b512016-09-06 20:57:50 +000016QueueList::QueueList(Process *process)
17 : m_process(process), m_stop_id(0), m_queues(), m_mutex() {}
18
19QueueList::~QueueList() { Clear(); }
20
21uint32_t QueueList::GetSize() {
22 std::lock_guard<std::mutex> guard(m_mutex);
23 return m_queues.size();
Jason Molenda5e8dce42013-12-13 00:29:16 +000024}
25
Kate Stoneb9c1b512016-09-06 20:57:50 +000026lldb::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 }
Jason Molenda5e8dce42013-12-13 00:29:16 +000033}
34
Kate Stoneb9c1b512016-09-06 20:57:50 +000035void QueueList::Clear() {
36 std::lock_guard<std::mutex> guard(m_mutex);
37 m_queues.clear();
Jason Molenda5e8dce42013-12-13 00:29:16 +000038}
39
Kate Stoneb9c1b512016-09-06 20:57:50 +000040void 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
47lldb::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;
Jason Molenda5e8dce42013-12-13 00:29:16 +000053 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 }
55 return ret;
56}
57
58lldb::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;
Jason Molenda5e8dce42013-12-13 00:29:16 +000064 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 }
66 return ret;
Jason Molenda5e8dce42013-12-13 00:29:16 +000067}
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069std::mutex &QueueList::GetMutex() { return m_mutex; }