1262182Semaste//===-- QueueList.h --------------------------------------------*- C++ -*-===//
2262182Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6262182Semaste//
7262182Semaste//===----------------------------------------------------------------------===//
8262182Semaste
9262182Semaste#ifndef liblldb_QueueList_h_
10262182Semaste#define liblldb_QueueList_h_
11262182Semaste
12309124Sdim#include <mutex>
13262182Semaste#include <vector>
14262182Semaste
15262182Semaste#include "lldb/Utility/Iterable.h"
16321369Sdim#include "lldb/Utility/UserID.h"
17314564Sdim#include "lldb/lldb-private.h"
18262182Semaste
19262182Semastenamespace lldb_private {
20262182Semaste
21262182Semaste// QueueList:
22341825Sdim// This is the container for libdispatch aka Grand Central Dispatch Queue
23341825Sdim// objects.
24262182Semaste//
25341825Sdim// Each Process will have a QueueList.  When the process execution is paused,
26341825Sdim// the QueueList may be populated with Queues by the SystemRuntime.
27262182Semaste
28314564Sdimclass QueueList {
29314564Sdim  friend class Process;
30262182Semaste
31262182Semastepublic:
32314564Sdim  QueueList(Process *process);
33262182Semaste
34314564Sdim  ~QueueList();
35262182Semaste
36314564Sdim  /// Get the number of libdispatch queues that are available
37314564Sdim  ///
38353358Sdim  /// \return
39314564Sdim  ///     The number of queues that are stored in the QueueList.
40314564Sdim  uint32_t GetSize();
41262182Semaste
42314564Sdim  /// Get the Queue at a given index number
43314564Sdim  ///
44353358Sdim  /// \param [in] idx
45314564Sdim  ///     The index number (0-based) of the queue.
46353358Sdim  /// \return
47314564Sdim  ///     The Queue at that index number.
48314564Sdim  lldb::QueueSP GetQueueAtIndex(uint32_t idx);
49262182Semaste
50314564Sdim  typedef std::vector<lldb::QueueSP> collection;
51314564Sdim  typedef LockingAdaptedIterable<collection, lldb::QueueSP, vector_adapter,
52314564Sdim                                 std::mutex>
53314564Sdim      QueueIterable;
54262182Semaste
55314564Sdim  /// Iterate over the list of queues
56314564Sdim  ///
57353358Sdim  /// \return
58314564Sdim  ///     An Iterable object which can be used to loop over the queues
59314564Sdim  ///     that exist.
60314564Sdim  QueueIterable Queues() { return QueueIterable(m_queues, m_mutex); }
61262182Semaste
62314564Sdim  /// Clear out the list of queues from the QueueList
63314564Sdim  void Clear();
64262182Semaste
65314564Sdim  /// Add a Queue to the QueueList
66314564Sdim  ///
67353358Sdim  /// \param [in] queue
68314564Sdim  ///     Used by the SystemRuntime to populate the QueueList
69314564Sdim  void AddQueue(lldb::QueueSP queue);
70262182Semaste
71314564Sdim  /// Find a queue in the QueueList by QueueID
72314564Sdim  ///
73353358Sdim  /// \param [in] qid
74314564Sdim  ///     The QueueID (same as returned by Thread::GetQueueID()) to find.
75314564Sdim  ///
76353358Sdim  /// \return
77314564Sdim  ///     A QueueSP to the queue requested, if it is present in the QueueList.
78314564Sdim  ///     An empty QueueSP will be returned if this queue was not found.
79314564Sdim  lldb::QueueSP FindQueueByID(lldb::queue_id_t qid);
80262182Semaste
81314564Sdim  /// Find a queue in the QueueList by IndexID
82314564Sdim  ///
83353358Sdim  /// \param [in] index_id
84314564Sdim  ///     Find a queue by IndexID.  This is an integer associated with each
85314564Sdim  ///     unique queue seen during a debug session and will not be reused
86314564Sdim  ///     for a different queue.  Unlike the QueueID, a 64-bit value, this
87314564Sdim  ///     will tend to be an integral value like 1 or 7.
88314564Sdim  ///
89353358Sdim  /// \return
90314564Sdim  ///     A QueueSP to the queue requested, if it is present in the QueueList.
91314564Sdim  ///     An empty QueueSP will be returned if this queue was not found.
92314564Sdim  lldb::QueueSP FindQueueByIndexID(uint32_t index_id);
93262182Semaste
94314564Sdim  std::mutex &GetMutex();
95262182Semaste
96262182Semasteprotected:
97314564Sdim  // Classes that inherit from Process can see and modify these
98314564Sdim  Process *m_process; ///< The process that manages this queue list.
99314564Sdim  uint32_t
100314564Sdim      m_stop_id; ///< The process stop ID that this queue list is valid for.
101314564Sdim  collection m_queues; ///< The queues for this process.
102314564Sdim  std::mutex m_mutex;
103262182Semaste
104262182Semasteprivate:
105353358Sdim  QueueList() = delete;
106262182Semaste};
107262182Semaste
108262182Semaste} // namespace lldb_private
109262182Semaste
110314564Sdim#endif // liblldb_QueueList_h_
111