112b93ac6SEd Maste //===-- QueueList.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"
11*435933ddSDimitry Andric #include "lldb/Target/Process.h"
1212b93ac6SEd Maste #include "lldb/Target/QueueList.h"
1312b93ac6SEd Maste 
1412b93ac6SEd Maste using namespace lldb;
1512b93ac6SEd Maste using namespace lldb_private;
1612b93ac6SEd Maste 
QueueList(Process * process)17*435933ddSDimitry Andric QueueList::QueueList(Process *process)
18*435933ddSDimitry Andric     : m_process(process), m_stop_id(0), m_queues(), m_mutex() {}
1912b93ac6SEd Maste 
~QueueList()20*435933ddSDimitry Andric QueueList::~QueueList() { Clear(); }
2112b93ac6SEd Maste 
GetSize()22*435933ddSDimitry Andric uint32_t QueueList::GetSize() {
234bb0738eSEd Maste   std::lock_guard<std::mutex> guard(m_mutex);
2412b93ac6SEd Maste   return m_queues.size();
2512b93ac6SEd Maste }
2612b93ac6SEd Maste 
GetQueueAtIndex(uint32_t idx)27*435933ddSDimitry Andric lldb::QueueSP QueueList::GetQueueAtIndex(uint32_t idx) {
284bb0738eSEd Maste   std::lock_guard<std::mutex> guard(m_mutex);
29*435933ddSDimitry Andric   if (idx < m_queues.size()) {
3012b93ac6SEd Maste     return m_queues[idx];
31*435933ddSDimitry Andric   } else {
3212b93ac6SEd Maste     return QueueSP();
3312b93ac6SEd Maste   }
3412b93ac6SEd Maste }
3512b93ac6SEd Maste 
Clear()36*435933ddSDimitry Andric void QueueList::Clear() {
374bb0738eSEd Maste   std::lock_guard<std::mutex> guard(m_mutex);
3812b93ac6SEd Maste   m_queues.clear();
3912b93ac6SEd Maste }
4012b93ac6SEd Maste 
AddQueue(QueueSP queue_sp)41*435933ddSDimitry Andric void QueueList::AddQueue(QueueSP queue_sp) {
424bb0738eSEd Maste   std::lock_guard<std::mutex> guard(m_mutex);
43*435933ddSDimitry Andric   if (queue_sp.get()) {
4412b93ac6SEd Maste     m_queues.push_back(queue_sp);
4512b93ac6SEd Maste   }
4612b93ac6SEd Maste }
4712b93ac6SEd Maste 
FindQueueByID(lldb::queue_id_t qid)48*435933ddSDimitry Andric lldb::QueueSP QueueList::FindQueueByID(lldb::queue_id_t qid) {
4912b93ac6SEd Maste   QueueSP ret;
50*435933ddSDimitry Andric   for (QueueSP queue_sp : Queues()) {
51*435933ddSDimitry Andric     if (queue_sp->GetID() == qid) {
5212b93ac6SEd Maste       ret = queue_sp;
5312b93ac6SEd Maste       break;
5412b93ac6SEd Maste     }
5512b93ac6SEd Maste   }
5612b93ac6SEd Maste   return ret;
5712b93ac6SEd Maste }
5812b93ac6SEd Maste 
FindQueueByIndexID(uint32_t index_id)59*435933ddSDimitry Andric lldb::QueueSP QueueList::FindQueueByIndexID(uint32_t index_id) {
6012b93ac6SEd Maste   QueueSP ret;
61*435933ddSDimitry Andric   for (QueueSP queue_sp : Queues()) {
62*435933ddSDimitry Andric     if (queue_sp->GetIndexID() == index_id) {
6312b93ac6SEd Maste       ret = queue_sp;
6412b93ac6SEd Maste       break;
6512b93ac6SEd Maste     }
6612b93ac6SEd Maste   }
6712b93ac6SEd Maste   return ret;
6812b93ac6SEd Maste }
6912b93ac6SEd Maste 
GetMutex()70*435933ddSDimitry Andric std::mutex &QueueList::GetMutex() { return m_mutex; }
71