QueueList.h 3.3 KB

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