summaryrefslogtreecommitdiffstats
path: root/lldb/include/lldb/Target/QueueList.h
blob: cdf2d004c350b96a624fc63aa5a72291813c34e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//===-- QueueList.h --------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_QueueList_h_
#define liblldb_QueueList_h_

#include <mutex>
#include <vector>

#include "lldb/Utility/Iterable.h"
#include "lldb/Utility/UserID.h"
#include "lldb/lldb-private.h"

namespace lldb_private {

//------------------------------------------------------------------
// QueueList:
// This is the container for libdispatch aka Grand Central Dispatch Queue
// objects.
//
// Each Process will have a QueueList.  When the process execution is paused,
// the QueueList may be populated with Queues by the SystemRuntime.
//------------------------------------------------------------------

class QueueList {
  friend class Process;

public:
  QueueList(Process *process);

  ~QueueList();

  //------------------------------------------------------------------
  /// Get the number of libdispatch queues that are available
  ///
  /// @return
  ///     The number of queues that are stored in the QueueList.
  //------------------------------------------------------------------
  uint32_t GetSize();

  //------------------------------------------------------------------
  /// Get the Queue at a given index number
  ///
  /// @param [in] idx
  ///     The index number (0-based) of the queue.
  /// @return
  ///     The Queue at that index number.
  //------------------------------------------------------------------
  lldb::QueueSP GetQueueAtIndex(uint32_t idx);

  typedef std::vector<lldb::QueueSP> collection;
  typedef LockingAdaptedIterable<collection, lldb::QueueSP, vector_adapter,
                                 std::mutex>
      QueueIterable;

  //------------------------------------------------------------------
  /// Iterate over the list of queues
  ///
  /// @return
  ///     An Iterable object which can be used to loop over the queues
  ///     that exist.
  //------------------------------------------------------------------
  QueueIterable Queues() { return QueueIterable(m_queues, m_mutex); }

  //------------------------------------------------------------------
  /// Clear out the list of queues from the QueueList
  //------------------------------------------------------------------
  void Clear();

  //------------------------------------------------------------------
  /// Add a Queue to the QueueList
  ///
  /// @param [in] queue
  ///     Used by the SystemRuntime to populate the QueueList
  //------------------------------------------------------------------
  void AddQueue(lldb::QueueSP queue);

  //------------------------------------------------------------------
  /// Find a queue in the QueueList by QueueID
  ///
  /// @param [in] qid
  ///     The QueueID (same as returned by Thread::GetQueueID()) to find.
  ///
  /// @return
  ///     A QueueSP to the queue requested, if it is present in the QueueList.
  ///     An empty QueueSP will be returned if this queue was not found.
  //------------------------------------------------------------------
  lldb::QueueSP FindQueueByID(lldb::queue_id_t qid);

  //------------------------------------------------------------------
  /// Find a queue in the QueueList by IndexID
  ///
  /// @param [in] index_id
  ///     Find a queue by IndexID.  This is an integer associated with each
  ///     unique queue seen during a debug session and will not be reused
  ///     for a different queue.  Unlike the QueueID, a 64-bit value, this
  ///     will tend to be an integral value like 1 or 7.
  ///
  /// @return
  ///     A QueueSP to the queue requested, if it is present in the QueueList.
  ///     An empty QueueSP will be returned if this queue was not found.
  //------------------------------------------------------------------
  lldb::QueueSP FindQueueByIndexID(uint32_t index_id);

  std::mutex &GetMutex();

protected:
  //------------------------------------------------------------------
  // Classes that inherit from Process can see and modify these
  //------------------------------------------------------------------
  Process *m_process; ///< The process that manages this queue list.
  uint32_t
      m_stop_id; ///< The process stop ID that this queue list is valid for.
  collection m_queues; ///< The queues for this process.
  std::mutex m_mutex;

private:
  QueueList();
};

} // namespace lldb_private

#endif // liblldb_QueueList_h_
OpenPOWER on IntegriCloud