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