QueueList.h revision 341825
1//===-- QueueList.h --------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_QueueList_h_
11#define liblldb_QueueList_h_
12
13#include <mutex>
14#include <vector>
15
16#include "lldb/Utility/Iterable.h"
17#include "lldb/Utility/UserID.h"
18#include "lldb/lldb-private.h"
19
20namespace lldb_private {
21
22//------------------------------------------------------------------
23// QueueList:
24// This is the container for libdispatch aka Grand Central Dispatch Queue
25// objects.
26//
27// Each Process will have a QueueList.  When the process execution is paused,
28// the QueueList may be populated with Queues by the SystemRuntime.
29//------------------------------------------------------------------
30
31class QueueList {
32  friend class Process;
33
34public:
35  QueueList(Process *process);
36
37  ~QueueList();
38
39  //------------------------------------------------------------------
40  /// Get the number of libdispatch queues that are available
41  ///
42  /// @return
43  ///     The number of queues that are stored in the QueueList.
44  //------------------------------------------------------------------
45  uint32_t GetSize();
46
47  //------------------------------------------------------------------
48  /// Get the Queue at a given index number
49  ///
50  /// @param [in] idx
51  ///     The index number (0-based) of the queue.
52  /// @return
53  ///     The Queue at that index number.
54  //------------------------------------------------------------------
55  lldb::QueueSP GetQueueAtIndex(uint32_t idx);
56
57  typedef std::vector<lldb::QueueSP> collection;
58  typedef LockingAdaptedIterable<collection, lldb::QueueSP, vector_adapter,
59                                 std::mutex>
60      QueueIterable;
61
62  //------------------------------------------------------------------
63  /// Iterate over the list of queues
64  ///
65  /// @return
66  ///     An Iterable object which can be used to loop over the queues
67  ///     that exist.
68  //------------------------------------------------------------------
69  QueueIterable Queues() { return QueueIterable(m_queues, m_mutex); }
70
71  //------------------------------------------------------------------
72  /// Clear out the list of queues from the QueueList
73  //------------------------------------------------------------------
74  void Clear();
75
76  //------------------------------------------------------------------
77  /// Add a Queue to the QueueList
78  ///
79  /// @param [in] queue
80  ///     Used by the SystemRuntime to populate the QueueList
81  //------------------------------------------------------------------
82  void AddQueue(lldb::QueueSP queue);
83
84  //------------------------------------------------------------------
85  /// Find a queue in the QueueList by QueueID
86  ///
87  /// @param [in] qid
88  ///     The QueueID (same as returned by Thread::GetQueueID()) to find.
89  ///
90  /// @return
91  ///     A QueueSP to the queue requested, if it is present in the QueueList.
92  ///     An empty QueueSP will be returned if this queue was not found.
93  //------------------------------------------------------------------
94  lldb::QueueSP FindQueueByID(lldb::queue_id_t qid);
95
96  //------------------------------------------------------------------
97  /// Find a queue in the QueueList by IndexID
98  ///
99  /// @param [in] index_id
100  ///     Find a queue by IndexID.  This is an integer associated with each
101  ///     unique queue seen during a debug session and will not be reused
102  ///     for a different queue.  Unlike the QueueID, a 64-bit value, this
103  ///     will tend to be an integral value like 1 or 7.
104  ///
105  /// @return
106  ///     A QueueSP to the queue requested, if it is present in the QueueList.
107  ///     An empty QueueSP will be returned if this queue was not found.
108  //------------------------------------------------------------------
109  lldb::QueueSP FindQueueByIndexID(uint32_t index_id);
110
111  std::mutex &GetMutex();
112
113protected:
114  //------------------------------------------------------------------
115  // Classes that inherit from Process can see and modify these
116  //------------------------------------------------------------------
117  Process *m_process; ///< The process that manages this queue list.
118  uint32_t
119      m_stop_id; ///< The process stop ID that this queue list is valid for.
120  collection m_queues; ///< The queues for this process.
121  std::mutex m_mutex;
122
123private:
124  QueueList();
125};
126
127} // namespace lldb_private
128
129#endif // liblldb_QueueList_h_
130